kubectl exec runs a command inside a container in a running pod. It helps inspect an application from inside without logging in to the node hosting the pod. section 5.3.4
Use kubectl exec for one-off commands or an interactive shell:
- Run a process listing with `kubectl exec kiada -- ps aux`. section 5.3.4
- Test the application internally with `kubectl exec kiada -- curl -s localhost:8080`. section 5.3.4
- Open an interactive shell with `kubectl exec -it kiada -- bash`; `-i` passes standard input and `-t` allocates a terminal. section 5.3.4
- Inspect files, network interfaces, or connectivity from that shell using tools available inside the container. section 5.3.4
For a pod with multiple containers, select the target with `-c` or `--container`. Without that option, kubectl exec uses the first container in the pod manifest. section 5.4.3
$ kubectl exec kiada -- ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 1.3 812860 27356 ? Ssl 11:54 0:00 node app.js #1 root 120 0.0 0.1 17500 2128 ? Rs 12:22 0:00 ps aux #2
A process-listing example shows the command running inside the container alongside the application process. section 5.3.4
