You will define a Deployment and a Service in YAML, apply them, then perform a rolling update and rollback. By the end you will manage workloads declaratively, the way real clusters are operated under GitOps.

Learning Objectives

  • Write Deployment and Service manifests.
  • Perform a zero-downtime rolling update.
  • Roll back a bad release in one command.
  • Time: ~3 hours · Difficulty: Intermediate · Prereqs: a running cluster from the basics lab.

Architecture Overview

Environment Setup

You will need: a running cluster and kubectl context set.

Before you begin: keep manifests in a directory so you can version them in Git.

Step-by-Step Execution

01
Write the Deployment + Service
# web.yaml
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.25
---
apiVersion: v1
kind: Service
metadata: { name: web }
spec:
  selector: { app: web }
  ports: [{ port: 80 }]
02
Apply it
kubectl apply -f web.yaml && kubectl rollout status deploy/web
03
Roll out a new image version
$ kubectl set image deploy/web web=nginx:1.27 && kubectl rollout status deploy/web
deployment "web" successfully rolled out
04
Roll back if needed
kubectl rollout undo deploy/web

Progress So Far

Testing & Validation

kubectl rollout history deploy/web && kubectl get svc web

You should see multiple revisions and a Service with a ClusterIP. If so, you can deploy, update, and undo declaratively.

Troubleshooting
  • Rollout stuck: a new pod is crashing; inspect with kubectl describe and logs.
  • Service has no endpoints: the selector labels must match the pod labels exactly.
  • Image not updating: use a specific tag, not latest, so changes are detected.

Extension Ideas

  • Expose externally and add ingress in Kubernetes Networking.
  • Add readiness/liveness probes and resource limits.
  • Manage manifests with Kustomize or Helm under GitOps.

Key Results

  • Deployed a 3-replica workload from declarative YAML.
  • Performed a zero-downtime rolling update.
  • Rolled back a release in a single command.
  • Exposed pods through a stable Service ClusterIP.