Executing a command in a container
Executing a command in a container
TL;DR
- Execute a Command in a Container
- Get a Shell in a Container
Executing Commands
Motivation
Debugging Workloads by running commands within the Container. Commands may be a Shell with a tty.
Exec Command
Run a command in a Container in the cluster by specifying the Pod name.
kubectl exec nginx-78f5d695bd-czm8z ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
Exec Shell
To get a Shell in a Container, use the -t -i
options to get a tty and attach STDIN.
kubectl exec -t -i nginx-78f5d695bd-czm8z bash
root@nginx-78f5d695bd-czm8z:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
Specifying the Container
For Pods running multiple Containers, the Container should be specified with-c <container-name>
.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.
Last modified September 30, 2020: SIG CLI docs - guide changes (d705a6d)