通过 ConfigMap 更新配置

此页面提供了通过 ConfigMap 在 Pod 中更新配置的逐步示例,并基于 配置 Pod 以使用 ConfigMap 任务。
在本教程结束时,您将了解如何更改正在运行的应用程序的配置。
本教程使用alpinenginx 镜像作为示例。

开始之前

您需要有一个 Kubernetes 集群,并且 kubectl 命令行工具必须配置为与您的集群通信。建议在至少有两个节点(不充当控制平面主机)的集群上运行本教程。如果您还没有集群,可以使用 minikube 创建一个,也可以使用以下 Kubernetes 游乐场之一

您需要具有 curl 命令行工具,以便从终端或命令提示符发出 HTTP 请求。如果您没有curl 可用,可以安装它。查看您本地操作系统的文档。

目标

  • 通过作为 Volume 挂载的 ConfigMap 更新配置
  • 通过 ConfigMap 更新 Pod 的环境变量
  • 通过 ConfigMap 在多容器 Pod 中更新配置
  • 通过 ConfigMap 在拥有 Sidecar 容器的 Pod 中更新配置

通过作为 Volume 挂载的 ConfigMap 更新配置

使用 kubectl create configmap 命令从 字面量值 创建 ConfigMap

kubectl create configmap sport --from-literal=sport=football

以下是一个 Deployment 清单的示例,其中 ConfigMap sport 作为 挂载到 Pod 中的唯一容器。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-volume
  labels:
    app.kubernetes.io/name: configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-volume
    spec:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred sport is $(cat /etc/config/sport)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: sport

创建 Deployment

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-as-volume.yaml

检查此 Deployment 的 Pod 以确保它们已准备就绪(通过 选择器 匹配)

kubectl get pods --selector=app.kubernetes.io/name=configmap-volume

您应该看到类似于以下内容的输出

NAME                                READY   STATUS    RESTARTS   AGE
configmap-volume-6b976dfdcf-qxvbm   1/1     Running   0          72s
configmap-volume-6b976dfdcf-skpvm   1/1     Running   0          72s
configmap-volume-6b976dfdcf-tbc6r   1/1     Running   0          72s

在运行这些 Pod 之一的每个节点上,kubelet 会获取该 ConfigMap 的数据,并将其转换为本地卷中的文件。然后,kubelet 会根据 Pod 模板中的指定内容将该卷挂载到容器中。该容器中运行的代码会从文件中加载信息,并使用它将报告打印到 stdout。您可以通过查看该 Deployment 中的某个 Pod 的日志来检查此报告

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployments/configmap-volume

您应该看到类似于以下内容的输出

Found 3 pods, using pod/configmap-volume-76d9c5678f-x5rgj
Thu Jan  4 14:06:46 UTC 2024 My preferred sport is football
Thu Jan  4 14:06:56 UTC 2024 My preferred sport is football
Thu Jan  4 14:07:06 UTC 2024 My preferred sport is football
Thu Jan  4 14:07:16 UTC 2024 My preferred sport is football
Thu Jan  4 14:07:26 UTC 2024 My preferred sport is football

编辑 ConfigMap

kubectl edit configmap sport

在出现的编辑器中,将键 sport 的值从 football 更改为 cricket。保存您的更改。kubectl 工具会相应地更新 ConfigMap(如果您看到错误,请重试)。

以下是您编辑后该清单可能的样子

apiVersion: v1
data:
  sport: cricket
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-04T14:05:06Z"
  name: sport
  namespace: default
  resourceVersion: "1743935"
  uid: 024ee001-fe72-487e-872e-34d6464a8a23

您应该看到以下输出

configmap/sport edited

跟踪(跟随此 Deployment 所属的某个 Pod 的最新条目)日志

kubectl logs deployments/configmap-volume --follow

几秒钟后,您应该看到日志输出发生如下更改

Thu Jan  4 14:11:36 UTC 2024 My preferred sport is football
Thu Jan  4 14:11:46 UTC 2024 My preferred sport is football
Thu Jan  4 14:11:56 UTC 2024 My preferred sport is football
Thu Jan  4 14:12:06 UTC 2024 My preferred sport is cricket
Thu Jan  4 14:12:16 UTC 2024 My preferred sport is cricket

当您有一个使用 configMap 卷或 projected 卷映射到正在运行的 Pod 的 ConfigMap 时,并且您更新了该 ConfigMap,正在运行的 Pod 几乎立即会看到更新。
但是,您的应用程序只有在编写为轮询更改或监视文件更新时才会看到更改。
在启动时只加载一次配置的应用程序不会注意到更改。

通过 ConfigMap 更新 Pod 的环境变量

使用 kubectl create configmap 命令从 字面量值 创建 ConfigMap

kubectl create configmap fruits --from-literal=fruits=apples

以下是一个 Deployment 清单的示例,其中通过 ConfigMap fruits 配置了一个环境变量。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-env-var
  labels:
    app.kubernetes.io/name: configmap-env-var
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-env-var
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-env-var
    spec:
      containers:
        - name: alpine
          image: alpine:3
          env:
            - name: FRUITS
              valueFrom:
                configMapKeyRef:
                  key: fruits
                  name: fruits
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The basket is full of $FRUITS";
                sleep 10; done;
          ports:
            - containerPort: 80

创建 Deployment

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-as-envvar.yaml

检查此 Deployment 的 Pod 以确保它们已准备就绪(通过 选择器 匹配)

kubectl get pods --selector=app.kubernetes.io/name=configmap-env-var

您应该看到类似于以下内容的输出

NAME                                 READY   STATUS    RESTARTS   AGE
configmap-env-var-59cfc64f7d-74d7z   1/1     Running   0          46s
configmap-env-var-59cfc64f7d-c4wmj   1/1     Running   0          46s
configmap-env-var-59cfc64f7d-dpr98   1/1     Running   0          46s

ConfigMap 中的键值对配置为 Pod 容器中的环境变量。通过查看属于 Deployment 的某个 Pod 的日志来检查这一点。

kubectl logs deployment/configmap-env-var

您应该看到类似于以下内容的输出

Found 3 pods, using pod/configmap-env-var-7c994f7769-l74nq
Thu Jan  4 16:07:06 UTC 2024 The basket is full of apples
Thu Jan  4 16:07:16 UTC 2024 The basket is full of apples
Thu Jan  4 16:07:26 UTC 2024 The basket is full of apples

编辑 ConfigMap

kubectl edit configmap fruits

在出现的编辑器中,将键 fruits 的值从 apples 更改为 mangoes。保存您的更改。kubectl 工具会相应地更新 ConfigMap(如果您看到错误,请重试)。

以下是您编辑后该清单可能的样子

apiVersion: v1
data:
  fruits: mangoes
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-04T16:04:19Z"
  name: fruits
  namespace: default
  resourceVersion: "1749472"

您应该看到以下输出

configmap/fruits edited

跟踪 Deployment 的日志并观察几秒钟的输出

# As the text explains, the output does NOT change
kubectl logs deployments/configmap-env-var --follow

请注意,即使您编辑了 ConfigMap,输出也保持不变

Thu Jan  4 16:12:56 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:06 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:16 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:26 UTC 2024 The basket is full of apples

您可以触发该替换。使用 kubectl rollout 对 Deployment 进行滚动更新。

# Trigger the rollout
kubectl rollout restart deployment configmap-env-var

# Wait for the rollout to complete
kubectl rollout status deployment configmap-env-var --watch=true

接下来,检查 Deployment

kubectl get deployment configmap-env-var

您应该看到类似于以下内容的输出

NAME                READY   UP-TO-DATE   AVAILABLE   AGE
configmap-env-var   3/3     3            3           12m

检查 Pod

kubectl get pods --selector=app.kubernetes.io/name=configmap-env-var

滚动更新会导致 Kubernetes 为 Deployment 创建一个新的 ReplicaSet;这意味着现有的 Pod 最终会终止,并且会创建新的 Pod。几秒钟后,您应该看到类似于以下内容的输出

NAME                                 READY   STATUS        RESTARTS   AGE
configmap-env-var-6d94d89bf5-2ph2l   1/1     Running       0          13s
configmap-env-var-6d94d89bf5-74twx   1/1     Running       0          8s
configmap-env-var-6d94d89bf5-d5vx8   1/1     Running       0          11s

查看此 Deployment 中某个 Pod 的日志

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployment/configmap-env-var

您应该看到类似于以下内容的输出

Found 3 pods, using pod/configmap-env-var-6d9ff89fb6-bzcf6
Thu Jan  4 16:30:35 UTC 2024 The basket is full of mangoes
Thu Jan  4 16:30:45 UTC 2024 The basket is full of mangoes
Thu Jan  4 16:30:55 UTC 2024 The basket is full of mangoes

这演示了更新从 ConfigMap 派生的 Pod 中的环境变量的场景。在后续的滚动更新期间,ConfigMap 值的更改将应用到 Pod。如果因其他原因(例如扩展 Deployment)而创建了 Pod,则新的 Pod 也将使用最新的配置值;如果您没有触发滚动更新,那么您可能会发现您的应用程序正在使用旧环境变量值和新环境变量值的混合。

