← Lessons

quiz vs the machine

Gold1380

System Design

Kubernetes Deployment and Scaling

Declarative Deployments, ReplicaSets, and how Kubernetes scales pods up and down.

5 min read · core · beat Gold to climb

Declarative desired state

A Deployment describes the desired state of your app such as which image to run and how many replicas to keep. Kubernetes continuously works to make the actual state match that desired state. You do not issue step by step commands, you declare an outcome.

ReplicaSets

A Deployment manages a ReplicaSet, which ensures a fixed number of identical pods are running. If a pod dies, the ReplicaSet creates a replacement to keep the replica count correct.

Rolling updates

When you change the image, the Deployment performs a rolling update. It gradually starts new pods and removes old ones, so the app stays available. If something goes wrong you can roll back to the previous version.

Scaling

  • Manual scaling set the replica count directly.
  • Horizontal Pod Autoscaler adjusts replicas based on metrics like CPU usage.

Scaling pods only helps if your nodes have spare capacity. A cluster autoscaler can add nodes when pods cannot be placed.

Key idea

A Deployment declares desired state and manages a ReplicaSet to keep pods running, enabling rolling updates, rollbacks, and automatic horizontal scaling.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a Deployment manage to keep a fixed number of pods running?

2. How does a rolling update keep the app available?

3. What does the Horizontal Pod Autoscaler adjust?