Kubernetes: Environment, config & secrets of workloads
9 Kubernetes commands: Environment, config & secrets of workloads. Click a command to see what each part does.
Kubernetes: Environment, config & secrets of workloadsIndex
- Whole sheet137
- Basics: cluster, namespaces & resources17
- Get & list resources23
- Context & namespace3
- Find resources9
- Debug: describe, events, logs8
- Exec, port-forward, copy4
- Deploy, roll out, roll back, scale7
- Cleanup & nodes4
- Services, DNS & networking checks6
- Environment, config & secrets of workloads9
- Create, generate & apply YAML10
- Patch, label, annotate & scale9
- Delete & force delete6
- Nodes, scheduling & access control11
- Productivity: aliases, contexts & output11
Environment, config & secrets of workloads9
kubectl exec <pod> -n <namespace> -- envPrint env vars of a running podWhat each part does
kubectl exec <pod>run in the pod (add -c <container>)-n <namespace>in this namespace (default: the context's namespace; -A for all)-- envprint all environment variables
kubectl set env deploy/<deployment> --list -n <namespace>Env vars set on a deployment (incl. from ConfigMaps/Secrets)What each part does
set env ... --listlist the env defined in the pod template, showing which come from configMapKeyRef / secretKeyRef-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl set env deploy/<deployment> <KEY>=<value> -n <namespace>; kubectl set env deploy/<deployment> <KEY>- -n <namespace>Set or remove an env var (triggers a rollout)CautionWhat each part does
<KEY>=<value>add or change<KEY>-trailing minus removes it
kubectl create configmap <name> --from-literal=<key>=<value> --from-file=<path> -n <namespace>Create a ConfigMap from literals or a fileWhat each part does
create configmap <name>new ConfigMap--from-literal=<key>=<value>one key/value--from-file=<path>file content (key = file name), or a whole directory
kubectl create secret generic <name> --from-literal=<key>=<value> -n <namespace>Create a generic secretWhat each part does
secret genericOpaque secret--from-literalvalue from the command line (lands in shell history: prefer --from-file or --from-env-file)
kubectl create secret docker-registry <name> --docker-server=<registry> --docker-username=<user> --docker-password=<token> -n <namespace>Create an image pull secretWhat each part does
secret docker-registrycredentials for a private registry; reference it in imagePullSecrets
kubectl create secret tls <name> --cert=<cert>.pem --key=<key>.pem -n <namespace>Create a TLS secretWhat each part does
secret tlskubernetes.io/tls secret used by ingresses--cert / --keyPEM certificate (with chain) and private key
kubectl get secret <secret> -n <namespace> -o go-template='{{range $k,$v := .data}}{{$k}}={{$v | base64decode}}{{"\n"}}{{end}}'Decode all keys of a secretWhat each part does
-o go-template='...'loop over every key and base64-decode the value
Tip Prints secrets in clear text on your screen.
kubectl create configmap <name> --from-file=<path> --dry-run=client -o yaml | kubectl apply -f -Update a ConfigMap from a file (apply-style)What each part does
--dry-run=client -o yamlgenerate the manifest without creating| kubectl apply -f -create or update it
Tip Pods only see new values after a restart (env) or after the kubelet syncs (mounted files).
Nothing matches.
My DevOps Playbook by Angelo John Calleja