如何将多个 configmap 放在 kubernetes 的同一个挂载路径中?

How can I put multi configmap in the same mount path in kubernetes?

我有两个 python 文件,testing_1.pytesting_2.py。 然后,我创建了配置映射 testing-config1 来存储 testing_1.pytesting-config2 分别存储 testing_2.py

在 Kubernetes yaml 中,

...
      containers:
      - name: spark-master
        image: bde2020/spark-master:2.4.4-hadoop2.7
        volumeMounts:
        - name: testing
          mountPath: /jobs
        - name: testing2
          mountPath: /jobs
      volumes:
        - name: testing
          configMap:
            name: testing-config1
        - name: testing2
          configMap:
            name: testing-config2
...

最终结果中,路径只包含testing_1.py.

您可以将两个文件放在同一个 ConfigMap 中。

或者,使用 projected 卷:

A projected volume maps several existing volume sources into the same directory.

Currently, the following types of volume sources can be projected:

  • secret
  • downwardAPI
  • configMap
  • serviceAccountToken

您可以通过在指定路径时提供 subPath 来完成。更改如下:

containers:
      - name: spark-master
        image: bde2020/spark-master:2.4.4-hadoop2.7
        volumeMounts:
        - name: testing
          mountPath: /jobs/testing_1.py
          subPath: testing_1.py
        - name: testing2
          mountPath: /jobs/testing_2.py
          subPath: testing_2.py
      volumes:
        - name: testing
          configMap:
            name: testing-config1
        - name: testing2
          configMap:
            name: testing-config2