Contents

Kubernetes Rolling Updates and Rollbacks

Rollout and Versioning

What's the Version?
The Version is a image version of the container.
For example, nginx:1.7.0 to nginx:1.7.1

Rollout Commands

Rollout Status

1
kubectl rollout status deployment/myapp-deployment

Rollout History

1
kubectl rollout history deployment/myapp-deployment

Deployment Strategy

Let's assume
You need to upgrade nginx:1.7.0 to nginx:1.7.1 now.

Recreate

Recreate
Delete all application and create all application at a time.
So, during the time, users cannot access the application.

Rolling Update

Rolling Update
Delete a few PODs and create a few PODs at a time.
Then users can access the application even if it’s in the maintenance time.

Check Strategy of the Deployment

StrategyType
You just need to check StrategyType in the description of the deployment.
1
kubectl describe deployment myapp-deployment | grep -i strategy

Apply Upgrade

1
2
3
4
5
# Declarative - After edit YAML
kubectl apply -f deployment-definition.yaml

# Imperative
kubectl set image deployment/myapp-deployment nginx-container=nginx:1.7.1

Rollback

Command

1
kubectl rollout undo deployment/myapp-deployment

Check Upgrade Status

1
kubectl get replicasets
1
2
3
4
5
6
7
8
9
# Before rollback
NAME                            DESIRED     CURRENT     READY   AGE 
myapp-deployment-67c749c58c     0           0           0       22m 
myapp-deployment-7d57dbdb8d     5           5           5       20m

# After rollback
NAME                            DESIRED     CURRENT     READY   AGE 
myapp-deployment-67c749c58c     5           5           5       22m 
myapp-deployment-7d57dbdb8d     0           0           0       20m