Skip to content
Related Articles
Open in App
Not now

Related Articles

Kubernetes – Run a Command in Pod’s Containers

Improve Article
Save Article
Like Article
  • Difficulty Level : Easy
  • Last Updated : 30 Mar, 2023
Improve Article
Save Article
Like Article

Pre-requisite: Kubernetes

Kubernetes is also known as K8s is an open-source container orchestration tool developed by google which is used for automating software deployment, scaling, and management. Currently, it is being maintained by the cloud native computing foundation(CNCF).

K8s has two versions, the original Kubernetes and a mini version which is known as minikube.

The major difference between Kubernetes and minikube is that on minikube you only have a single node instead of a node cluster. Due to this, we do not have to go through the trouble of setting up the entire Kubernetes configuration.

Now let us see the working of commands inside a K8s pod. A pod in K8s is a single instance of an application and it is the smallest entity inside K8s.

Running Commands Inside a Pod:

Step 1. Start the minikube

$ minikube start
minikube start

 

Step 2. Verify if minikube is running or not

$ minikube status
minikube status

 

Now we have to deploy a pod, we are going to use a pod that will be running an image of NGINX inside it.

Step 3. Run a pod

$ kubectl run <pod_name> --image=<your_image_name>
Pod name is nginxpod

 

The above command will create a pod inside your minikube. 

Step 4. View, the list of pods.

$ kubectl get pods
pod status

 

Now that our pod is created, let us enter inside our pod and run some commands.

Step 5. ssh into the minkube.

$ minikube ssh
Inside minikube

 

Step 6. Check the list of all the running containers

$ docker ps -a
nginx pod

 

Now we will get inside the Nginx-pod and run some commands:

Step 7. Get inside the Pod

$ docker exec -it <Id_of_container> /bin/bash
working inside pod

 

Now we are inside the Nginx-pod, let us run a few commands like ls, pwd, and cd.

Output:

Running commands inside pod

 

So this is how we can use the minikube to deploy a pod and run a command inside it.

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!