Kubernetes – Run a Command in Pod’s Containers
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
Step 2. Verify if minikube is running or not
$ 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>
The above command will create a pod inside your minikube.
Step 4. View, the list of pods.
$ kubectl get pods
Now that our pod is created, let us enter inside our pod and run some commands.
Step 5. ssh into the minkube.
$ minikube ssh
Step 6. Check the list of all the running containers
$ docker ps -a
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
Now we are inside the Nginx-pod, let us run a few commands like ls, pwd, and cd.
So this is how we can use the minikube to deploy a pod and run a command inside it.
Please Login to comment...