4월 23일 완료 /
목표
- kubectl 도구 사용 연습
- 배포 yaml 파일 만들기
- 배포 시작, 업데이트 및 확장
- 배포 및 배포 스타일 업데이트 연습
진행
영역 설정
gcloud config set compute/zone
샘플 코드
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 deployments/auth.yaml
i
...
containers:
- name: auth
image: kelseyhightower/auth:1.0.0
...
:wq
cat deployments/auth.yaml
kubectl create -f deployments/auth.yaml
kubectl get deployments
kubectl get replicasets
kubectl get pods
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
kubectl get services frontend
curl -ks https://<EXTERNAL-IP>
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`
배포 확장
kubectl explain deployment.spec.replicas
kubectl scale deployment hello --replicas=5
kubectl get pods | grep hello- | wc -l
kubectl scale deployment hello --replicas=3
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
kubectl rollout pause deployment/hello
kubectl rollout status deployment/hello
kubectl get pods -o jsonpath --template='{range .items[*]}{.metadata.name}{"\t"}{"\t"}{.spec.containers[0].image}{"\n"}{end}'
kubectl rollout resume deployment/hello
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}'
> Canary 배포
cat deployments/hello-canary.yaml
kubectl create -f deployments/hello-canary.yaml
kubectl get deployments
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version
> Blue/Green 배포
서비스
kubectl apply -f services/hello-blue.yaml
Blue/Green 배포를 사용하여 업데이트하기
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
Blue/Green 롤백
kubectl apply -f services/hello-blue.yaml
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version
'개발' 카테고리의 다른 글
UIPath 오류 해결 방법 (0) | 2023.07.02 |
---|---|
[GCP] Kubernetes Engine에서 Jenkins로 지속적 배포 (0) | 2023.04.23 |
[GCP] Kubernetes를 통한 클라우드 조정 (0) | 2023.04.22 |
[GCP] Kubernetes Engine: Qwik Start (1) | 2023.04.22 |
[GCP] Docker 소개 (0) | 2023.04.22 |