我们可以使用不同的卷安装相同Configmap?

问题描述 投票:1回答:1

两个吊舱正在运行,并有不同的卷安装,但需要在运行2个荚使用相同configmap的。

kubernetes configmap
1个回答
2
投票

当然,你可以做到这一点。您可以安装相同ConfigMap成不同的音量。你可以看看到configure-pod-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和两个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
© www.soinside.com 2019 - 2024. All rights reserved.