CKA (Certified Kubernetes Administrator)/Kode Kloud

4.Application Lifecycle Management - Rolling Updates and Rollbacks

seulseul 2022. 1. 20. 17:27
LABS – CERTIFIED KUBERNETES ADMINISTRATOR WITH PRACTICE TESTS > APPLICATION LIFECYCLE MANAGEMENT

Application Lifecycle Management

01. 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 called Webapp Portal above your terminal.

 

02. What is the current color of the web application?

Access the Webapp Portal.

 

ask : blue

03. 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.

# curl_test.sh
for i in {1..35}; do
   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"';
   echo ""
done

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

ask : 4

controlplane ~ ➜  kubectl get pod
NAME                        READY   STATUS    RESTARTS   AGE
frontend-7776cb7d57-dtghk   1/1     Running   0          4m53s
frontend-7776cb7d57-r8q5z   1/1     Running   0          4m53s
frontend-7776cb7d57-bz75n   1/1     Running   0          4m53s
frontend-7776cb7d57-w2xlh   1/1     Running   0          4m53s

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

 

kubectl describe pod frontend-7776cb7d57-dtghk

ask : kodekloud/webapp-color:v1

 

06. Inspect the deployment and identify the current strategy

 

ask : RollingUpdate

controlplane ~ ✖ kubectl describe deployment frontend | grep -i strategy
StrategyType:           RollingUpdate
RollingUpdateStrategy:  25% max unavailable, 25% max surge

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

1) All PODs are taken down before upgrading any

2) PODs are upgraded few at a time (정답)

 

08. 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.

  • Deployment Name: frontend
  • Deployment Image: kodekloud/webapp-color:v2
# 정답
Run the command 
kubectl edit deployment frontend
and modify the image to kodekloud/webapp-color:v2.
Next, save and exit. The pods should be recreated with the new image.


# 오답...
kubectl get deployments frontend -o yaml > frontend-2.yaml

controlplane ~ ➜  kubectl apply -f frontend-2.yaml --force
Warning: resource deployments/frontend is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
deployment.apps/frontend configured

 

09.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.

Hello, Application Version: v2 ; Color: green OK
 

10. Up to how many PODs can be down for upgrade at a time

Consider the current strategy settings and number of PODs - 4

정답 : 1

 

:) RollingUpdateStrategy 을 보면된다는데...

controlplane ~ ➜  kubectl describe deployments frontend

Name:                   frontend
Namespace:              default
CreationTimestamp:      Thu, 20 Jan 2022 07:29:48 +0000
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 2
Selector:               name=webapp
Replicas:               4 desired | 4 updated | 4 total | 4 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        20
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  name=webapp
  Containers:
   simple-webapp:
    Image:        kodekloud/webapp-color:v2
    Port:         8080/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   frontend-7c7fcfc8cb (4/4 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  34m    deployment-controller  Scaled up replica set frontend-7776cb7d57 to 4
  Normal  ScalingReplicaSet  4m57s  deployment-controller  Scaled up replica set frontend-7c7fcfc8cb to 1
  Normal  ScalingReplicaSet  4m57s  deployment-controller  Scaled down replica set frontend-7776cb7d57 to 3
  Normal  ScalingReplicaSet  4m56s  deployment-controller  Scaled up replica set frontend-7c7fcfc8cb to 2
  Normal  ScalingReplicaSet  4m34s  deployment-controller  Scaled down replica set frontend-7776cb7d57 to 1
  Normal  ScalingReplicaSet  4m34s  deployment-controller  Scaled up replica set frontend-7c7fcfc8cb to 4
  Normal  ScalingReplicaSet  4m10s  deployment-controller  Scaled down replica set frontend-7776cb7d57 to 0

controlplane ~ ➜
 

11. Change the deployment strategy to Recreate

Do not delete and re-create the deployment. Only update the strategy type for the existing deployment.

  • Deployment Name: frontend
  • Deployment Image: kodekloud/webapp-color:v2
  • Strategy: Recreate
# Hint
Run the command 
kubectl edit deployment frontend

and modify the required field.

Make sure to delete the properties of rollingUpdate as well, 
set at strategy.rollingUpdate.

 

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
  namespace: default
spec:
  replicas: 4
  selector:
    matchLabels:
      name: webapp
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        name: webapp
    spec:
      containers:
      - image: kodekloud/webapp-color:v2
        name: simple-webapp
        ports:
        - containerPort: 8080
          protocol: TCP

 

12. 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.

  • Deployment Name: frontend
  • Deployment Image: kodekloud/webapp-color:v3
# step 1
kubectl edit deploymetns frontend

# step2
# yaml 파일이 열리면 image version 을 3 으로 변경해준후 저장하면 됨

 

13. 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.

controlplane ~ ➜  ./curl-test.sh 
Hello, Application Version: v3 ; Color: red OK
 

Bookmark

https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

 

Deployments

A Deployment provides declarative updates for Pods and ReplicaSets. You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new Rep

kubernetes.io