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
| Phase | Meaning |
|---|
| Pending | Accepted; image/container not ready |
| Running | At least one container running/starting |
| Succeeded | All containers exited OK |
| Failed | At least one container failed |
| Unknown | State 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>
kubectl logs <n> -f / kubectl logs <n> -p
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
Pod configuration
env:
- name: SPRING_PROFILES_ACTIVE
value: prod
command: ["/bin/sh"]
args: ["-c", "loop..."]
kubectl run mypod --image=busybox:1.36.1 -o yaml --dry-run=client > pod.yaml -- <cmd>
Namespaces
| NS | Purpose |
|---|
default | User workloads without explicit NS |
kube-system | System components (CoreDNS, etc.) |
kube-public, kube-node-lease | System: 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
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