kubectl exec: Running Commands in Pods

Let's execute different commands inside running containers.

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

Use the following terminal to test all the commands from this lesson.

Get hands-on with 1400+ tech skills courses.