728x90

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 클라우드의 클러스터 대시보드에서 디플로이먼트/파드/레플리카셋등 확인

728x90

'cloud' 카테고리의 다른 글

Kubernetes Essentials with IBM Cloud - Lab 1  (0) 2020.03.18
728x90

요즘 IBM Badge 모으는 재미에 빠졌네요. 오늘은 쿠버네티스 기본에 대해서 공부했습니다.

과정명은 Container & Kubernetes Essentials with IBM Cloud입니다.

Lab 1의 과정을 정리해봤습니다. 제가 연습한 실습 환경은 CentOS 7입니다.

아래 사이트를 순서대로 따라한 것입니다. 조금 시행착오는 있을 수 있는데 어렵지 않습니다.

 

참고 사이트 :

https://cloud.ibm.com/docs/cli?topic=cloud-cli-getting-started

https://github.com/IBM/container-service-getting-started-wt

 

---- 초기 구성


1. IBM Cloud CLI 설치

Linux에서 IBM Cloud에 접근할 수 있는 커맨드라인 인터페이스를 설치합니다.

curl -sL https://ibm.biz/idt-installer | bash

 

2. IBM Cloud 로그인

ibmcloud login -a cloud.ibm.com -r us-south -g default

ibmcloud ks cluster config --cluster bpkadubd0gijteu5rpt0

[root@db2 ~]# ibmcloud ks cluster ls
OK
Name        ID                     State    Created      Workers   Location   Version       Resource Group Name   Provider
mycluster   bpkadubd0gijteu5rpt0   normal   5 days ago   1         Dallas     1.16.7_1524   default               classic



---- IBM Cloud에 이미지 푸시

1. 네임스페이스 추가
<참고> 도커 데몬이 실행중인지 확인, 실행중이 아니라면 도커 데몬 실행
systemctl status docker
systemctl start docker

ibmcloud cr login
ibmcloud cr namespace-add <my_namespace>

[root@db2 Lab 1]# ibmcloud cr namespace-add skjeong4 
Adding namespace 'skjeong4'... 
Successfully added namespace 'skjeong4' 
OK 

 

2. Lab 1 폴더로 이동하여 도커 이미지 빌드

 

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

[root@db2 Lab 1]# ibmcloud cr build --tag us.icr.io/skjeong4/hello-world . 
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:latest 
The push refers to repository [us.icr.io/skjeong4/hello-world] 
99f142d4db2d: Pushed 
9043b37014f9: Pushed 
7eab2e812ea7: Pushed 
0804854a4553: Pushed 
6bd4a62f5178: Pushed 
9dfa40a0da3b: Pushed 
latest: digest: sha256:a22a1e31c72344a671dad2c2343bb9238929b3c140306b986a187fc16e268c93 size: 1576 
OK


3. 도커 이미지 빌드 확인

[root@db2 Lab 1]# ibmcloud cr images 
Listing images... 
Repository                       Tag      Digest         Namespace   Created          Size    Security status 
us.icr.io/skjeong4/hello-world   latest   a22a1e31c723   skjeong4    30 minutes ago   27 MB   No Issues 
OK

 


---- 배포

1. 클러스터 설정 파일 가져오기 및 환경변수 적용

ibmcloud ks cluster-config <yourclustername>

[root@db2 Lab 1]# ibmcloud ks cluster-config mycluster 
WARNING: This legacy command is deprecated and will soon be unsupported. Use the 'ibmcloud ks cluster config' command instead. 
For more information, see 'https://ibm.biz/iks-cli-v1' 
WARNING: The behavior of this command in your current CLI version is deprecated, and becomes unsupported when CLI version 1.0 is released in March 2020. To use the new behavior now, set the 'IKS_BETA_VERSION' environment variable. In bash, run 'export IKS_BETA_VERSION=1'. 
Note: Changing the beta version can include other breaking changes. For more information, see 'https://ibm.biz/iks-cli-v1' 
OK 
The configuration for mycluster was downloaded successfully. 
Export environment variables to start using Kubernetes. 
export KUBECONFIG=/root/.bluemix/plugins/container-service/clusters/mycluster/kube-config-hou02-mycluster.yml 


2. 클러스터에 이미지 배포 - pod 생성

kubectl run hello-world --image=us.icr.io/<namespace>/hello-world

[root@db2 Lab 1]# kubectl delete deployment hello-world 
deployment.apps "hello-world" deleted 
[root@db2 Lab 1]# kubectl run hello-world --image=us.icr.io/skjeong4/hello-world 
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead. 
deployment.apps/hello-world created 



3. pod 생성 확인

kubectl get pods

[root@db2 Lab 1]# kubectl get pods
NAME                           READY   STATUS              RESTARTS   AGE
hello-world-684dfdd9c5-gjf4p   0/1     ContainerCreating   0          5s
[root@db2 Lab 1]# kubectl get pods
NAME                           READY   STATUS    RESTARTS   AGE
hello-world-684dfdd9c5-gjf4p   1/1     Running   0          10s


