Kubernetes pods are the smallest units of execution in Kubernetes. We’ll explore concepts behind Kubernetes pods and how to manage them using
kubectl. Keep reading to find out more.
I assume that you’ve already heard about Kubernetes and want to explore more. Today, we’ll explore Kubernetes Pods and how to manage them using
Kubernetes Pods Concepts
Kubernetes pod is the most basic Kubernetes object. It’s also the smallest unit of execution in Kubernetes.
Few facts about Kubernetes pods. They:
- wrap containers and provide an environment for them.
- run on a Kubernetes Node.
- provide horizontal scaling for Kubernetes.
- live only once.
- get a unique virtual IP address.
- multiple pods may run on a single node.
You can view pods as VMs or physical machines. Hence, pod loopback interface (localhost) is shared between the containers. It’s also true regarding memory and volumes. In addition, containers in the same pod have to bind to different ports. Of course, containers in different pods can use the same ports.
While it’s possible to run multiple containers in a pod, you usually do it in exceptional cases when pod containers need to be tightly coupled.
Next, let’s see how to manage Kubernetes pods using
Install on your machine:
The tutorial assumes familiarity with basic git, docker, docker-compose and
Manage Kuberenetes Pods using kubectl
If you come from Docker world, you probably wonder how to run container in a pod. Below, we’ll see basic CRUD
kubectl commands for pods management.
For that purpose, let’s start multi-node Kubernetes cluster using
minikube start --nodes 2 -p multinode-demo
Our Kubernetes cluster will have 2 nodes:
$ kubectl get nodes NAME STATUS ROLES AGE VERSION multinode-demo Ready control-plane,master 86s v1.21.2 multinode-demo-m02 NotReady <none> 51s v1.21.2
- Next let’s run 2 pods. One will run
$ kubectl run apache --image=httpd
- And another one will run
kubectl run wordpress --image=wordpress
docker run, right?
- Let’s view the pods (similar to
$ kubectl get pods NAME READY STATUS RESTARTS AGE apache 1/1 Running 0 17m wordpress 1/1 Running 0 15m
- You wonder how to access the pods? In
dockerworld we published container ports. In
Kubernetesworld we’ll use port-forwarding.
wordpress80 port to 8090 port on your workstation in a new terminal.
$ minikube -p multinode-demo kubectl -- port-forward wordpress 8090:80
- Now, navigate to http://localhost:8090/ and observe WordPress installation screen:
apache80 port to 8080 port on your workstation in a new terminal.
minikube -p multinode-demo kubectl -- port-forward apache 8080:80
- Navigate to http://localhost:8080/ and you should see
It works!in your browser.
- Let’s launch Kubernetes dashboard in original terminal where we ran
minikube -p multinode-demo dashboard
A browser will show our Kubernetes cluster workloads which are 2 pods.
docker rmequivalent is
kubectl remove. Let’s remove the pods:
$ kubectl delete pod wordpress apache pod "wordpress" deleted pod "apache" deleted
- Finally, let’s let’s stop our cluster:
$ minikube stop -p multinode-demo
Note, that you can find more useful information in kubectl for Docker Users. Also, you would usually run pods using Kubernetes deployments. We’ll cover them in later posts.
That’s it about Kuberenetes pods. Of course, this post is mostly introductory. And we’ll definitely come back to Kubernetes pods in future posts. As always, feel free to share and comment.
- Become a Certified Kubernetes Administrator (CKA)!
- Become a Certified Kubernetes Application Developer (CKAD)!
- BUNDLE KUBERNETES FUNDAMENTALS & CKA CERTIFICATION (COURSE & CERTIFICATION) FOR THE BEST DEAL! $499 ONLY!
Recommended Kubernetes courses on Pluralsight:
Sign up using this link to get exclusive discounts like 50% off your first month or 15% off an annual subscription)
Recommended Kubernetes books on Amazon:
You may find interesting below articles I wrote: