DEV Community

Sathish
Sathish

Posted on • Originally published at sathishsaravanan.com

Understanding Pods in Kubernetes

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

Enter fullscreen mode Exit fullscreen mode

To see more detail:

kubectl describe pod <pod-name>

Enter fullscreen mode Exit fullscreen mode

Creating a Pod

With a command

kubectl run myapp --image=nginx

Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

To apply it:

kubectl apply -f pod.yaml
Enter fullscreen mode Exit fullscreen mode

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 PolicyAlways, 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)