CKAD field manual
k8s Pod YAML example
A Pod is one or more containers on one node. On the exam: kubectl run, dry-run to YAML, edit, apply.
kubectl run web --image=nginx:1.27 --restart=Never
kubectl run web --image=nginx:1.27 --restart=Never --port=80 --labels=app=web -o yaml --dry-run=client > pod.yaml
# edit pod.yaml
kubectl apply -f pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: web
namespace: default
labels:
app: web
spec:
restartPolicy: Never
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
kubectl get po web -o wide
kubectl describe po web
kubectl logs web
kubectl exec -it web -- sh
kubectl delete po web --force --grace-period=0
Fields
- spec
- Most of spec cannot be changed on a live Pod. Delete and recreate.
- restartPolicy
- Default is Always. Never = stay stopped. Jobs need Never or OnFailure.
- containers.name
- kubectl run names the container after the Pod. Set this if the question names it.
- ports
- Documents the port. Does not publish it. You still need a Service.
- containerPort
- Port inside the container. A Service targetPort should match this.
- kubectl run
- --restart=Never makes a one-shot Pod. Omit it and the default is Always.
- --dry-run
- Prints YAML only. Nothing is created until apply.
- kubectl describe
- Events live here. Use this first when the Pod is not Running.
- kubectl delete
- --force --grace-period=0 skips the graceful wait.
Watch
- kubectl run creates a Pod. --restart=Never for a one-shot. Default restartPolicy is Always.
- Most of spec cannot be changed on a live Pod. Delete and recreate.
- If the question names the container, set containers[0].name. kubectl run uses the Pod name.
Official docs Pods