Member-only story
Working with Kubernetes Secrets
1 min readFeb 6, 2021
Assuming your kube context and namespace that are of your interest are kube-ctx
and kube-ns
respectively
To create a secret (using yaml configuration file secret.yml
, see ex: below)
apiVersion: v1
kind: Secret
metadata:
name: secret-name
namespace: kube-ns
type: Opaque
data:
secret-key: MWYyZDFlMmU2N2Rm
Visit the documentation, to see a full list of available options for defining a secret
To apply the above configuration file
kubectl --context kube-ctx apply -f secret.yml
To list all secrets for a namespace
kubectl --context kube-ctx -n kube-ns get secrets
To describe a secret (assuming you are interested in the secret secret-name
), either use the describe option
kubectl --context kube-ctx -n kube-ns describe secret/secret-name
or the get option
kubectl --context kube-ctx -n kube-ns get secret/secret-name -o yaml
To decode (base64) the secret (assuming your secret key is secret-key
, which you can get from the Data
or data
section from the previous command outputs)
kubectl --context kube-ctx -n kube-ns get secret secret-name -o jsonpath={.data."secret-key"} | base64 -D