gpt4 book ai didi

kubernetes - 我们可以将相同的Configmap用于不同的卷安装吗?

转载 作者:行者123 更新时间:2023-12-02 12:05:08 25 4
gpt4 key购买 nike

两个Pod正在运行并且具有不同的卷安装,但是需要在2个正在运行的Pod中使用相同的configmap。

最佳答案

当然可以。您可以将相同的ConfigMap装入不同的卷。您可以看看configure-pod-configmap

假设您的ConfigMap如下:

apiVersion: v1
kind: ConfigMap
metadata:
name: special-config
namespace: default
data:
SPECIAL_LEVEL: very
SPECIAL_TYPE: charm

还有两个 pod :
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod-01
spec:
containers:
- name: test-container
image: busybox
command: [ "/bin/sh", "-c", "ls /etc/config/" ]
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
# Provide the name of the ConfigMap containing the files you want
# to add to the container
name: special-config
restartPolicy: Never
---
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod-02
spec:
containers:
- name: test-container
image: busybox
command: [ "/bin/sh", "-c", "ls /etc/config/" ]
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
# Provide the name of the ConfigMap containing the files you want
# to add to the container
name: special-config
restartPolicy: Never

现在,在创建上面的 ConfigMap和两个 Pods之后,查看日志:
# for 1st Pod
$ kubectl logs -f dapi-test-pod-01
SPECIAL_LEVEL
SPECIAL_TYPE

# for 2nd Pod
$ kubectl logs -f dapi-test-pod-02
SPECIAL_LEVEL
SPECIAL_TYPE

关于kubernetes - 我们可以将相同的Configmap用于不同的卷安装吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54628878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com