Skip to content
thesarfo

Concept

Kubernetes: Deployments

How Deployments manage rolling updates and rollbacks over ReplicaSets, with an example manifest.

views 0

A Deployment provides declarative updates for Pods and ReplicaSets, enabling application scaling, rolling updates, and rollbacks. It maintains the desired state of applications and ensures that the right number of Pods are always running.

Deployments use a default RollingUpdate strategy for seamless version transitions but can also use the Recreate strategy for disruptive updates. When a Deployment is updated (e.g., changing the image version), it creates a new ReplicaSet while gradually replacing Pods from the old ReplicaSet.

Example YAML manifest:

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx-deployment
template:
metadata:
labels:
app: nginx-deployment
spec:
containers:
- name: nginx
image: nginx:1.20.2
ports:
- containerPort: 80

Key commands:

Terminal window
kubectl create -f def-deploy.yaml
kubectl create deployment nginx-deployment \
--image=nginx:1.20.2 --port=80 --replicas=3
kubectl create deployment nginx-deployment \
--image=nginx:1.20.2 --port=80 --replicas=3 \
--dry-run=client -o yaml > nginx-deploy.yaml
kubectl create -f nginx-deploy.yaml
kubectl create -f nginx-deploy.json

Deployment updates result in new ReplicaSets being created (e.g., updating from image 1.20.2 to 1.21.5), transitioning Pods from one revision to the next through a rolling update process.