LinuxCommandLibrary

kubectl-exec

TLDR

Execute command in pod

$ kubectl exec [pod-name] -- [command]
copy
Open interactive shell
$ kubectl exec -it [pod-name] -- /bin/sh
copy
Execute in specific container
$ kubectl exec [pod-name] -c [container] -- [command]
copy
Execute bash in pod
$ kubectl exec -it [pod-name] -- /bin/bash
copy

SYNOPSIS

kubectl exec [options] pod-name -- command [args...]

DESCRIPTION

kubectl exec executes a command in a container running in a pod. Similar to docker exec. The double dash (--) separates kubectl options from the command to execute.

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

Copied to clipboard