如何在kubernetes中把多个文件/secret挂载到公共目录中?

down 发表于: 2022-02-17   最后更新时间: 2022-02-17 23:15:13   1,445 游览

我有多个由不同文件创建的secret。我想把它们都存储在公共目录/var/secrets/中。不幸的是,我无法做到这一点,因为kubernetes抛出了 'Invalid value: "/var/secret": must be unique 错误,在pod验证步骤中。下面是我的pod定义的一个例子。

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: alpine-secret
  name: alpine-secret
spec:
  containers:
  - command:
    - sleep
    - "3600"
    image: alpine
    name: alpine-secret
    volumeMounts:
    - name: xfile
      mountPath: "/var/secrets/"
      readOnly: true
    - name: yfile
      mountPath: "/var/secrets/"
      readOnly: true
  volumes:
  - name: xfile
    secret:
      secretName: my-secret-one
  - name: yfile
    secret:
      secretName: my-secret-two

如何在同一目录下挂载多个secret的文件?

发表于 2022-02-17

Projected Volume

您可以使用一个projected在相同的目录中挂两个secrets。

例如

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: alpine-secret
  name: alpine-secret
spec:
  containers:
  - command:
    - sleep
    - "3600"
    image: alpine
    name: alpine-secret
    volumeMounts:
    - name: xyfiles
      mountPath: "/var/secrets/"
      readOnly: true
  volumes:
  - name: xyfiles
    projected:
      sources:
      - secret:
          name: my-secret-one
      - secret:
          name: my-secret-two
你的答案

查看kubernetes相关的其他问题或提一个您自己的问题