Understanding Kubernetes Pods: The Building Blocks of Container Orchestration.


Pod are the smallest deployable units of computing that you can create and manage in kubernetes. A pod is like a small package that holds one or more related applications. Think of it like a lunchbox that contains different food items (applications) that need to be together. These applications share the same space, storage, and network, and they always run side by side.
Creating and Managing Pods
In kubernetes there are two ways to create a pod which is the imperative method and the declarative method. Let us take a look at these methods.
The imperative method is like giving direct commands to kubernetes, telling it exactly what to do in the moment just like manually starting a program on your computer. Let’s create an nginx pod that runs an nginx container
kubectl run nginx-pod --image=nginx
The command kubectl run nginx-pod --image=nginx creates a new Pod in Kubernetes named nginx-pod, running a container using the nginx image. This is an imperative way of deploying a Pod, meaning you’re giving a direct command for immediate execution. Kubernetes will pull the nginx image from a container registry (like Docker Hub) and start the Pod with that container.
The declarative method (using YAML manifests) is like writing a recipe that describes the desired state of your application, allowing Kubernetes to automatically ensure it matches that state. Imperative is quick for one-time tasks, while declarative is better for managing and maintaining consistent configurations over time. Let’s take a look at how create a tomcat pod that runs a tomcat container
Open the vi editor and create a file tomcat-pod.yaml
vi tomcat-pod.yaml
apiVersion: v1
apiVersion: v1
kind: Pod
metadata:
name: tomcat-pod
spec:
containers:
- name: tomcat
image: tomcat:9.0
ports:
- containerPort: 8080
With the vi tomcat-pod.yaml command a file named tomcat-pod.yaml is create with its content above. This YAML manifest defines a Pod named tomcat-pod in Kubernetes. It specifies that the Pod should run a single container named tomcat, using the tomcat:9.0 image. The container is set to listen on port 8080 inside the Pod.
Use this command below to run the initiate the pod creation from the tomcat-pod.yaml file.
kubectl apply -f tomcat-pod.yaml
We can go ahead to confirm that we have the tomcat-pod is running successfully. Use this command to check the state of the pod. The command kubectl get pods lists all the Pods running in the current Kubernetes cluster. It displays details like the Pod name, status (e.g., Running, Pending, Completed), number of restarts, and age.
kubectl get pods -o wide
In conclusion, Kubernetes Pods serve as the fundamental building blocks of container orchestration, providing a versatile and efficient way to manage applications. By understanding the two primary methods of creating and managing Pods imperative and declarative you can effectively deploy and maintain applications within a Kubernetes cluster.
Subscribe to my newsletter
Read articles from Obinna Iheanacho directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Obinna Iheanacho
Obinna Iheanacho
DevOps Engineer with a proven track record of streamlining software development and delivery processes. Skilled in automation, configuration management, and continuous integration and delivery (CI/CD), with expertise in cloud infrastructure and containerization technologies. Possess strong communication and collaboration skills, able to work effectively across development, operations, and business teams to achieve common goals. Dedicated to staying current with the latest technologies and tools in the DevOps field to drive continuous improvement and innovation.