Pods in Kubernetes – A Practical Introduction
When learning Kubernetes, the first and most important concept to understand is the Pod. It is the base unit. Without understanding Pods properly, it is hard to work with other Kubernetes objects like Deployments, Services, or Jobs.
In this post, I will explain what a Pod is, how it behaves, how to create it, and how to work with it.
What is a Pod?
A Pod is the smallest deployable object in Kubernetes. It wraps one or more containers. In most cases, one Pod runs one container. But sometimes, you may need to run two or more containers inside one Pod. All containers in a Pod share:
- The same network IP address
- The same storage volumes (if defined)
- The same lifecycle
This means they can talk to each other like they are on the same machine, and they always run together on the same node.
When to Use Multiple Containers in a Pod
This is rare, but sometimes useful. For example:
- A helper container to push logs (sidecar)
- A container that prepares data before main app starts (init)
- Two processes that need fast communication or shared files
Pod Lifecycle – What Happens to a Pod
A Pod goes through these states:
- Pending – Kubernetes accepted the Pod, but containers are not started yet
- Running – Containers are up and running
- Succeeded – Containers finished with success
- Failed – Containers exited with errors
- Unknown – Node cannot report current state
You can check status with:
kubectl get pods
To see more detail:
kubectl describe pod <pod-name>
Creating a Pod
With a command
kubectl run myapp --image=nginx
This creates a Pod that runs nginx.
With a YAML file
Example YAML:
apiVersion: v1
kind: Pod
metadata:
name: mypod
labels:
app: demo
spec:
containers:
- name: mycontainer
image: nginx
To apply it:
kubectl apply -f pod.yaml
Useful Pod Concepts
- Labels and Selectors – To group Pods and work with Services
- Liveness and Readiness Probes – For checking container health
- Volumes – Shared data inside Pod
- Init Containers – Start before main container
- Environment Variables – Configuration for the app
- Resource Limits – Set CPU and memory limits
-
Restart Policy –
Always
,OnFailure
,Never
Troubleshooting Pods
Some common commands:
-
kubectl logs <pod-name>
– Check logs -
kubectl exec -it <pod-name> -- bash
– Go inside the container -
kubectl describe pod <pod-name>
– View full details -
kubectl delete pod <pod-name>
– Remove the Pod
If the Pod is stuck, check Events section in describe output.
Final Thoughts
Pods are the core building block in Kubernetes. Once you understand how they work, many other parts of the system will start to make sense. Practice creating, modifying, and deleting Pods often. That’s how you get comfortable working with them.
Start simple, and slowly build up.
Top comments (0)