5

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.

Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
  • the problem may be in your `containers[]` section. If not, then describe your pod using `$ kubectl describe` cmd. – Shudipta Sharma Jul 19 '19 at 07:10
  • Does you app also run from /app folder? Because I think the secret-mount will replace any contents of /app from your container image. Maybe try mounting as /config or similar. – Hitobat Jul 19 '19 at 08:27

3 Answers3

11

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
Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
0

Is it possible for you to share the full yaml to see if it has other issues and because of that it crashes for you?

I've tried this in my environment and it just works fine, please see the attached image.

tested on my env - see the following figure:

enter image description here

Shudipta Sharma
  • 5,178
  • 3
  • 19
  • 33
  • Does it overwrite the content of /app folder? I guess this happens which causes my application to crash because /app is root of the application. – Kok How Teh Jul 19 '19 at 07:17
-1

Yes, you're asumption is right. Mounting into the root folder will This is why we usually mount secrets under different folder, like /senstivie. I never tried @KOk , but it looks interesting - I'll be interesting to learn if it worked!

Anyway, if you want to see a real working example - this is the volume mount definition and this is the Dockerfile for an OSS project I built (Kamus, a solution for secrets encryption). It's similar to your use case - dotnet core, with appsettings.secrets.json. Please let me know if it didn't helped.

Omer Levi Hevroni
  • 1,935
  • 1
  • 15
  • 33