brunch

174. CLI로 GKE클러스터 생성,배포(4/4)

by Master Seo


<1> GKE 클러스터 생성

<2> 디플로이 먼트 생성

<3> 확장

<4> 롤링 업데이트

<5> 카나리 배포

<6> 블루 그린 배포





<1> GKE 클러스터 생성



1

gcloud auth list


gcloud config list project


gcloud config set compute/zone us-central1-a




2

gcloud container clusters create test1 --num-nodes 3

(10분 소요)




<2> 디플로이 먼트 생성


1

새 터미널에서 모니터링


watch -d kubectl get deploy,replicasets,svc,pods


2

kubectl create -f deployments/auth.yaml


NAME READY UP-TO-DATE AVAILABLE AGE

deployment.apps/auth 1/1 1 1 85s


NAME DESIRED CURRENT READY AGE

replicaset.apps/auth-85957c88d8 1 1 1 86s


NAME READY STATUS RESTARTS AGE

pod/auth-85957c88d8-j5q8k 1/1 Running 0 86s



3

서비스 생성

kubectl create -f services/auth.yaml



NAME READY UP-TO-DATE AVAILABLE AGE

deployment.apps/auth 1/1 1 1 3m59s


NAME DESIRED CURRENT READY AGE

replicaset.apps/auth-85957c88d8 1 1 1 3m59s


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

service/auth ClusterIP 10.116.15.239 <none> 80/TCP 48s

service/kubernetes ClusterIP 10.116.0.1 <none> 443/TCP 9m4s


NAME READY STATUS RESTARTS AGE

pod/auth-85957c88d8-j5q8k 1/1 Running 0 4m




4

hello 디플로이먼트와 서비스 생성?


kubectl create -f deployments/hello.yaml

kubectl create -f services/hello.yaml


watch -d kubectl get deploy,replicasets,svc,pods


NAME READY UP-TO-DATE AVAILABLE AGE

deployment.apps/auth 1/1 1 1 5m23s

deployment.apps/hello 3/3 3 3 41s


NAME DESIRED CURRENT READY AGE

replicaset.apps/auth-85957c88d8 1 1 1 5m23s

replicaset.apps/hello-6c595f956c 3 3 3 41s


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

service/auth ClusterIP 10.116.15.239 <none> 80/TCP 2m12s

service/hello ClusterIP 10.116.6.27 <none> 80/TCP 41s

service/kubernetes ClusterIP 10.116.0.1 <none> 443/TCP 10m


NAME READY STATUS RESTARTS AGE

pod/auth-85957c88d8-j5q8k 1/1 Running 0 5m24s

pod/hello-6c595f956c-2x4tf 1/1 Running 0 42s

pod/hello-6c595f956c-8lkb9 1/1 Running 0 42s

pod/hello-6c595f956c-qtt78 1/1 Running 0 42s



5

fornt ?


kubectl create secret generic tls-certs --from-file tls/

kubectl create configmap nginx-frontend-conf --from-file=nginx/frontend.conf

kubectl create -f deployments/frontend.yaml

kubectl create -f services/frontend.yaml



NAME READY UP-TO-DATE AVAILABLE AGE

deployment.apps/auth 1/1 1 1 9m2s

deployment.apps/frontend 1/1 1 1 49s

deployment.apps/hello 3/3 3 3 4m20s


NAME DESIRED CURRENT READY AGE

replicaset.apps/auth-85957c88d8 1 1 1 9m2s

replicaset.apps/frontend-6869899d96 1 1 1 49s

replicaset.apps/hello-6c595f956c 3 3 3 4m20s


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

service/auth ClusterIP 10.116.15.239 <none> 80/TCP 5m50s

service/frontend LoadBalancer 10.116.10.50 34.133.202.41 443:32695/TCP 48s

service/hello ClusterIP 10.116.6.27 <none> 80/TCP 4m19s

service/kubernetes ClusterIP 10.116.0.1 <none> 443/TCP 14m


NAME READY STATUS RESTARTS AGE

pod/auth-85957c88d8-j5q8k 1/1 Running 0 9m2s

pod/frontend-6869899d96-frvdk 1/1 Running 0 49s

pod/hello-6c595f956c-2x4tf 1/1 Running 0 4m20s

pod/hello-6c595f956c-8lkb9 1/1 Running 0 4m20s

pod/hello-6c595f956c-qtt78 1/1 Running 0 4m20s






<3> 확장


1

kubectl scale deployment hello --replicas=5


NAME READY UP-TO-DATE AVAILABLE AGE

deployment.apps/auth 1/1 1 1 11m

deployment.apps/frontend 1/1 1 1 3m46s

deployment.apps/hello 5/5 5 5 7m17s


NAME DESIRED CURRENT READY AGE

replicaset.apps/auth-85957c88d8 1 1 1 11m

replicaset.apps/frontend-6869899d96 1 1 1 3m46s

replicaset.apps/hello-6c595f956c 5 5 5 7m17s


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

service/auth ClusterIP 10.116.15.239 <none> 80/TCP 8m47s

service/frontend LoadBalancer 10.116.10.50 34.133.202.41 443:32695/TCP 3m45s

service/hello ClusterIP 10.116.6.27 <none> 80/TCP 7m16s

service/kubernetes ClusterIP 10.116.0.1 <none> 443/TCP 17m


NAME READY STATUS RESTARTS AGE

pod/auth-85957c88d8-j5q8k 1/1 Running 0 11m

pod/frontend-6869899d96-frvdk 1/1 Running 0 3m46s

pod/hello-6c595f956c-2x4tf 1/1 Running 0 7m17s

