Kubectl exec: Everything You Need To Know in 2026


The “kubectl exec” command helps you to get inside the running container by opening it and accessing its shell. The shell gives a command-line interface for the running commands and interact with the container’s environment, likely to running commands on our own computer’s command line.

In this article,we will explore abour kubectl exec and learn how to use “kubectl exec” to get a shell to the running container. So let’s get started.

What is Kubernetes?

Kubernetes is considered as one of the powerful container orchestration platform for deploying and managing the containerized applications effectively. However, managing containerized applications is more than about just getting them and running up. Sometimes, it requires to interact with containers to perform crucial tasks, like debugging issues or modifying the files or directories.

So, the question is now that how can you interact with the running container? The answer is simple; by using the “kubectl exec” command. Now let’s understand what is kubectl exec.

What is Kubectl Exec?
Kubectl

Kubectl is the command line tool for communicating with Kubernetes clusters with the help of Kubernetes API. You can utilize it to track the Kubernetes status, edit resources, apply manifest files, and what not. It is the general admin tool for the k8s clusters.

It majorly relies on your operating system whether you need to install kubectl separately. The packages for Kubernetes and Docker may install it for you.

Kubectl Exec

Exec is one of the kubectl’s most useful tools. You can utulize it to execute the command inside the container. If you are familiar with Docker, then kubectl’s exec might remind you of the Docker’s exec command.

Kubectl Exec Syntax

The syntax for the “kubectl exec” command is given below:

kubectl exec [OPTIONS] POD_NAME -- COMMAND [ARGS...]

Now let’s know what each part of the syntax tells:

1. kubectl exec: This is the command that is used to execute commands inside the container.

2. [OPTIONS]: These are the optional flags that you can pass to “kubectl exec” to modify the behavior. For instance, you can use this “-it” flag to run the command in the interactive mode.

3. POD_NAME: This is the name of the Pod that contains the container you need to execute commands in.

4. —: This is a separator that explains “kubectl exec” to treat all  the subsequent arguments as the command to execute inside container.

5. COMMAND: This is the command you might need to execute inside the container.

6. [ARGS…]: These are  the optional arguments to the command you might need to execute.

Open and Access the Container’s Shell Using Kubectl Exec

In this section, we’ll explore how to open and access a container’s shell using the “kubectl exec” command. I’ll walk you through an example that involves five simple steps.Open and Access the Container’s Shell Using Kubectl Exec

Step 1: Create a Deployment

Before we can execute shell commands inside a container, we need to create a Kubernetes deployment. Open a terminal and run the following command:

kubectl create deployment mynginx --image=nginx

This command creates a deployment resource named “mynginx” using the “nginx” Docker image. And the deployment creates a Pod that hosts the container running the “nginx” web server

Step 2: Check the Pod status

Once the deployment is created, we need to check the Pod status to ensure that it’s running correctly. To do this, run the following command:

kubectl get pods

This command will display a list of all the Pods running in your Kubernetes cluster. Look for the Pod with a name starting with “mynginx” and ensure that it’s in the “Running” state.

Step 3: Open and access the container’s shell

A shell is a program that provides a command-line interface for interacting with an operating system, including a container’s operating system. It allows you to enter commands and execute them within the container’s environment.

To open and access the shell of the container running the “nginx” web server, run the following command:

kubectl exec -it mynginx-56766fcf49-4b6ls -- /bin/bash

Here, “/bin/bash” is the command that will be executed inside the container running inside the “mynginx-56766fcf49-4b6ls” Pod. Because we have specified “bash”, you’ll see a Bash shell session that’s connected to the container.

You can now run any command that you would normally run using a shell. Before we jump into that, let’s explore the “-it” flag in more detail.

The “-it” flag is actually a combination of two flags: “-i” and “-t”.

The “-i” flag stands for “interactive” and tells “kubectl” that we want an interactive session with the container. This means that we’ll be able to send commands to the container and see its output.

The “-t” flag is used to allocate a pseudo-TTY (terminal) and tells “kubectl” that we want a terminal session with the container. This means that we’ll see the output from the container in a terminal window.

Without the “-t” flag, we won’t see the shell prompt. The output from the container will still be displayed, but we won’t be able to interact with the container’s shell. We won’t be able to execute any commands that require user input.

Step 4: Run commands using the shell

Now that we have access to the container’s shell, let’s run some commands inside the container. Let’s use the “curl” command to access the default page served by the “nginx” web server running inside the container. Run the command below:

curl http://localhost

After executing the command, you’ll see an output similar to this:

The output you see above is the content of the “index.html” file, which is the default page served by the “nginx” web server. Note that the “index.html” file is stored in the “/usr/share/nginx/html/” directory inside the container.

Now, let’s replace the contents of the “index.html” file with the text “Welcome to Floydee “. To do this, run the following command:

