Day 8/40 — Kubernetes Deployment, Replication Controller and ReplicaSet Explained

The eighth installment of the Tech Tutorials with Piyush 40-day CKA course. This session moves from standalone Pods to the workload controllers that guarantee high availability, self-healing, and zero-downtime updates in production Kubernetes.

Video Summary

This ~35-minute tutorial explains the three core Kubernetes workload controllers that manage Pod replication: ReplicationController (legacy), ReplicaSet (modern), and Deployment (the production standard). Piyush combines whiteboard theory with live terminal demonstrations using kubectl and YAML manifests.

Key Concepts Covered

1. Why Pods Need Controllers A bare Pod is a single point of failure. If it crashes, user traffic receives no response. Kubernetes controllers solve this by continuously monitoring the desired state (number of replicas) and reconciling the actual state — spinning up replacements automatically.

2. ReplicationController (Legacy)

  • apiVersion: v1, kind: ReplicationController
  • Ensures a specified number of Pod replicas are running at all times
  • Uses a template field inside spec to define the Pod blueprint (image, ports, labels)
  • If a Pod dies, the controller creates a new one from the template
  • Supports manual scaling by updating the replicas field
  • Limitation: Cannot adopt existing Pods that were not created by it

3. ReplicaSet (Modern Replacement)

  • apiVersion: apps/v1, kind: ReplicaSet
  • Functionally similar to ReplicationController but with a critical addition: selectors
  • The spec.selector.matchLabels field allows a ReplicaSet to manage existing Pods that match its label criteria, even if they were created independently
  • This makes ReplicaSets more flexible and is the reason Deployments use ReplicaSets under the hood
  • Scaling methods demonstrated:
    1. Edit YAML → kubectl apply -f
    2. Edit live object → kubectl edit rs <name>
    3. Imperative command → kubectl scale --replicas=10 rs/<name>

4. Deployment (Production Standard)

  • apiVersion: apps/v1, kind: Deployment
  • A higher-level abstraction that manages ReplicaSets, which in turn manage Pods
  • Key superpower: Rolling Updates
    • Updates Pods one-by-one (or in batches) so the application never goes offline
    • Old Pods serve traffic while new Pods are being created and health-checked
    • Ideal for production workloads like banking or trading platforms where downtime is unacceptable
  • Rollback capability
    • kubectl rollout history deployment/<name> — view revision history
    • kubectl rollout undo deployment/<name> — revert to the previous revision
  • Image updates
    • kubectl set image deployment/<name> container=image:tag — change container image on the live object

Hands-On Commands Demonstrated

CommandPurpose
kubectl apply -f rc.yamlCreate a ReplicationController
kubectl get rcList ReplicationControllers
kubectl get rsList ReplicaSets
kubectl get deployList Deployments
kubectl get allShow all resources in the namespace
kubectl describe pod <name>Inspect Pod details and events
kubectl scale --replicas=5 rs/<name>Scale a ReplicaSet imperatively
kubectl edit rs <name>Edit a live ReplicaSet object
kubectl set image deploy/<name> <container>=<image>:<tag>Update container image
kubectl rollout history deploy/<name>View deployment revision history
kubectl rollout undo deploy/<name>Roll back to previous revision
kubectl create deploy <name> --image=<image> --dry-run=client -o yaml > deploy.yamlGenerate a Deployment YAML via dry-run

YAML Structure Highlight

A Deployment manifest contains:

  • apiVersion: apps/v1
  • kind: Deployment
  • metadata (name, labels)
  • spec.replicas — desired number of Pods
  • spec.selector.matchLabels — which Pods to manage
  • spec.template — the Pod template (metadata + spec.containers)

Exam Tips Emphasized

  • Time is everything on the CKA exam. Prefer imperative commands (kubectl scale, kubectl create) over manual YAML editing when possible.
  • Use --dry-run=client -o yaml to quickly generate manifest skeletons, then modify and apply.
  • Know your shortcuts. The exam environment uses vi; practice Shift+A (append at end of line) and other vi navigation commands.
  • The cheat sheet is your friend. kubectl <command> --help provides copy-pasteable examples.

Sources

See Also

Wiki Concepts

Creator / Entity