Version note: examples use the Kubernetes v1.35 documentation snapshot, not necessarily the newest release. Check current support and component compatibility. These commands were not tested on a live cluster.
What this guide covers
A Deployment describes how many application copies should run. It manages a ReplicaSet, which creates replacement Pods when the number falls below the requested count. Deleting one Pod does not delete the Deployment.
Before you start
Use a test cluster. Create controller-lab with kubectl create namespace controller-lab. This exercise deliberately deletes one test Pod.
Step 1: Create a Deployment
Save this as deployment.yaml, apply it, and wait for its rollout:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
namespace: controller-lab
spec:
replicas: 2
revisionHistoryLimit: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.28.0
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
memory: 128Mi
Use kubectl apply -f deployment.yaml and kubectl -n controller-lab rollout status deployment/web.
Step 2: Delete one Pod and watch
List the Pods, replace the placeholder with one actual name, and delete only that Pod:
kubectl -n controller-lab get deployment,replicaset,pod
kubectl -n controller-lab get pods -l app=web -o name
# Copy one returned Pod name into the next command.
kubectl -n controller-lab delete pod CHOSEN_POD_NAME
kubectl -n controller-lab get pods -l app=web --watch
The replacement has a different Pod name and identity. Stop the watch with Ctrl+C. If you want to stop the application, change or remove its owning Deployment instead.
Step 3: Investigate missing replacements
Inspect the Deployment and events:
kubectl -n controller-lab describe deployment web
kubectl -n controller-lab get replicasets -l app=web
kubectl -n controller-lab get events --sort-by=.metadata.creationTimestamp
kubectl -n kube-system get pods -l component=kube-controller-manager
Requested replicas, created Pods and ready Pods are different counts. Image failures, insufficient node resources and readiness failures can prevent the ready count from reaching the requested count.
Check the result
The Deployment should return to its requested ready-replica count. Multiple replicas on one worker still fail together if that worker is lost.
Conversation
0 commentsNo comments yet. Start the conversation below.