Comprehensive Guide to Task 3
; Rolling Updates in Kubernetes
Deployments test questions
and answers
1. Understanding Rolling Updates
A rolling update is Kubernetes' default deployment strategy that allows
you to update your application without downtime by gradually replacing
old Pods with new ones.
Key Characteristics:
Creates a new ReplicaSet for the updated version
Gradually scales up new Pods while scaling down old ones
Maintains application availability during the update
Enabled by default in Deployment objects
2. How Rolling Updates Work
The update process follows these steps:
1. New ReplicaSet Creation
Kubernetes creates a new ReplicaSet with the updated configuration
2. Gradual Pod Replacement
o Increments new Pod count (per maxSurge)
o Decrements old Pod count (per maxUnavailable)
o Continues until all old Pods are replaced
3. Old ReplicaSet Retention
Keeps old ReplicaSet for potential rollbacks
3. Initiating a Rolling Update
Method 1: Imperative Update
sh
Copy
,kubectl set image deployment/hello hello=kelseyhightower/hello:2.0.0
Method 2: Declarative Update (Editing YAML)
sh
Copy
kubectl edit deployment hello
Then modify:
yaml
Copy
containers:
- name: hello
image: kelseyhightower/hello:2.0.0
4. Monitoring the Update
Check ReplicaSets:
sh
Copy
kubectl get replicasets -w
Shows old and new ReplicaSets with their Pod counts.
View Rollout Status:
sh
Copy
kubectl rollout status deployment/hello
Sample output:
Copy
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
Check Pod Images:
sh
Copy
, kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}
{.spec.containers[0].image}{"\n"}{end}'
5. Controlling the Update Process
Pause a Rollout:
sh
Copy
kubectl rollout pause deployment/hello
Use cases:
Testing new version with partial traffic
Investigating issues during update
Resume a Rollout:
sh
Copy
kubectl rollout resume deployment/hello
Rollback Process:
sh
Copy
kubectl rollout undo deployment/hello
6. Update Strategy Configuration
Default strategy (can be customized in YAML):
yaml
Copy
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25% # How many extra Pods can be created
maxUnavailable: 25% # Max Pods that can be unavailable
Calculation Example (for 4 replicas):
; Rolling Updates in Kubernetes
Deployments test questions
and answers
1. Understanding Rolling Updates
A rolling update is Kubernetes' default deployment strategy that allows
you to update your application without downtime by gradually replacing
old Pods with new ones.
Key Characteristics:
Creates a new ReplicaSet for the updated version
Gradually scales up new Pods while scaling down old ones
Maintains application availability during the update
Enabled by default in Deployment objects
2. How Rolling Updates Work
The update process follows these steps:
1. New ReplicaSet Creation
Kubernetes creates a new ReplicaSet with the updated configuration
2. Gradual Pod Replacement
o Increments new Pod count (per maxSurge)
o Decrements old Pod count (per maxUnavailable)
o Continues until all old Pods are replaced
3. Old ReplicaSet Retention
Keeps old ReplicaSet for potential rollbacks
3. Initiating a Rolling Update
Method 1: Imperative Update
sh
Copy
,kubectl set image deployment/hello hello=kelseyhightower/hello:2.0.0
Method 2: Declarative Update (Editing YAML)
sh
Copy
kubectl edit deployment hello
Then modify:
yaml
Copy
containers:
- name: hello
image: kelseyhightower/hello:2.0.0
4. Monitoring the Update
Check ReplicaSets:
sh
Copy
kubectl get replicasets -w
Shows old and new ReplicaSets with their Pod counts.
View Rollout Status:
sh
Copy
kubectl rollout status deployment/hello
Sample output:
Copy
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
Check Pod Images:
sh
Copy
, kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}
{.spec.containers[0].image}{"\n"}{end}'
5. Controlling the Update Process
Pause a Rollout:
sh
Copy
kubectl rollout pause deployment/hello
Use cases:
Testing new version with partial traffic
Investigating issues during update
Resume a Rollout:
sh
Copy
kubectl rollout resume deployment/hello
Rollback Process:
sh
Copy
kubectl rollout undo deployment/hello
6. Update Strategy Configuration
Default strategy (can be customized in YAML):
yaml
Copy
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25% # How many extra Pods can be created
maxUnavailable: 25% # Max Pods that can be unavailable
Calculation Example (for 4 replicas):