Understanding Pods
The Pod is the most fundamental building block in Kubernetes. Every container you run, every application you deploy -- it all starts with a Pod.
What Is a Pod?
A Pod is the smallest deployable unit in Kubernetes. It represents a single instance of a running process in your cluster. A Pod wraps one or more containers and provides them with shared networking and storage.
Think of a Pod as an apartment. The containers inside are the roommates -- they share the same address (IP), the same front door (network namespace), and the same living space (storage volumes).
Single vs Multi-Container Pods
Single-container Pods are the most common pattern. One Pod, one container, one purpose.
Multi-container Pods are used when containers need to work closely together. Common multi-container patterns include:
- Sidecar -- a helper container that enhances the main container (like a logging agent)
- Init container -- runs before the main container to set things up (like running database migrations)
- Ambassador -- a proxy container that handles connections for the main container
In most cases, you will use single-container Pods.
Pod Lifecycle
A Pod moves through several phases during its lifetime:
| Phase | Meaning |
|---|---|
| Pending | The Pod has been accepted but containers are not yet running |
| Running | At least one container is running |
| Succeeded | All containers completed successfully (common for Jobs) |
| Failed | At least one container exited with an error |
| Unknown | The Pod status cannot be determined |
# Check the phase of your pods
kubectl get pods
# Get detailed status information
kubectl describe pod my-app
Creating a Pod Imperatively
The imperative approach creates a Pod directly from the command line:
# Run an nginx pod
kubectl run my-nginx --image=nginx
# Run a pod and immediately open a shell
kubectl run debug-pod --image=busybox -it --rm -- /bin/sh
This is great for quick testing and debugging.
Creating a Pod Declaratively
The declarative approach uses a YAML manifest file. This is the recommended method for production workloads.
apiVersion: v1
kind: Pod
metadata:
name: my-nginx
labels:
app: nginx
environment: dev
spec:
containers:
- name: nginx
image: nginx:1.27
ports:
- containerPort: 80
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
Apply the manifest:
# Create the pod from the YAML file
kubectl apply -f pod.yaml
# Check that it is running
kubectl get pod my-nginx
# See detailed information
kubectl describe pod my-nginx
# View the pod logs
kubectl logs my-nginx
# Delete the pod when done
kubectl delete pod my-nginx
Key Takeaways
- A Pod is the smallest deployable unit, wrapping one or more containers
- Single-container Pods are the most common pattern
- Pods have a lifecycle: Pending, Running, Succeeded, Failed, Unknown
- Imperative creation (
kubectl run) is fast for testing - Declarative creation (
kubectl apply -f) is best for reproducible, production workloads - Always define resource requests and limits in your Pod specs