Create a ConfigMap from an env file and patch it in

Builds a ConfigMap from a KEY=VALUE file, then adds it to the container envFrom with a JSON patch

kubectl create configmap <name> --from-env-file=app.env -n <ns> --dry-run=client -o yaml | kubectl apply -f -; kubectl patch deploy/<name> -n <ns> --type=json -p='[{"op":"add","path":"/spec/template/spec/containers/0/envFrom/-","value":{"configMapRef":{"name":"<name>"}}}]'

tool
kubectl73 commands
tags
kubectlsecretsgitopsk8s

More kubectl commands

  • kubectl get pods -A -o wide

    Shows every pod with its node and IP address

  • kubectl describe pod <name> -n <ns>

    Shows events, conditions and volume mounts; the first stop when a pod is unhappy

  • kubectl logs -f <pod> -n <ns>

    Streams logs in real time; for a pod with several containers add -c <container>

  • kubectl logs <pod> --previous -n <ns>

    Logs from the container that crashed or restarted last time; the real error is usually here

  • kubectl exec -it <pod> -n <ns> -- bash

    Starts an interactive bash shell in a running container

all 73 kubectl commands