You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
A Deployment is the primary way to run stateless applications in Kubernetes. It declaratively describes a desired number of pod replicas and the pod template to use, and it manages rolling updates and rollbacks automatically.
If you create a bare pod and the node it runs on fails, the pod is gone. A Deployment creates a ReplicaSet behind the scenes, which in turn ensures the specified number of pod replicas are running at all times. If a pod crashes or a node disappears, the ReplicaSet controller creates a replacement.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
labels:
app: web-app
spec:
replicas: 3
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: web
image: my-registry/web-app:1.0.0
ports:
- containerPort: 3000
resources:
requests:
cpu: "200m"
memory: "256Mi"
limits:
cpu: "500m"
memory: "512Mi"
Key fields:
By default, Kubernetes uses a RollingUpdate strategy, which replaces old pods with new ones incrementally. You can tune two parameters:
The alternative strategy is Recreate, which terminates all pods before starting new ones — useful when the application cannot run two versions simultaneously.
# Apply or update a deployment
kubectl apply -f deployment.yaml
# Check rollout status
kubectl rollout status deployment/web-app
# Scale the deployment
kubectl scale deployment web-app --replicas=5
# Update the container image
kubectl set image deployment/web-app web=my-registry/web-app:2.0.0
# Rollback to the previous revision
kubectl rollout undo deployment/web-app
# View rollout history
kubectl rollout history deployment/web-app
A Deployment creates and manages ReplicaSets. Each time you update the pod template (e.g., change the image), a new ReplicaSet is created and the old one is scaled down. This is how rollbacks work — Kubernetes keeps a configurable history of old ReplicaSets and can restore any of them.
Deployments are intended for stateless applications. Kubernetes also provides:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.