Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I mount a single file from a secret in Kubernetes?

How can I mount a 'single' file from a secret?

I've created a secret with:

kubectl create secret generic oauth \
        --from-file=./.work-in-progress/oauth_private.key \
        --from-file=./.work-in-progress/oauth_public.key \

How can I mount the oauth_private.key file as a single file, rather than overriding the entire path with a directory that ONLY contains the two files (and potentially removing files that existed on the container initially)?

like image 230
Chris Stryczynski Avatar asked Nov 14 '18 08:11

Chris Stryczynski


People also ask

How do I get data from secret Kubernetes?

Using Secrets as files from a Pod If you want to access data from a Secret in a Pod, one way to do that is to have Kubernetes make the value of that Secret be available as a file inside the filesystem of one or more of the Pod's containers. To configure that, you: Create a secret or use an existing one.

How do I decode a secret file in Kubernetes?

For this demonstration we will create a simple secret with username and password for database. Run the kubectl create secret command to create an Secret object the Kubernetes API server. You can as well output encoded data and decode with base64.


1 Answers

You can do as bellow:

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: redis
    volumeMounts:
    - name: foo
      mountPath: "/etc/foo"
      readOnly: true
  volumes:
  - name: foo
    secret:
      secretName: mysecret
      items:
      - key: username
        path: my-group/my-username

Suppose mysecret contains username and password. Above yaml will mount only username in /etc/foo/my-group/my-username directory.

For more details check this: Using Secrets as Files from a Pod

like image 109
Emruz Hossain Avatar answered Sep 19 '22 16:09

Emruz Hossain