kubectl 1.37 reference · Debugging
kubectl exec Command (kubectl)
Run a command in a container of a running pod, for example a shell, a database client or a quick check.
kubectl 1.37
Syntax
kubectl exec [-it] POD|TYPE/NAME [-c CONTAINER] -- COMMAND [ARGS...]
Parameters
| Parameter | Description |
|---|---|
-it |
Interactive terminal. |
-c CONTAINER |
Choose the container. |
-- COMMAND |
The command after a double dash. |
Examples
kubectl create namespace rc-ref-exec > /dev/null
trap 'kubectl delete namespace rc-ref-exec --wait=false > /dev/null' EXIT
kubectl -n rc-ref-exec run app --image=busybox:1.37 --env=MODE=demo -- sleep 3600 > /dev/null
kubectl -n rc-ref-exec wait --for=condition=Ready pod/app --timeout=120s > /dev/null
kubectl -n rc-ref-exec exec app -- sh -c 'echo MODE=$MODE; hostname'
Output
MODE=demo app
Run this on your computer — see “Get Started” for setup.
kubectl create namespace rc-ref-exec2 > /dev/null
trap 'kubectl delete namespace rc-ref-exec2 --wait=false > /dev/null' EXIT
kubectl -n rc-ref-exec2 create deployment cache --image=redis:8-alpine > /dev/null
kubectl -n rc-ref-exec2 rollout status deployment/cache --timeout=120s > /dev/null
kubectl -n rc-ref-exec2 exec deploy/cache -- redis-cli ping
Output
PONG
Run this on your computer — see “Get Started” for setup.
Related
kubectl logs· Print a container's logs from a pod, deployment or job; follow them, limit lines, or read the previous crashed container.kubectl debug· Debug pods and nodes with ephemeral containers or copies, even when the image has no shell or tools.- kubectl Essentials · tutorial