通过 ConfigMap 在多容器 Pod 中更新配置

使用 kubectl create configmap 命令从 字面量值 创建 ConfigMap

kubectl create configmap color --from-literal=color=red

以下是一个 Deployment 的清单示例,该清单管理一组 Pod,每个 Pod 都有两个容器。这两个容器共享一个 emptyDir 卷,它们使用该卷进行通信。第一个容器运行一个 Web 服务器 (nginx)。Web 服务器容器中共享卷的挂载路径为 /usr/share/nginx/html。第二个辅助容器基于 alpine,对于该容器,emptyDir 卷挂载在 /pod-data 上。辅助容器会写入一个 HTML 文件,其内容基于 ConfigMap。Web 服务器容器通过 HTTP 提供 HTML。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-two-containers
  labels:
    app.kubernetes.io/name: configmap-two-containers
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-two-containers
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-two-containers
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
        - name: alpine
          image: alpine:3
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;

创建 Deployment

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-two-containers.yaml

检查此 Deployment 的 Pod 以确保它们已准备就绪(通过 选择器 匹配)

kubectl get pods --selector=app.kubernetes.io/name=configmap-two-containers

您应该看到类似于以下内容的输出

NAME                                        READY   STATUS    RESTARTS   AGE
configmap-two-containers-565fb6d4f4-2xhxf   2/2     Running   0          20s
configmap-two-containers-565fb6d4f4-g5v4j   2/2     Running   0          20s
configmap-two-containers-565fb6d4f4-mzsmf   2/2     Running   0          20s

