ConfigMap 卷未作为卷与秘密一起安装

ConfigMap volume is not mounting as volume along with secret

我在部署 YAML 文件中引用了 Secrets 和 ConfigMap。秘密卷正在按预期安装,但不是 ConfigMap。

我创建了一个包含多个文件的 ConfigMap,当我执行 kubectl get configmap ... 它会显示所有预期值。此外,当我只创建 ConfigMaps 时,它可以很好地安装卷,但不能与 Secret 一起安装。

我试过不同的方案,将它们放在同一目录中以将它们分开,但似乎不起作用。

这是我的 YAML。我是否正确引用了 ConfigMap?

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-deployment
spec:
  selector:
    matchLabels:
      app: hello
  replicas: 1 # tells deployment to run 1 pod
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello
        image: XXX/yyy/image-50
        ports:
        - containerPort: 9009
          protocol: TCP      
        volumeMounts:
        - mountPath: /shared
          name: configs-volume
          readOnly: true
        volumeMounts:
        - mountPath: data/secrets
          name: atp-secret
          readOnly: true
      volumes:
      - name: configs-volume
        configMap:
          name: prompts-config
          key: application.properties
      volumes:
      - name: atp-secret
        secret:
          defaultMode: 420
          secretName: dev-secret
      restartPolicy: Always
      imagePullSecrets:
      - name: ocirsecrets

您有两个单独的 volumes: 列表和两个单独的 volumeMounts: 列表。当 Kubernetes 尝试在 Pod 规范中查找 volumes: 的列表时,它会在每个集合中找到最后一个匹配项。

volumes:
- name: configs-volume
volumes: # this completely replaces the list of volumes
- name: atp-secret

在这两种情况下,您都需要一个 volumes:volumeMounts: 键,然后这些键下有多个列表项。

volumes:
- name: configs-volume
  configMap: { ... }
- name: atp-secret                 # do not repeat volumes: key
  secret: { ... }
containers:
  - name: hello
    volumeMounts:
      - name: configs-volume
        mountPath: /shared
      - name: atp-secret           # do not repeat volumeMounts: key
        mounthPath: /data/secrets