title | description |
---|---|
Kubernetes - Update Deployment |
Learn and Implement Kubernetes Update Deployment |
- We can update deployments using two options
- Set Image
- Edit Deployment
- Observation: Please Check the container name in
spec.container.name
yaml output and make a note of it and replace inkubectl set image
command
# Get Container Name from current deployment
kubectl get deployment my-first-deployment -o yaml
# Update Deployment - SHOULD WORK NOW
kubectl set image deployment/<Deployment-Name> <Container-Name>=<Container-Image>
kubectl set image deployment/my-first-deployment kubenginx=stacksimplify/kubenginx:2.0.0
- Observation: By default, rollout happens in a rolling update model, so no downtime.
# Verify Rollout Status
kubectl rollout status deployment/my-first-deployment
# Verify Deployment
kubectl get deploy
- Observation:
- Verify the Events and understand that Kubernetes by default do "Rolling Update" for new application releases.
- With that said, we will not have downtime for our application.
# Descibe Deployment
kubectl describe deployment my-first-deployment
- Observation: New ReplicaSet will be created for new version
# Verify ReplicaSet
kubectl get rs
- Observation: Pod template hash label of new replicaset should be present for PODs letting us know these pods belong to new ReplicaSet.
# List Pods
kubectl get po
- We should see
Application Version:V2
whenever we access the application in browser
# Get Load Balancer IP
kubectl get svc
# Application URL
http://<External-IP-from-get-service-output>
- Observation: We have the rollout history, so we can switch back to older revisions using revision history available to us.
# Verify Rollout History
kubectl rollout history deployment/my-first-deployment
# Update REVISION CHANGE-CAUSE
kubectl annotate deployment/my-first-deployment kubernetes.io/change-cause="Deployment UPDATE - App Version 2.0.0 - SET IMAGE OPTION"
# Verify Rollout History
kubectl rollout history deployment/my-first-deployment
# Edit Deployment
kubectl edit deployment/<Deployment-Name>
kubectl edit deployment/my-first-deployment
# Change From 2.0.0
spec:
containers:
- image: stacksimplify/kubenginx:2.0.0
# Change To 3.0.0
spec:
containers:
- image: stacksimplify/kubenginx:3.0.0
- Observation: Rollout happens in a rolling update model, so no downtime.
# Verify Rollout Status
kubectl rollout status deployment/my-first-deployment
# Describe Deployment
kubectl describe deployment/my-first-deployment
- Observation: We should see 3 ReplicaSets now, as we have updated our application to 3rd version 3.0.0
# Verify ReplicaSet and Pods
kubectl get rs
kubectl get po
- We should see
Application Version:V3
whenever we access the application in browser
# Get Load Balancer IP
kubectl get svc
# Application URL
http://<External-IP-from-get-service-output>
- Observation: We have the rollout history, so we can switch back to older revisions using revision history available to us.
# Verify Rollout History
kubectl rollout history deployment/my-first-deployment
# Update REVISION CHANGE-CAUSE
kubectl annotate deployment/my-first-deployment kubernetes.io/change-cause="Deployment UPDATE - App Version 3.0.0 - EDIT DEPLOYMENT OPTION"
# Verify Rollout History
kubectl rollout history deployment/my-first-deployment