Run a command in all pods

Runs the command in every pod that matches the label selector

kubectl get pods -n <ns> -l app=<label> -o name | xargs -I{} kubectl exec {} -n <ns> -- <cmd>

tool
kubectl73 commands
tags
podsdebug

More kubectl commands

  • kubectl get pods -n <ns> -w

    Keeps the pod list on screen and updates it when a status changes

  • kubectl top pods -A --sort-by=cpu

    Pod resource usage in all namespaces, sorted by CPU

  • kubectl create token <sa-name> -n <ns> --duration=1h

    Generates a short-lived bound token, here valid for 1 hour

  • kubectl auth can-i --list -n <ns>

    Shows everything the current user can do in the namespace

  • kubectl delete pods --all -n <ns>

    Forces all pods to be recreated; handy after a ConfigMap change

all 73 kubectl commands