K8s by Example: Deployments
| Deployments manage Pods via ReplicaSets. The hierarchy is: Deployment → ReplicaSet → Pods. Deployments add self-healing, scaling, rolling updates, and rollbacks on top of ReplicaSets. |
| deployment.yaml | |
| Deployments use the | |
| The Pod template defines what each replica looks like. Labels in the template must match the selector. | |
| terminal | |
| Kubernetes uses reconciliation loops to maintain desired state. Delete a Pod and watch the Deployment recreate it automatically. | |
| terminal | |
| Scale up and new Pods are created automatically. Scale down and excess Pods are terminated. | |
| rolling-update-strategy.yaml | |
| Two update strategies: | |
|
| |
| terminal | |
| Rolling updates create a new ReplicaSet and gradually shift Pods. Old ReplicaSets are kept (scaled to 0) for rollbacks. | |
| terminal | |
| Each update creates a new revision in the history. View all revisions with rollout history. | |
| terminal | |
| Update the image to trigger a rolling update. Watch the status with rollout status. | |
| terminal | |
| Rollbacks are fast because old ReplicaSets still exist. Kubernetes just scales them up and down. | |
| terminal | |
| Pause and resume rollouts for canary-style deployments. While paused, you can test new Pods before completing the update. | |