Skip to content
Rahul Shishodiaon GitHub LinkedIn profile

Pods and Namespaces

Pods

  • Smallest deployable unit; usually 1 container per Pod
  • Pod IP not stable after restart: use Service for stable access
  • Creation flow: create → schedule → pull image → run container

Pod phases

PhaseMeaning
PendingAccepted; image/container not ready
RunningAt least one container running/starting
SucceededAll containers exited OK
FailedAt least one container failed
UnknownState unavailable
  • Container states (separate): Waiting, Running, Terminated

kubectl: Pods

kubectl run hazelcast --image=hazelcast:5.1.7 --port=5701 \
  --env="DNS_DOMAIN=cluster" --labels="app=hazelcast,env=prod"
kubectl apply -f pod.yaml
kubectl get po / kubectl get po <n> -o wide / -o yaml
kubectl describe po <n>          # events for debugging
kubectl logs <n> -f / kubectl logs <n> -p   # -p = previous instance
kubectl exec -it <n> -- /bin/sh
kubectl exec <n> -- env
kubectl run busybox --image=busybox:1.36.1 --rm -it --restart=Never -- wget <ip>:80
kubectl delete po <n> / kubectl delete po <n> --now   # exam time-saver

Pod configuration

env:
- name: SPRING_PROFILES_ACTIVE
  value: prod
command: ["/bin/sh"]      # overrides ENTRYPOINT
args: ["-c", "loop..."]   # overrides CMD
kubectl run mypod --image=busybox:1.36.1 -o yaml --dry-run=client > pod.yaml -- <cmd>

Namespaces

NSPurpose
defaultUser workloads without explicit NS
kube-systemSystem components (CoreDNS, etc.)
kube-public, kube-node-leaseSystem: don't use
kubectl create namespace code-red
kubectl run pod --image=nginx -n code-red
kubectl get po -n code-red
kubectl config set-context --current --namespace=code-red
kubectl config view --minify | grep namespace:
kubectl delete namespace code-red   # cascades: deletes all objects in NS

Exam tips

  • Exam often specifies a namespace: set context once with config set-context
  • kubectl logs -p after CrashLoopBackOff: previous container logs
  • -- separates kubectl flags from in-container command