kubectl-exec
executes a command in a container running in a pod
TLDR
Execute command in pod
SYNOPSIS
kubectl exec [options] pod-name -- command [args...]
DESCRIPTION
kubectl exec runs a command directly inside a container that is part of a running Kubernetes pod, functioning similarly to `docker exec`. It establishes a connection to the container's runtime environment through the Kubernetes API server and kubelet, allowing you to inspect files, run diagnostics, or open an interactive shell session.
The double dash (--) is required to separate kubectl flags from the command and its arguments that should be passed to the container. When combined with -i (stdin) and -t (tty) flags, it provides a fully interactive terminal session. For pods with multiple containers, the -c flag lets you specify which container to target.
PARAMETERS
-c, --container name
Container name in multi-container pod.-i, --stdin
Pass stdin to container.-t, --tty
Allocate TTY.-n, --namespace name
Kubernetes namespace.
SEE ALSO
kubectl(1), kubectl-attach(1)
