All labs

Reliability lab · Cloud, Platform & Security

Deploy, scale, break, and recover a Kubernetes service

Create a small Deployment in an isolated namespace, expose it internally, delete a Pod deliberately, and observe the controller restore the desired replica count.

30–40 min Beginner kubectl · disposable cluster

Lab outcome

First-hand evidence of desired state, replica replacement, scaling, Service selection, and namespace cleanup.

Before you start

  • 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.

Shellbash
kubectl config current-context
kubectl cluster-info
kubectl auth can-i create deployments.apps

Checkpoint

  • 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.

Shellbash
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-lab

Checkpoint

  • 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.

Shellbash
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-lab

Checkpoint

  • 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.

PowerShellpowershell
$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 wide

Checkpoint

  • 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.

Shellbash
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-lab

Checkpoint

  • The Deployment reports five desired and five available replicas.
  • The Service has endpoints for the Ready Pods.

Verification

  • 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.

Cleanup

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