참고 > pod 생성에 오류가 있는 경우 확인 방법

[root@db2 Lab 1]# kubectl get pods 
NAME                           READY   STATUS         RESTARTS   AGE 
hello-world-5dd7d6d7d4-78g4h   0/1     ErrImagePull   0          3s 
[root@db2 Lab 1]# kubectl delete deployment hello-world 
deployment.apps "hello-world" deleted 
[root@db2 Lab 1]# kubectl describe pod hello-world-5dd7d6d7d4-78g4h 
Name:               hello-world-5dd7d6d7d4-78g4h 
Namespace:          default 
Priority:           0 
PriorityClassName:   
Node:               10.77.223.248/10.77.223.248 
Start Time:         Thu, 12 Mar 2020 10:47:52 +0900 
Labels:             pod-template-hash=5dd7d6d7d4 
                    run=hello-world 
Annotations:        kubernetes.io/psp: ibm-privileged-psp 
Status:             Pending 
IP:                 xxx.xx.xx.xx 
Controlled By:      ReplicaSet/hello-world-5dd7d6d7d4 
Containers: 
  hello-world: 
    Container ID: 
    Image:          us.icr.io/skjeong4/hello-world:1 
    Image ID: 
    Port:            
    Host Port:       
    State:          Waiting 
      Reason:       ImagePullBackOff 
    Ready:          False 
    Restart Count:  0 
    Environment:     
    Mounts: 
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-zj8ts (ro) 
Conditions: 
  Type              Status 
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes: 
  default-token-zj8ts: 
    Type:        Secret (a volume populated by a Secret) 
    SecretName:  default-token-zj8ts 
    Optional:    false 
QoS Class:       BestEffort 
Node-Selectors:   
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 600s 
                 node.kubernetes.io/unreachable:NoExecute for 600s 
Events: 
  Type     Reason     Age               From                    Message 
  ----     ------     ----              ----                    ------- 
  Normal   Scheduled  13s               default-scheduler       Successfully assigned default/hello-world-5dd7d6d7d4-78g4h to 10.77.223.248 
  Warning  Failed     12s               kubelet, 10.77.223.248  Failed to pull image "us.icr.io/skjeong4/hello-world:1": rpc error: code = NotFound desc = failed to pull and unpack image "us.icr.io/skjeong4/hello-world:1": failed to resolve reference "us.icr.io/skjeong4/hello-world:1": us.icr.io/skjeong4/hello-world:1: not found 
  Warning  Failed     12s               kubelet, 10.77.223.248  Error: ErrImagePull 
  Normal   BackOff    11s               kubelet, 10.77.223.248  Back-off pulling image "us.icr.io/skjeong4/hello-world:1" 
  Warning  Failed     11s               kubelet, 10.77.223.248  Error: ImagePullBackOff 
  Normal   Pulling    0s (x2 over 12s)  kubelet, 10.77.223.248  Pulling image "us.icr.io/skjeong4/hello-world:1" 


3. 해당 pod에 서비스 포트 할당

kubectl expose deployment/hello-world --type="NodePort" --port=8080

[root@db2 Lab 1]# kubectl expose deployment/hello-world --type="NodePort" --port=8080 
service/hello-world exposed 


4. 클러스터에 배포된 포트 확인

kubectl describe service <name-of-deployment>

[root@db2 Lab 1]# kubectl describe service hello-world 
Name:                     hello-world 
Namespace:                default 
Labels:                   run=hello-world 
Annotations:               
Selector:                 run=hello-world 
Type:                     NodePort 
IP:                       xxx.xx.xxx.xxx 
Port:                       8080/TCP 
TargetPort:               8080/TCP 
NodePort:                   32412/TCP 
Endpoints:                xxx.xx.xx.xx:8080 
Session Affinity:         None 
External Traffic Policy:  Cluster 
Events:                    


5. 클러스터의 Public IP 확인

ibmcloud ks workers <name-of-cluster>

[root@db2 script]# ibmcloud ks workers mycluster 
OK 
ID                                                     Public IP        Private IP      Flavor   State    Status   Zone    Version 
kube-bpkadubd0gijteu5rpt0-mycluster-default-00000094   xxx.xxx.xx.xxx   xx.xx.xxx.xxx   free     normal   Ready    hou02   1.16.7_1525

 

6. 클러스터에 배포된 어플리케이션 실행

 

curl <public-IP>:<nodeport>

[root@db2 Lab 3]# curl xxx.xxx.xx.xxx:32412
Hello world from hello-world-684dfdd9c5-fll85! Your app is up and running in a cluster!
728x90

'cloud' 카테고리의 다른 글

Kubernetes Essentials with IBM Cloud - Lab 2  (0) 2020.03.18

+ Recent posts