Pods β The Building Blocks
A Pod is the smallest deployable unit in Kubernetes. It is a wrapper around one or more containers that share storage, network, and a specification for how to run.
In most cases, you will run one container per Pod. But multi-container Pods are useful when containers need to share resources closely β like a web server and a sidecar logging agent.
Pod Lifecycle
Pod States:
ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
β Pending βββββΆβ Running βββββΆβSucceeded β β Failed β
β (waiting)β β (active) β β (completed) β (crashed) β
ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
β β
ββββββββββ¬ββββββββ
βΌ
Unknown
(status unclear)
Pending β Pod has been accepted but containers are not yet running. It might be waiting for scheduling or pulling images.
Running β At least one container is still running.
Succeeded β All containers terminated successfully (exit code 0).
Failed β At least one container terminated with a non-zero exit code.
Writing a Pod Manifest
apiVersion: v1
kind: Pod
metadata:
name: my-first-pod
labels:
app: hello
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
labels β Key-value pairs used to organize and select resources. You will use labels extensively in Kubernetes.
resources β Always set resource requests and limits. Requests help the scheduler place the pod; limits prevent a container from consuming too much.
Working with Pods
# Create a pod
kubectl apply -f pod.yaml
# List pods
kubectl get pods
# Describe a pod (see events and details)
kubectl describe pod my-first-pod
# View logs
kubectl logs my-first-pod
# Execute a command inside the pod
kubectl exec -it my-first-pod -- /bin/bash
# Delete a pod
kubectl delete pod my-first-pod
Why You Rarely Create Pods Directly
Pods are ephemeral. When a pod dies, it is gone forever. Instead of creating pods directly, you use Deployments and ReplicaSets to manage pod lifecycle automatically. We will cover that in the Workloads section.