Skip to content
Search

Kubectl:exec

lastmod 2026-02-23created 2026-02-231 edits

Run inside a container

Simple usage

With a single container:

kubectl exec -it <pod-name> -- /bin/bash

For a multi-container Pod, specify the container with the -c option:

kubectl exec -it <pod-name> -c <container-name> -- /bin/bash

If you need to specify a namespace, add <cocde>-n</code>:

kubectl exec -it <pod-name> -n <namespace> -- /bin/bash

Listing containers

kubectl get pod <pod-name> -o jsonpath='{.spec.containers[*].name}'

If you need line breaks:

kubectl get pod <pod-name> -o jsonpath='{range .spec.containers[*]}{.name}{"\n"}{end}'

See also

author Zer0 sitemap