echo "Welcome to Floydee" > /usr/share/nginx/html/index.html

This command will write the text “Welcome to Floydee ” to the “index.html” file, effectively replacing its content.

Now, let’s execute the “curl” command again to verify that the change has been implemented successfully.

curl http://localhost

After executing the command, you’ll see an output similar to this:

As you can see, the default page is replaced with the text “Welcome to Floydee “.

Congratulations! You have now successfully interacted with a running container from it’s shell.

Step 5: Exit the container’s shell

To exit the container’s shell and back to the terminal, press the “CTRL + D” button or you can run the “exit” command.

Conclusion

In this post, we learned how to execute shell commands into a running container using the “kubectl exec” command. It is a powerful tool for managing and troubleshooting containerized applications in a Kubernetes cluster.

If you have a Docker container that is not yet deployed to a Kubernetes cluster, you can still execute shell commands inside the container using the “docker exec” command.

  • All
  • Uncategorized
  • Technology
  • Automotive and Aerospace
  • EdTech
  • HR
AI’s Biggest Constraint Isn’t Models. It’s Data Reliability
Artificial Intelligence has never been more powerful—or more misunderstood. Every few months, a new model promises sharper reasoning, faster responses, and more human-like interactions. Benchmarks improve, demos impress, and expectations rise. Yet, beneath this visible progress lies a quieter, more persistent limitation—one that no model upgrade has fully resolved. AI doesn’t struggle because it lacks intelligence. It struggles because it lacks reliable data. The Illusion of Progress At first glance, AI seems to be advancing at an extraordinary pace. Models can now: In reality, AI models are not designed to verify truth. They are designed to predict what comes next,…
Kubectl exec: Everything You Need To Know in 2026
The “kubectl exec” command helps you to get inside the running container by opening it and accessing its shell. The shell gives a command-line interface for the running commands and interact with the container’s environment, likely to running commands on our own computer’s command line. In this article,we will explore abour kubectl exec and learn how to use “kubectl exec” to get a shell to the running container. So let’s get started. What is Kubernetes? Kubernetes is considered as one of the powerful container orchestration platform for deploying and managing the containerized applications effectively. However, managing containerized applications is more…
Reimagining the Consumer Enterprise: AI & Automation Outlook (2025–2035)
This report presents a forward-looking perspective on how artificial intelligence, automation, and advanced analytics are set to reshape consumer-facing enterprises across manufacturing, retail, restaurants, and apparel. The insights below quantify productivity potential, role redesign implications, and capital investment considerations. 1. Automation Potential by Consumer Subsector By 2030, 30–35% of activities across consumer organizations could be enhanced or automated. By 2035, productivity gains may exceed 50% in manufacturing-heavy subsectors. 2. Functional Transformation Outlook Supply chain functions exhibit the highest automation potential due to repetitive, data-driven processes. Corporate functions such as finance and HR follow, while customer-facing commercial functions experience more gradual…
Sustainability and Efficiency : How Digital Twins Support Greener Automotive Solutions
Digital twins — high-fidelity virtual replicas of physical assets, processes, or systems — are shifting automotive engineering from costly physical iterations to fast, data-driven optimization. For an industry pushing to decarbonize while meeting customer demands for performance, safety and range, digital twins deliver concrete sustainability and efficiency gains across design, manufacturing and in-use vehicle operations. Below I present a reader-friendly deep dive with recent statistics, concise case examples, a short table of key metrics, and two downloadable charts (market projection and comparative energy-savings) you can use in presentations. Quick summary (TL;DR) Why digital twins matter for “green” vehicles Key use…
LMS Development Cost in 2026 – Complete Pricing Guide
Understanding LMS development cost is critical for businesses, educational institutions, and enterprises planning to build a learning management system tailored to their needs. Whether you are creating an LMS for corporate training, academic learning, or online courses, the total development cost can vary significantly depending on features, complexity, technology stack, and scalability requirements. A clear breakdown of LMS development cost helps decision-makers plan budgets accurately, avoid hidden expenses, and align technical investments with long-term learning goals. LMS Development Cost Breakdown LMS TypeEstimated LMS Development CostIdeal ForBasic LMS$15,000 – $30,000Small teams, startups, internal trainingMid-Level LMS$30,000 – $60,000SMBs, training providersAdvanced LMS$60,000 –…
7 Benefits of AI in HR: How AI Is Transforming HR
The benefits of AI in HR are becoming clearer as organizations seek to modernize their human resource practices. As workforces are expanding, remote work teams have been established, and HR processes have become data-intensive, the old methods are no longer adequate. The artificial intelligence (AI) can help the HR unit automate its routine and use workforce data to extract actionable insights and provide employees with more personalized experiences. Consequently, AI in HR is not only a trend but also a strategic requirement of contemporary organizations. What Is AI in HR? AI in HR can be defined as the application of artificial intelligence…