티스토리 뷰

반응형

요즘 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!
반응형
댓글