Kubernetes Pods
Kubernetes Pods
Section titled “Kubernetes Pods”A Pod is the smallest deployable unit in Kubernetes. It wraps one or more containers that share a network namespace and storage volumes.
Pod vs Container
Section titled “Pod vs Container”A Pod is not a container — it is a wrapper around one or more containers. Containers in the same pod:
- Share the same IP address and port space
- Can communicate via
localhost - Share mounted volumes
Most pods run a single container. Multi-container pods are used for sidecar patterns (e.g., a log shipper alongside the main app).
Minimal Pod Spec
Section titled “Minimal Pod Spec”apiVersion: v1kind: Podmetadata: name: my-app labels: app: my-appspec: containers: - name: my-app image: nginx:1.25 ports: - containerPort: 80Apply it:
kubectl apply -f pod.yamlPod Lifecycle Phases
Section titled “Pod Lifecycle Phases”| Phase | Meaning |
|---|---|
Pending | Accepted but not yet scheduled or image not yet pulled |
Running | At least one container is running |
Succeeded | All containers exited with code 0 |
Failed | At least one container exited with non-zero code |
Unknown | Node communication lost |
Resource Requests and Limits
Section titled “Resource Requests and Limits”Always set these to help the scheduler and protect other workloads:
resources: requests: memory: "64Mi" cpu: "250m" limits: memory: "128Mi" cpu: "500m"- requests — minimum guaranteed resources
- limits — maximum allowed before throttling (CPU) or OOM kill (memory)
Common kubectl Commands for Pods
Section titled “Common kubectl Commands for Pods”# List pods in current namespacekubectl get pods
# Detailed pod info (events, conditions, IP)kubectl describe pod my-app
# View logskubectl logs my-appkubectl logs my-app --previous # logs from last crashed container
# Open a shell inside the containerkubectl exec -it my-app -- /bin/sh
# Delete a podkubectl delete pod my-app
# Watch pod status changes livekubectl get pods -wLiveness and Readiness Probes
Section titled “Liveness and Readiness Probes”livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 10 periodSeconds: 5
readinessProbe: httpGet: path: /ready port: 8080 initialDelaySeconds: 5 periodSeconds: 3- liveness — restart the container if this fails
- readiness — remove the pod from service endpoints until this passes
Why Pods Are Ephemeral
Section titled “Why Pods Are Ephemeral”Never rely on a pod’s IP address or local file system. Pods can be rescheduled to different nodes at any time. Use:
- Services for stable network access
- PersistentVolumes for durable storage
- Deployments to manage pod lifecycle (not raw pods)
In practice, you almost never create bare pods — you create Deployments, which manage pods for you.