What You Will Learn
Beginner
- What a Pod is and why it exists
- How to create a Pod
- Pod lifecycle and states
A Pod is the smallest deployable unit in Kubernetes. It contains one or more containers that share networking and storage. Usually, one container per Pod.
Why Pods, not containers?
Kubernetes could manage containers directly, but Pods add shared networking (same IP, ports) and shared volumes for tightly-coupled containers. 99% of Pods have exactly 1 container.pod.yamlyaml
apiVersion: v1
kind: Pod
metadata:
name: my-web
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
resources:
limits:
memory: "128Mi"
cpu: "250m"Terminalbash
# Create the Pod
kubectl apply -f pod.yaml
# Check it
kubectl get pods
kubectl describe pod my-web
# Access it
kubectl port-forward my-web 8080:80
# Open http://localhost:8080
# Delete
kubectl delete pod my-webPod States
| State | Meaning |
|---|---|
| Pending | Created but not yet running (pulling image, scheduling) |
| Running | Container is executing |
| Succeeded | Completed successfully (batch jobs) |
| Failed | Container exited with error |
| CrashLoopBackOff | Crashing repeatedly - check logs! |
Practical Exercise
Create pod.yaml with nginx:alpine
Apply: kubectl apply -f pod.yaml
Check: kubectl get pods - wait for Running
Port-forward: kubectl port-forward my-web 8080:80
Open browser: http://localhost:8080
Clean up: kubectl delete pod my-web
Key Takeaways
- Pod = smallest K8s unit. Usually 1 container per Pod.
- Containers in a Pod share networking (same IP) and volumes.
- Create: kubectl apply -f pod.yaml.
- States: Pending, Running, Succeeded, Failed, CrashLoopBackOff.
- Port-forward: kubectl port-forward to access locally.
Comments
Comments
Post a Comment