Kubernetes/Helm:何时调用ConfigMap函数?

rkkpypqq  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(1)|浏览(122)

如果我有一个这样的ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: id-config
data:
  uuid: "{{ randAlphaNum 32 }}"

字符串
和一个StatefulSet规范,如下所示(取自kubernetes的StatefulSet Basics页面并稍作修改):

apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: registry.k8s.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
      env:
      - name: UUID
        valueFrom:
          configMapKeyRef:
            name: id-config
            key: uuid
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi


randAlphaNum是否只在初始部署时调用一次,然后randAlphaNum返回的值存储在uuid键中,并在pod重新启动时使用?还是每次创建或重启pod时都会调用randAlphaNum,并返回不同的uuid?先谢谢你。

csbfibhn

csbfibhn1#

当你使用Helm进行部署时,你需要区分两种不同的情况:
1.呈现清单,这在执行helm CLI的计算机上本地发生。
1.部署呈现的清单。即向Kubernetes API发送指令以部署某些资源。
清单文件中的条目(如{{ randAlphaNum 32 }})在步骤1中渲染,预渲染结果发送到Kubernetes API。只有当您要求Helm再次渲染和部署时,它才会更改。

相关问题