A pod is one or more containers sharing a network and storage. Bare pods are not replaced if they die, so you almost always use a Deployment.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels: { app: web }
template:
metadata:
labels: { app: web }
spec:
containers:
- name: web
image: nginx:1.20
ports: [{ containerPort: 80 }]
kubectl apply -f web.yaml
kubectl get pods -l app=web
kubectl set image deployment/web web=nginx:1.21
kubectl rollout status deployment/web
kubectl rollout undo deployment/web
The Deployment creates a ReplicaSet, which keeps three pods running. A rolling update replaces pods gradually, and rollout undo returns to the previous ReplicaSet. Generate YAML quickly with kubectl create deployment web --image=nginx:1.20 --dry-run=client -o yaml.