IT/GCP

[Cloud Hero 2-4] Kubernetes Engine으로 배포 관리

Jflip 2022. 11. 22. 18:00
728x90

안녕하세요! Devfest Cloud Hero 세션에 오신 여러분 환영합니다.

이번 퀘스트에서는 이기종 배포 방식(Heterogeneous Deployments)

활용되는 곳에서 컨테이너의 확장 및 관리 실습을 진행하게 됩니다.

 

Compute / zone 설정하기

gcloud config set compute/zone us-east5-b

샘플 코드 다운받고, 폴더 이동하기

gsutil -m cp -r gs://spls/gsp053/orchestrate-with-kubernetes .
cd orchestrate-with-kubernetes/kubernetes

클러스터 생성하기

gcloud container clusters create bootcamp \
  --machine-type e2-small \
  --num-nodes 3 \
  --scopes “https://www.googleapis.com/auth/projecthosting,storage-rw"

디플로이먼트 확인하기

kubectl explain deployment

디플로이먼트 필드 확인하기

kubectl explain deployment --recursive

디플로이먼트 오브젝트 확인하기

kubectl explain deployment.metadata.name

디플로이먼트 구성파일 업데이트하기

vi deployment/auth.yaml

에디터에서 i 누르고, 하기와 같이 버전 변경하기 1.0.0으로

...
containers:
- name: auth
  image: "kelseyhightower/auth:1.0.0"
...

auth.yaml 파일 저장하기

:wq

디플로이먼트 확인하기

cat deployment/auth.yaml

auth 디플로이먼트 배포하기

kubectl create –f deployment/auth.yaml

디플로이먼트 배포 확인하기

kubectl get deployment

리플리카셋 확인하기

kubectl get replicasets

auth 서비스 생성하기

kubectl create –f services/auth.yaml

디플로이먼트 생성하고, 외부 노출하기

kubectl create -f deployments/hello.yaml
kubectl create -f services/hello.yaml

디플로이먼트 생성후 외부 노출하기

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

External IP 확인 후, curl 명령으로 확인하기

kubectl get services frontend
curl –ks https://<EXTERNAL-IP>

curl 명령어 수행하기

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

explain 명령어 수행하기

kubectl explain deployment.spec.replicas

scale 명령 수행하기

kubectl scale deployment hello –replicas=5

파드 동작 확인하기

kubectl get pods | grep hello- | wc -l

파드 원상 복구하기

kubectl scale deployment hello --replicas=3

Pod 개수 확인하기

kubectl get pods | grep hello- | wc -l

디플로이먼트 업데이트하기

kubectl edit deployment hello

이미지 변경하기

...
containers:
  image: kelseyhightower/hello:2.0.0
...

 

레플리카셋 확인하기

kubectl get replicaset

롤아웃 히스토리 확인하기

kubectl rollout history deployment/hello

rollout 재개하기

kubectl rollout resume deployment/hello

status 체크하기

kubectl rollout status deployment/hello

업데이트 롤백하기

kubectl rollout undo deployment/hello

롤백 확인하기

kubectl rollout history deployment/hello

롤백된 파드 확인하기

kubectl get pods -o jsonpath --template='{range .items[*]}{.metadata.name}{"\t"}{"\t"}{.spec.containers[0].image}{"\n"}{end}'

카나리 배포 생성하기

cat deployments/hello-canary.yaml

카나리 배포 생성하기

kubectl create -f deployments/hello-canary.yaml

디플로이먼트 확인하기

kubectl get deployments

hello 버전 확인하기

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

서비스 업데이트하기

kubectl apply -f services/hello-blue.yaml

디플로이먼트 생성하기

kubectl create -f deployments/hello-green.yaml

구성 확인하기

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

신규 버전 서비스 업데이트 하기

kubectl apply -f services/hello-green.yaml

서비스 업데이트 확인하기

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

롤백하기

kubectl apply -f services/hello-blue.yaml

버전 확인하기

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

감사합니다.

728x90
반응형