kubernetesmount-pointkubernetes-secretsapp-secret

kubernetes secret items not mounted as file path


I have the following yaml:

        volumeMounts:
        - name: app-secret
          mountPath: /app
          readOnly: true
      volumes:
      - name: app-secret
        secret:
          secretName: app-secret
          items:
          - key: app-secret.json
            path: appsettings.secret.json

I expect the secret is mounted on /app/appsettings.secret.json but it isn't. I don't know where it is mounted and the container crashes and I don't have a chance to kubectl exec into the container to inspect where the secret is mounted. My guess is that it wipes out the content of /app. Any advice and insight is appreciated.


Solution

  • This works:

     volumeMounts:
            - name: app-secret
              mountPath: /app/appsettings.secret.json
              subPath: appsettings.secret.json
              readOnly: true
          volumes:
          - name: app-secret
            secret:
              secretName: app-secret
              items:
              - key: app-secret.json
                path: appsettings.secret.json