Lab outcome
First-hand evidence of desired state, replica replacement, scaling, Service selection, and namespace cleanup.
kubectl installed. A disposable Kubernetes cluster with a working container runtime. Permission to create and delete a namespace, Deployment, Service, and Pods.Guided procedure
Complete the lab 01 Verify the cluster context The most important command in this lab is the first one: prove that kubectl targets a disposable cluster.
Shell bash
kubectl config current-context
kubectl cluster-info
kubectl auth can-i create deployments.appsCheckpoint
• The context is local or explicitly designated for learning. • The authorization check returns yes. 02 Create an isolated workload Use a namespace so every lab resource has one cleanup boundary. A Deployment owns the Pods through a ReplicaSet.
Shell bash
kubectl create namespace dr-lab
kubectl create deployment atlas-web --image=nginx:stable-alpine --replicas=3 -n dr-lab
kubectl rollout status deployment/atlas-web -n dr-lab --timeout=120s
kubectl get deployment,replicaset,pods -n dr-labCheckpoint
• The Deployment reports 3/3 available replicas. • Three Pods are Ready. 03 Expose the Deployment inside the cluster Create a ClusterIP Service and inspect its selector and endpoints. No public load balancer is created.
Shell bash
kubectl expose deployment atlas-web --port=80 --target-port=80 --type=ClusterIP -n dr-lab
kubectl get service,endpoints -n dr-lab
kubectl describe service atlas-web -n dr-labCheckpoint
• The Service selector is app=atlas-web. • The endpoints correspond to the available Pods. 04 Delete one Pod and watch desired state recover Delete one managed Pod. The Deployment's ReplicaSet should create a new Pod so the observed state returns to three replicas.
PowerShell powershell
$env:VICTIM_POD = kubectl get pods -n dr-lab -l app=atlas-web -o jsonpath='{.items[0].metadata.name}'
kubectl delete pod $env:VICTIM_POD -n dr-lab
kubectl wait --for=condition=Ready pod -l app=atlas-web -n dr-lab --timeout=120s
kubectl get pods -n dr-lab -l app=atlas-web -o wideCheckpoint
• The deleted Pod name disappears. • A replacement Pod appears and the Ready count returns to three. 05 Scale the desired state Change the Deployment from three to five replicas and verify that the controller converges on the new target.
Shell bash
kubectl scale deployment/atlas-web --replicas=5 -n dr-lab
kubectl rollout status deployment/atlas-web -n dr-lab --timeout=120s
kubectl get deployment,pods -n dr-labCheckpoint
• The Deployment reports five desired and five available replicas. • The Service has endpoints for the Ready Pods. The workload reaches three Ready replicas before the failure test. Deleting one managed Pod causes a different Pod to be created. Scaling to five changes both desired state and observed state. All resources live inside the dr-lab namespace.Delete the dedicated namespace, which removes the Deployment, ReplicaSet, Pods, and Service together. Confirm the namespace is gone.
Shell
kubectl delete namespace dr-lab
kubectl get namespace dr-lab