公开 Deployment(kubectl 工具为您创建一个 服务

kubectl expose deployment configmap-two-containers --name=configmap-service --port=8080 --target-port=80

使用 kubectl 转发端口

# this stays running in the background
kubectl port-forward service/configmap-service 8080:8080 &

访问服务。

curl http://localhost:8080

您应该看到类似于以下内容的输出

Fri Jan  5 08:08:22 UTC 2024 My preferred color is red

编辑 ConfigMap

kubectl edit configmap color

在出现的编辑器中,将键 color 的值从 red 更改为 blue。保存您的更改。kubectl 工具会相应地更新 ConfigMap(如果您看到错误,请重试)。

以下是您编辑后该清单可能的样子

apiVersion: v1
data:
  color: blue
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-05T08:12:05Z"
  name: color
  namespace: configmap
  resourceVersion: "1801272"
  uid: 80d33e4a-cbb4-4bc9-ba8c-544c68e425d6

在几秒钟内循环访问服务 URL。

# Cancel this when you're happy with it (Ctrl-C)
while true; do curl --connect-timeout 7.5 http://localhost:8080; sleep 10; done

您应该看到输出发生如下更改

Fri Jan  5 08:14:00 UTC 2024 My preferred color is red
Fri Jan  5 08:14:02 UTC 2024 My preferred color is red
Fri Jan  5 08:14:20 UTC 2024 My preferred color is red
Fri Jan  5 08:14:22 UTC 2024 My preferred color is red
Fri Jan  5 08:14:32 UTC 2024 My preferred color is blue
Fri Jan  5 08:14:43 UTC 2024 My preferred color is blue
Fri Jan  5 08:15:00 UTC 2024 My preferred color is blue

通过 ConfigMap 在拥有 Sidecar 容器的 Pod 中更新配置

可以通过使用 Sidecar 容器 作为辅助容器来写入 HTML 文件,从而复制上述场景。
由于 Sidecar 容器在概念上是一个 Init 容器,因此它保证在主 Web 服务器容器之前启动。
这确保了 HTML 文件在 Web 服务器准备提供服务时始终可用。
请参阅 启用 Sidecar 容器 以使用此功能。

如果您要从上一个场景继续,可以使用名为 color 的 ConfigMap 来执行此场景。
如果您要独立执行此场景,请使用 kubectl create configmap 命令从 字面量值 创建 ConfigMap

kubectl create configmap color --from-literal=color=blue

以下是一个 Deployment 的清单示例,该清单管理一组 Pod,每个 Pod 都有一个主容器和一个 Sidecar 容器。这两个容器共享一个 emptyDir 卷,它们使用该卷进行通信。主容器运行一个 Web 服务器 (NGINX)。Web 服务器容器中共享卷的挂载路径为 /usr/share/nginx/html。第二个容器是一个基于 Alpine Linux 的 Sidecar 容器,用作辅助容器。对于该容器,emptyDir 卷挂载在 /pod-data 上。Sidecar 容器会写入一个 HTML 文件,其内容基于 ConfigMap。Web 服务器容器通过 HTTP 提供 HTML。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-sidecar-container
  labels:
    app.kubernetes.io/name: configmap-sidecar-container
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-sidecar-container
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-sidecar-container
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
      initContainers:
        - name: alpine
          image: alpine:3
          restartPolicy: Always
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;

创建 Deployment

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-and-sidecar-container.yaml

检查此 Deployment 的 Pod 以确保它们已准备就绪(通过 选择器 匹配)

kubectl get pods --selector=app.kubernetes.io/name=configmap-sidecar-container

您应该看到类似于以下内容的输出

NAME                                           READY   STATUS    RESTARTS   AGE
configmap-sidecar-container-5fb59f558b-87rp7   2/2     Running   0          94s
configmap-sidecar-container-5fb59f558b-ccs7s   2/2     Running   0          94s
configmap-sidecar-container-5fb59f558b-wnmgk   2/2     Running   0          94s

公开 Deployment(kubectl 工具为您创建一个 服务

kubectl expose deployment configmap-sidecar-container --name=configmap-sidecar-service --port=8081 --target-port=80

使用 kubectl 转发端口

# this stays running in the background
kubectl port-forward service/configmap-sidecar-service 8081:8081 &

访问服务。

curl http://localhost:8081

您应该看到类似于以下内容的输出

Sat Feb 17 13:09:05 UTC 2024 My preferred color is blue

编辑 ConfigMap

kubectl edit configmap color

在出现的编辑器中,将键 color 的值从 blue 更改为 green。保存更改。kubectl 工具将相应地更新 ConfigMap(如果出现错误,请重试)。

以下是您编辑后该清单可能的样子

apiVersion: v1
data:
  color: green
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-02-17T12:20:30Z"
  name: color
  namespace: default
  resourceVersion: "1054"
  uid: e40bb34c-58df-4280-8bea-6ed16edccfaa

在几秒钟内循环访问服务 URL。

# Cancel this when you're happy with it (Ctrl-C)
while true; do curl --connect-timeout 7.5 http://localhost:8081; sleep 10; done

您应该看到输出发生如下更改

Sat Feb 17 13:12:35 UTC 2024 My preferred color is blue
Sat Feb 17 13:12:45 UTC 2024 My preferred color is blue
Sat Feb 17 13:12:55 UTC 2024 My preferred color is blue
Sat Feb 17 13:13:05 UTC 2024 My preferred color is blue
Sat Feb 17 13:13:15 UTC 2024 My preferred color is green
Sat Feb 17 13:13:25 UTC 2024 My preferred color is green
Sat Feb 17 13:13:35 UTC 2024 My preferred color is green

通过作为卷挂载的不可变 ConfigMap 更新配置

下面显示了一个 不可变 ConfigMap 的示例清单。

apiVersion: v1
data:
  company_name: "ACME, Inc." # existing fictional company name
kind: ConfigMap
immutable: true
metadata:
  name: company-name-20150801

创建不可变 ConfigMap

kubectl apply -f https://k8s.io/examples/configmap/immutable-configmap.yaml

下面是一个带有不可变 ConfigMap company-name-20150801 的 Deployment 清单示例,该 ConfigMap 作为 挂载到 Pod 的唯一容器中。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: immutable-configmap-volume
  labels:
    app.kubernetes.io/name: immutable-configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: immutable-configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: immutable-configmap-volume
    spec:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The name of the company is $(cat /etc/config/company_name)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: company-name-20150801

创建 Deployment

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-immutable-configmap-as-volume.yaml

检查此 Deployment 的 Pod 以确保它们已准备就绪(通过 选择器 匹配)

kubectl get pods --selector=app.kubernetes.io/name=immutable-configmap-volume

您应该看到类似于以下内容的输出

NAME                                          READY   STATUS    RESTARTS   AGE
immutable-configmap-volume-78b6fbff95-5gsfh   1/1     Running   0          62s
immutable-configmap-volume-78b6fbff95-7vcj4   1/1     Running   0          62s
immutable-configmap-volume-78b6fbff95-vdslm   1/1     Running   0          62s

Pod 的容器引用 ConfigMap 中定义的数据,并使用它将报告打印到标准输出。你可以通过查看该 Deployment 中某个 Pod 的日志来检查此报告。

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployments/immutable-configmap-volume

您应该看到类似于以下内容的输出

Found 3 pods, using pod/immutable-configmap-volume-78b6fbff95-5gsfh
Wed Mar 20 03:52:34 UTC 2024 The name of the company is ACME, Inc.
Wed Mar 20 03:52:44 UTC 2024 The name of the company is ACME, Inc.
Wed Mar 20 03:52:54 UTC 2024 The name of the company is ACME, Inc.

使用下面显示的清单创建一个新的不可变 ConfigMap。

apiVersion: v1
data:
  company_name: "Fiktivesunternehmen GmbH" # new fictional company name
kind: ConfigMap
immutable: true
metadata:
  name: company-name-20240312
kubectl apply -f https://k8s.io/examples/configmap/new-immutable-configmap.yaml

您应该看到类似于以下内容的输出

configmap/company-name-20240312 created

检查新创建的 ConfigMap。

kubectl get configmap

你应该看到显示旧和新 ConfigMap 的输出。

NAME                    DATA   AGE
company-name-20150801   1      22m
company-name-20240312   1      24s

修改 Deployment 以引用新的 ConfigMap。

编辑 Deployment

kubectl edit deployment immutable-configmap-volume

在出现的编辑器中,更新现有的卷定义以使用新的 ConfigMap。

volumes:
- configMap:
    defaultMode: 420
    name: company-name-20240312 # Update this field
  name: config-volume

您应该看到以下输出

deployment.apps/immutable-configmap-volume edited

这将触发滚动更新。等待所有以前的 Pod 终止,并等待新的 Pod 进入就绪状态。

监视 Pod 的状态

kubectl get pods --selector=app.kubernetes.io/name=immutable-configmap-volume
NAME                                          READY   STATUS        RESTARTS   AGE
immutable-configmap-volume-5fdb88fcc8-29v8n   1/1     Running       0          13s
immutable-configmap-volume-5fdb88fcc8-52ddd   1/1     Running       0          14s
immutable-configmap-volume-5fdb88fcc8-n5jx4   1/1     Running       0          15s
immutable-configmap-volume-78b6fbff95-5gsfh   1/1     Terminating   0          32m
immutable-configmap-volume-78b6fbff95-7vcj4   1/1     Terminating   0          32m
immutable-configmap-volume-78b6fbff95-vdslm   1/1     Terminating   0          32m

你最终应该看到类似于以下内容的输出

NAME                                          READY   STATUS    RESTARTS   AGE
immutable-configmap-volume-5fdb88fcc8-29v8n   1/1     Running   0          43s
immutable-configmap-volume-5fdb88fcc8-52ddd   1/1     Running   0          44s
immutable-configmap-volume-5fdb88fcc8-n5jx4   1/1     Running   0          45s

查看此 Deployment 中某个 Pod 的日志

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployment/immutable-configmap-volume

您应该看到类似于以下内容的输出

Found 3 pods, using pod/immutable-configmap-volume-5fdb88fcc8-n5jx4
Wed Mar 20 04:24:17 UTC 2024 The name of the company is Fiktivesunternehmen GmbH
Wed Mar 20 04:24:27 UTC 2024 The name of the company is Fiktivesunternehmen GmbH
Wed Mar 20 04:24:37 UTC 2024 The name of the company is Fiktivesunternehmen GmbH

一旦所有部署都迁移到使用新的不可变 ConfigMap,建议删除旧的 ConfigMap。

kubectl delete configmap company-name-20150801

摘要

对作为 Pod 上的卷挂载的 ConfigMap 的更改将在随后的 kubelet 同步后无缝可用。

对为 Pod 配置环境变量的 ConfigMap 的更改将在随后的 Pod 滚动更新后可用。

一旦 ConfigMap 被标记为不可变,就无法撤消此更改(你无法将不可变 ConfigMap 变为可变),你也无法对 databinaryData 字段的内容进行任何更改。你可以删除并重新创建 ConfigMap,或者创建一个新的不同的 ConfigMap。当你删除 ConfigMap 时,正在运行的容器及其 Pod 会保留对任何引用该现有 ConfigMap 的卷的挂载点。

清理

如果 kubectl port-forward 命令正在运行,请终止它们。

删除在教程期间创建的资源

kubectl delete deployment configmap-volume configmap-env-var configmap-two-containers configmap-sidecar-container immutable-configmap-volume
kubectl delete service configmap-service configmap-sidecar-service
kubectl delete configmap sport fruits color company-name-20240312

kubectl delete configmap company-name-20150801 # In case it was not handled during the task execution
最后修改时间:2024 年 7 月 17 日下午 9:39 PST:Clean up updating-configuration-via-a-configmap.md (860edc844f)