How to mount multiple files / secrets into common directory in kubernetes?

前端 未结 3 1262
无人及你
无人及你 2021-02-05 14:08

I\'ve multiple secrets created from different files. I\'d like to store all of them in common directory /var/secrets/. Unfortunately, I\'m unable to do that because

相关标签:
3条回答
  • 2021-02-05 14:29

    Edited: @Jonas answer is correct!

    However, if you use volumes as I did in the question then, short answer is you cannot do that, You have to specify mountPath to an unused directory - volumes have to be unique and cannot be mounted to common directory.

    Solution: What I did at the end was, instead keeping files in separate secrets, I created one secret with multiple files.

    0 讨论(0)
  • 2021-02-05 14:31

    Projected Volume

    You can use a projected volume to have two secrets in the same directory

    Example

    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
    
    0 讨论(0)
  • 2021-02-05 14:45

    (EDIT: Never mind - I just noticed @Jonas gave the same answer earlier. +1 from me)

    Starting with Kubernetes v1.11+ it is possible with projected volumes:

    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

    This is an example for "... how to use a projected Volume to mount several existing volume sources into the same directory".

    0 讨论(0)
提交回复
热议问题