Skip to content

Kubernetes: Environment, config & secrets of workloads

9 Kubernetes commands: Environment, config & secrets of workloads. Click a command to see what each part does.

Index
9 items
Click a command to see what each part does.

Environment, config & secrets of workloads9

  • kubectl exec <pod> -n <namespace> -- envPrint env vars of a running pod

    What each part does

    1. kubectl exec <pod>run in the pod (add -c <container>)
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    3. -- 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

    1. set env ... --listlist the env defined in the pod template, showing which come from configMapKeyRef / secretKeyRef
    2. -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)Caution

    What each part does

    1. <KEY>=<value>add or change
    2. <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 file

    What each part does

    1. create configmap <name>new ConfigMap
    2. --from-literal=<key>=<value>one key/value
    3. --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 secret

    What each part does

    1. secret genericOpaque secret
    2. --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 secret

    What each part does

    1. 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 secret

    What each part does

    1. secret tlskubernetes.io/tls secret used by ingresses
    2. --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 secret

    What each part does

    1. -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

    1. --dry-run=client -o yamlgenerate the manifest without creating
    2. | kubectl apply -f -create or update it

    Tip Pods only see new values after a restart (env) or after the kubelet syncs (mounted files).

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…