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.