티스토리 뷰

반응형

Lab 1에 이은 Lab 2입니다. replica를 만들고 모니터링하는 방법을 실습하는 내용입니다.

 

---- Scale apps with replicas

1. replica set 업데이트

먼저 Lab 1에서 배포한 deployment를 조회합니다.

[root@db2 Lab 2]# kubectl get deployment 
NAME          READY   UP-TO-DATE   AVAILABLE   AGE 
hello-world   1/1     1            1           30m

 

edit명령으로 deployment 설정파일을 수정합니다.

kubectl edit deployment

spec: 
  progressDeadlineSeconds: 600 
  replicas: 1                            // 1을 10으로 변경하고 저장 //
  revisionHistoryLimit: 10 
  selector: 
    matchLabels: 
      run: hello-world 
  strategy: 
    rollingUpdate: 
      maxSurge: 25% 
      maxUnavailable: 25% 
    type: RollingUpdate 
  template: 
    metadata: 
      creationTimestamp: null 
      labels: 
        run: hello-world 


[root@db2 Lab 2]# kubectl edit deployment hello-world 
deployment.apps/hello-world edited 


2. 변경한 사항 적용하기


kubectl rollout status deployment/hello-world

[root@db2 Lab 2]# kubectl rollout status deployment/hello-world
deployment "hello-world" successfully rolled out


3. pod 확인하기

kubectl get pods

[root@db2 Lab 2]# kubectl get pods 
NAME                           READY   STATUS    RESTARTS   AGE 
hello-world-684dfdd9c5-b48hq   1/1     Running   0          2m32s 
hello-world-684dfdd9c5-gjf4p   1/1     Running   0          35m 
hello-world-684dfdd9c5-jqssq   1/1     Running   0          2m32s 
hello-world-684dfdd9c5-nwx8x   1/1     Running   0          2m32s 
hello-world-684dfdd9c5-p9ccg   1/1     Running   0          2m32s 
hello-world-684dfdd9c5-q6grb   1/1     Running   0          2m32s 
hello-world-684dfdd9c5-sw7qt   1/1     Running   0          2m32s 
hello-world-684dfdd9c5-tbswg   1/1     Running   0          2m32s 
hello-world-684dfdd9c5-vq9jn   1/1     Running   0          2m32s 
hello-world-684dfdd9c5-w8xwp   1/1     Running   0          2m32s 



----------- Update and roll back apps

1. 새 컨테이너 빌드

ibmcloud cr build --tag us.icr.io/<my_namespace>/hello-world:2 .

[root@db2 Lab 2]# ibmcloud cr build --tag us.icr.io/skjeong4/hello-world:2 . 
Sending build context to Docker daemon  14.85kB 
Step 1/6 : FROM node:9.4.0-alpine 
 ---> b5f94997f35f 
Step 2/6 : COPY app.js . 
 ---> Using cache 
 ---> 7709ec5f4400 
Step 3/6 : COPY package.json . 
 ---> Using cache 
 ---> e7a815f63218 
Step 4/6 : RUN npm install &&    apk update &&    apk upgrade 
 ---> Using cache 
 ---> 8cf455abe99a 
Step 5/6 : EXPOSE  8080 
 ---> Using cache 
 ---> 6d43110f568e 
Step 6/6 : CMD node app.js 
 ---> Using cache 
 ---> 34a819beea5a 
Successfully built 34a819beea5a 
Successfully tagged us.icr.io/skjeong4/hello-world:2 
The push refers to repository [us.icr.io/skjeong4/hello-world] 
99f142d4db2d: Layer already exists 
9043b37014f9: Layer already exists 
7eab2e812ea7: Layer already exists 
0804854a4553: Layer already exists 
6bd4a62f5178: Layer already exists 
9dfa40a0da3b: Layer already exists 
2: digest: sha256:a22a1e31c72344a671dad2c2343bb9238929b3c140306b986a187fc16e268c93 size: 1576 

OK 
[root@db2 Lab 2]# ibmcloud cr images 
Listing images... 

Repository                       Tag      Digest         Namespace   Created      Size    Security status 
us.icr.io/skjeong4/hello-world   2        a22a1e31c723   skjeong4    1 hour ago   27 MB   No Issues 
us.icr.io/skjeong4/hello-world   latest   a22a1e31c723   skjeong4    1 hour ago   27 MB   No Issues 

OK 


2. 새 컨테이너를 기존 deployment에 업데이트

kubectl set image deployment/hello-world hello-world=us.icr.io//hello-world:2

[root@db2 Lab 2]# kubectl set image deployment/hello-world hello-world=us.icr.io/skjeong4/hello-world:2 
deployment.apps/hello-world image updated 


3. 업데이트 내역 확인

kubectl rollout status deployment/hello-world
kubectl get replicasets

[root@db2 Lab 2]# kubectl rollout status deployment/hello-world 
deployment "hello-world" successfully rolled out 
[root@db2 Lab 2]# kubectl get replicasets 
NAME                     DESIRED   CURRENT   READY   AGE 
hello-world-5c6cb477cf   10        10        10      5m12s 
hello-world-684dfdd9c5   0         0         0       109m 


4. 어플리케이션 실행 테스트 (curl 또는 웹)

curl <public-IP>:<nodeport>

[root@db2 Lab 2]# curl xxx.xxx.xx.xxx:32412 
Hello world from hello-world-5c6cb477cf-7r9dv! Your app is up and running in a cluster! 


5. 업데이트 롤백하기

kubectl rollout undo deployment/<name-of-deployment>

[root@db2 Lab 2]# kubectl rollout undo deployment/hello-world 
deployment "hello-world" successfully rolled out


---- Check the health of apps

1. Lab 2 디렉토리의 healthcheck.yml 파일 수정

image: ".icr.io//hello-world:2"
=> image: ".icr.io/skjeong4/hello-world:2"

2. IBM 클라우드의 클러스터 대시보드에서 디플로이먼트/파드/레플리카셋등 확인

반응형
댓글