Monday, September 28, 2020

Rolling Updates and Rollbacks

 1. We have deployed a simple web application. Inspect the PODs and the Services Wait for the application to fully deploy and view the application using the link above your terminal.

master $ kubectl get deployment

NAME       READY   UP-TO-DATE   AVAILABLE   AGE

frontend   4/4     4            4           94s

master $ kubectl get pods

NAME                        READY   STATUS    RESTARTS   AGE

frontend-6bb4f9cdc8-hc8ws   1/1     Running   0          107s

frontend-6bb4f9cdc8-hjnmm   1/1     Running   0          107s

frontend-6bb4f9cdc8-nw9nb   1/1     Running   0          107s

frontend-6bb4f9cdc8-zb5v2   1/1     Running   0          107s

master $ kubectl get services

NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE

kubernetes       ClusterIP   10.96.0.1      <none>        443/TCP          16m

webapp-service   NodePort    10.98.32.239   <none>        8080:30080/TCP   111s


2. Run the script named curl-test.sh to send multiple requests to test the web application. Take a note of the output. Execute the script at /root/curl-test.sh.


master $ ls -ltr

total 8

drwxr-xr-x 4 root root 4096 Jul  8 08:30 go

-rwxr-xr-x 1 root root  215 Sep 29 02:45 curl-test.sh

master $ vi curl-test.sh

master $ sh -x curl-test.sh

+ kubectl exec --namespace=kube-public curl -- sh -c test=`wget -qO- -T 2  http://webapp-service.default.svc.cluster.local:8080/info 2>&1` && echo "$test OK" || echo "Failed"

Hello, Application Version: v1 ; Color: blue OK

+ echo


master $


3. Inspect the deployment and identify the number of PODs deployed by it

--> master $ kubectl get pods

NAME                        READY   STATUS    RESTARTS   AGE

frontend-6bb4f9cdc8-hc8ws   1/1     Running   0          107s

frontend-6bb4f9cdc8-hjnmm   1/1     Running   0          107s

frontend-6bb4f9cdc8-nw9nb   1/1     Running   0          107s

frontend-6bb4f9cdc8-zb5v2   1/1     Running   0          107s


4. What container image is used to deploy the applications?

master $ kubectl describe deployment frontend | grep -i image

    Image:        kodekloud/webapp-color:v1


5. Inspect the deployment and identify the current strategy

--master $ kubectl describe deployment frontend | grep -i strategy

StrategyType:           RollingUpdate

RollingUpdateStrategy:  25% max unavailable, 25% max surge


6. If you were to upgrade the application now what would happen?

-Since it is a rollback upgrade, few would go down and few would be scaled up.



7. Let us try that. Upgrade the application by setting the image on the deployment to 'kodekloud/webapp-color:v2' Do not delete and re-create the deployment. Only set the new image name for the existing deployment. info_outline 

Hint Deployment Name: frontend Deployment Image: kodekloud/webapp-color:v2


master $ kubectl set image deployment/frontend simple-webapp=kodeloud/webapp-color:v2

deployment.apps/frontend image updated

8. Run the script curl-test.sh again. Notice the requests now hit both the old and newer versions. However none of them fail. Execute the script at /root/curl-test.sh.

master $ sh -x curl-test.sh

+ kubectl exec --namespace=kube-public curl -- sh -c test=`wget -qO- -T 2  http://webapp-service.default.svc.cluster.local:8080/info 2>&1` && echo "$test OK" || echo "Failed"

Hello, Application Version: v2 ; Color: green OK

+ echo

8. Up to how many PODs can be down for upgrade at a time Consider the current strategy settings and number of PODs - 4 info_outline Hint Look at the Max Unavailable value under RollingUpdateStrategy in deployment details


master $ kubectl describe deployment frontend | grep -i strategy

StrategyType:           RollingUpdate

RollingUpdateStrategy:  25% max unavailable, 25% max surge


Right now there are 4 pods and 25 % of 4 is 1, so 1 is the answer.


9. Upgrade the application by setting the image on the deployment to 'kodekloud/webapp-color:v3' Do not delete and re-create the deployment. Only set the new image name for the existing deployment.

master $ kubectl set image deployment/frontend simple-webapp=kodekloud/webapp-color:v3

deployment.apps/frontend image updated


Run the script curl-test.sh again. Notice the failures. Wait for the new application to be ready. Notice that the requests now do not hit both the versions Execute the script at /root/curl-test.sh.

No comments:

Post a Comment