Search⌘ K

kubectl exec: Running Commands in Pods

Explore how to run commands within Kubernetes pods using kubectl exec. Understand remote command execution and interactive shell sessions to manage containers effectively. Learn best practices and how pod hostnames correspond to pod names.

We'll cover the following...

The kubectl exec command is a great way to execute commands inside running containers.

We can use kubectl exec in two ways:

  1. Remote command execution

  2. Exec session

Remote command execution lets us send commands to a container from our local shell. The container executes the command and returns the output to our shell.

An exec session connects our local shell to the container’s shell and is the same as being logged on to the container.

Let’s look at both, starting with remote command execution.

Playground

...