Topic 01: Pods Link to heading
A Pod is the smallest deployable unit in Kubernetes. You don’t deploy containers directly — you deploy Pods that contain containers. Containers in the same Pod share a network namespace (same IP, same localhost) and can share volumes. Usually one container per Pod — multiple containers is the sidecar pattern.
Pods are ephemeral. If a Pod dies, a controller replaces it — it’s not restarted in place.
YAML Link to heading
apiVersion: v1
kind: Pod
metadata:
name: web
labels:
app: web
tier: frontend
spec:
containers:
- name: web # container name — cannot be set imperatively
image: nginx
ports:
- containerPort: 80
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
cpu: 200m
memory: 128Mi
Common Patterns Link to heading
Command and args Link to heading
spec:
containers:
- name: runner
image: busybox
command: ["sh", "-c", "echo hello && sleep 3600"]
command overrides Docker ENTRYPOINT. args overrides Docker CMD. Both together override both.
Environment variables Link to heading
spec:
containers:
- name: app
image: nginx
env:
- name: PORT
value: "8080" # numeric values must be quoted
- name: DEBUG
value: "true"
Volume mount Link to heading
spec:
containers:
- name: app
image: nginx
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
emptyDir: {}
Imperative Link to heading
# Basic
k run web --image=nginx
# With labels
k run web --image=nginx --labels=app=web,tier=frontend
# With env vars
k run web --image=nginx --env=PORT=8080 --env=DEBUG=true
# With port
k run web --image=nginx --port=80
# In namespace
k run web --image=nginx -n production
# Generate YAML
k run web --image=nginx $do
# Force delete
k delete pod web --force --grace-period 0
# Exec into pod
k exec -it web -- sh
k exec -it web -c nginx -- sh # specific container in multi-container pod
# Logs
k logs web
k logs web -c nginx # specific container
k logs web --previous # crashed container
k logs web -f # follow
# Resource usage
k top pods
k top pod web
Common Mistakes Link to heading
- Numeric env values not quoted —
value: "8080"notvalue: 8080 containerPortis informational only — it doesn’t open or expose the port- Cannot name a container imperatively — container name defaults to pod name. Use
$doand edit YAML if a specific container name is required.
Exam Tips Link to heading
k describe pod <n>→ Events section shows scheduling or image pull failuresk get pod <n> -o wide→ shows node and pod IPk get pods --show-labels→ always run before writing a NetworkPolicy- Pod lifecycle: Pending → Running → Succeeded / Failed
restartPolicydefaults toAlways— Jobs requireNeverorOnFailure