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)?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With