Skip to content

Instantly share code, notes, and snippets.

@DStorck
Last active May 31, 2018 22:50
Show Gist options
  • Save DStorck/bd43cfc907d9892fff2b8e685445a71c to your computer and use it in GitHub Desktop.
Save DStorck/bd43cfc907d9892fff2b8e685445a71c to your computer and use it in GitHub Desktop.
# make secret with kubectl create secret generic my-secret --from-literal=key1=supersecret
# to use secret in a env var
apiVersion: v1
kind: Pod
metadata:
name: pod-secrets-to-env
namespace: default
spec:
containers:
- image: redis
name: redis
env:
- name:
ValueFrom:
secretKeyRef:
name: my-secret
key: key1
---
# use secret via file
apiVersion: v1
kind: Pod
metadata:
name: pod-secrets-via-file
namespace: default
spec:
containers:
- image: redis
name: redis
volumeMounts:
- mountPath: /secrets
name: foo
volumes:
- name: foo
secret:
secretName: my-secret
@DStorck
Copy link
Author

DStorck commented Aug 31, 2017

this assumes secret has been already created called my-secret with key1:<some_value>

@DStorck
Copy link
Author

DStorck commented Sep 7, 2017

That’s it for pod-via-file. You can check if it works by kubectl exec into the pod and looking for the file with ls -l / and finding the secrets folder. The key should be a filename in there, and cat’ing it should read the value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment