Kubernetes 我们可以为不同的卷装载使用相同的Configmap吗?
两个吊舱正在运行,并且具有不同的卷装载,但是需要在两个运行的吊舱中使用相同的configmap。当然可以这样做。您可以将相同的Kubernetes 我们可以为不同的卷装载使用相同的Configmap吗?,kubernetes,configmap,Kubernetes,Configmap,两个吊舱正在运行,并且具有不同的卷装载,但是需要在两个运行的吊舱中使用相同的configmap。当然可以这样做。您可以将相同的ConfigMap装载到不同的卷中。你可以看看 比如说,您的ConfigMap如下所示: apiVersion: v1 kind: ConfigMap metadata: name: special-config namespace: default data: SPECIAL_LEVEL: very SPECIAL_TYPE: charm 和两个豆荚:
ConfigMap
装载到不同的卷中。你可以看看
比如说,您的ConfigMap
如下所示:
apiVersion: v1
kind: ConfigMap
metadata:
name: special-config
namespace: default
data:
SPECIAL_LEVEL: very
SPECIAL_TYPE: charm
和两个豆荚:
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
和两个pod
后的日志:
# 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
我收到一个错误,如“在抛出'std::ios\u base::failure'实例后终止调用”what():basic\u filebuf::underflow error读取文件“@Nancy yuo尝试过吗?它对我有用,也应该对你有用。我们可以将其中一个POD的“volumeMounts:-name:config volume mountPath:/etc/config”更改为volumeMounts:-name:config-volume-2 mountPath:/etc/config-2吗。。。配置映射保持sameLet me并发布结果。您可以按照名称字段的规则使用名称