IT 3300 : Virtualization

Kubernetes — Deployments

The controller you'll actually use

  • A Deployment manages a set of identical pods
  • It keeps the desired number running (self-healing)
  • It handles scaling and rolling updates
  • Under the hood it manages a ReplicaSet

The hierarchy

Deployment
  -> ReplicaSet (a specific version + replica count)
       -> Pods (the running copies)

You manage the Deployment; it manages the rest.

A Deployment manifest

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.27
          ports:
            - containerPort: 80

Labels & selectors

  • Labels are key/value tags on objects (app: web)
  • The Deployment's selector finds the pods it owns by label
  • Services use the same mechanism to find pods
  • Labels are the glue that connects Kubernetes objects

Create and scale

    kubectl apply -f deploy.yaml
    kubectl get deployments
    kubectl scale deployment web --replicas=5
  • Kill a pod (kubectl delete pod ...) and watch a new one appear —
    self-healing in action

Rolling updates

    kubectl set image deployment/web web=nginx:1.27.1
    kubectl rollout status deployment/web
  • k8s replaces pods gradually — no downtime
  • Old ReplicaSet scales down as the new one scales up

Rollbacks

    kubectl rollout history deployment/web
    kubectl rollout undo deployment/web
  • Bad release? Roll back to the previous ReplicaSet in seconds
  • This is why "desired state + version history" is powerful

Lab goals

  • Deploy 3 replicas; delete a pod and watch it heal
  • Roll out an image update and observe the gradual replacement
  • Break the update on purpose, then roll it back