>_ IzzyLab

Hands-on task

This task is step 4 of the course “Kubernetes: manifests from Namespace to RBAC”

Deployment with 3 replicas

easy~11 min

This sandbox has its own Kubernetes cluster: it takes longer to start than a regular sandbox, and kubectl is already configured. You need a Deployment web from the nginx:1.27-alpine image with 3 replicas, with its manifest in /root/deploy.yaml. You don't have to write it by hand — it's easier to generate it with a kubectl command in --dry-run=client -o yaml mode. Open the file in the Editor tab and see how kubectl linked the selector to the pod's labels. Then apply the manifest to the cluster and wait until all three replicas are ready.

What you'll practise:
  • kubernetes
  • kubectl
  • deployment
  • dry-run
  • manifest generation
  • kubectl apply

Topic breakdown

In prod, Kubernetes YAML manifests are almost never written from scratch — they're generated with imperative kubectl commands and the resulting draft is tweaked. The --dry-run=client -o yaml flag is the key technique: kubectl doesn't create the object in the cluster, it just prints the ready YAML to stdout, which can be redirected to a file. The value of generation is that kubectl itself correctly links selector.matchLabels with template.metadata.labels — the very pair of labels whose mismatch most often trips people up when writing by hand — and the result can be validated against schemas offline with kubeconform. The finished file goes to the cluster with kubectl apply -f: it creates the object or brings an existing one in line with the file. apply returns at once while the pods are still starting, so you wait for the rollout with kubectl rollout status — it finishes when all replicas are ready.

What's checked

  1. Manifest is valid against the schema
  2. The file has a Deployment with 3 replicas
  3. Name web, image nginx:1.27-alpine
  4. Deployment web is applied to the cluster
  5. 3 of 3 replicas are ready

What it looks like