pod/hello-6c595f956c-8lkb9 1/1 Running 0 7m17s

pod/hello-6c595f956c-kc6rv 1/1 Running 0 25s

pod/hello-6c595f956c-qtt78 1/1 Running 0 7m17s

pod/hello-6c595f956c-tdrvv 1/1 Running 0 25s



2

kubectl get pods | grep hello- | wc -l

5개



3

kubectl scale deployment hello --replicas=3



4

kubectl get pods | grep hello- | wc -l

3





<4> 롤링 업데이트



1

kubectl edit deployment hello

버전을 1.0에서 2.0으로 변경


2

$ kubectl get replicaset

NAME DESIRED CURRENT READY AGE

auth-85957c88d8 1 1 1 16m

frontend-6869899d96 1 1 1 7m56s

hello-6c595f956c 0 0 0 11m

hello-6df48465f6 3 3 3 47s


3

롤링 배포 히스토리


kubectl rollout history deployment/hello


deployment.apps/hello

REVISION CHANGE-CAUSE

1 <none>

2 <none>



4

중지

kubectl rollout pause deployment/hello


5

계속

kubectl rollout resume deployment/hello



6

상태 확인

kubectl rollout status deployment/hello

deployment "hello" successfully rolled out



7

롤백

kubectl rollout undo deployment/hello


8

상태 확인

kubectl rollout status deployment/hello




<5> 카나리 배포


1개만 배포해서 상태 확인 배포


kubectl create -f deployments/hello-canary.yaml



2

NAME READY UP-TO-DATE AVAILABLE AGE

deployment.apps/auth 1/1 1 1 24m

deployment.apps/frontend 1/1 1 1 15m

deployment.apps/hello 3/3 3 3 19m

deployment.apps/hello-canary 1/1 1 1 50s


NAME DESIRED CURRENT READY AGE

replicaset.apps/auth-85957c88d8 1 1 1 24m

replicaset.apps/frontend-6869899d96 1 1 1 15m

replicaset.apps/hello-6c595f956c 3 3 3 19m

replicaset.apps/hello-6df48465f6 0 0 0 8m43s

replicaset.apps/hello-canary-587f4f85f4 1 1 1 50s


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

service/auth ClusterIP 10.116.15.239 <none> 80/TCP 20m

service/frontend LoadBalancer 10.116.10.50 34.133.202.41 443:32695/TCP 15m

service/hello ClusterIP 10.116.6.27 <none> 80/TCP 19m

service/kubernetes ClusterIP 10.116.0.1 <none> 443/TCP 29m


NAME READY STATUS RESTARTS AGE

pod/auth-85957c88d8-j5q8k 1/1 Running 0 24m

pod/frontend-6869899d96-frvdk 1/1 Running 0 15m

pod/hello-6c595f956c-8l9pr 1/1 Running 0 3m44s

pod/hello-6c595f956c-b4sk6 1/1 Running 0 4m4s

pod/hello-6c595f956c-lpbhj 1/1 Running 0 3m54s

pod/hello-canary-587f4f85f4-mxrlc 1/1 Running 0 50s




<6> 블루 그린 배포


1

kubectl apply -f services/hello-blue.yaml




2

kubectl create -f deployments/hello-green.yaml



3

확인

curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version

2.0



4

kubectl apply -f services/hello-green.yaml


5

확인

curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version



6

NAME READY UP-TO-DATE AVAILABLE AGE

deployment.apps/auth 1/1 1 1 26m

deployment.apps/frontend 1/1 1 1 18m

deployment.apps/hello 3/3 3 3 21m

deployment.apps/hello-canary 1/1 1 1 3m15s

deployment.apps/hello-green 3/3 3 3 24s


NAME DESIRED CURRENT READY AGE

replicaset.apps/auth-85957c88d8 1 1 1 26m

replicaset.apps/frontend-6869899d96 1 1 1 18m

replicaset.apps/hello-6c595f956c 3 3 3 21m

replicaset.apps/hello-6df48465f6 0 0 0 11m

replicaset.apps/hello-canary-587f4f85f4 1 1 1 3m16s

replicaset.apps/hello-green-75b897597c 3 3 3 25s


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

service/auth ClusterIP 10.116.15.239 <none> 80/TCP 23m

service/frontend LoadBalancer 10.116.10.50 34.133.202.41 443:32695/TCP 18m

service/hello ClusterIP 10.116.6.27 <none> 80/TCP 21m

service/kubernetes ClusterIP 10.116.0.1 <none> 443/TCP 31m


NAME READY STATUS RESTARTS AGE

pod/auth-85957c88d8-j5q8k 1/1 Running 0 26m

pod/frontend-6869899d96-frvdk 1/1 Running 0 18m

pod/hello-6c595f956c-8l9pr 1/1 Running 0 6m10s

pod/hello-6c595f956c-b4sk6 1/1 Running 0 6m30s

pod/hello-6c595f956c-lpbhj 1/1 Running 0 6m20s

pod/hello-canary-587f4f85f4-mxrlc 1/1 Running 0 3m16s

pod/hello-green-75b897597c-hm259 1/1 Running 0 25s



7

롤백


kubectl apply -f services/hello-blue.yaml


curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version

{"version":"1.0.0"}





다음 자료


https://brunch.co.kr/@topasvga/2395





https://brunch.co.kr/@topasvga/1840



https://brunch.co.kr/@topasvga/2388



k8s.png



감사합니다.


keyword
매거진의 이전글173. VM인스턴스 생성과 GCP 모니터링(3/4)