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
deployments/auth.yaml
구성 파일을 업데이트vi deployments/auth.yaml
i
로 image: kelseyhightower/auth:1.0.0
수정cat deployments/auth.yaml
kubectl create
명령어를 실행하여 인증 배포를 만들면 배포 매니페스트의 데이터에 따라 하나의 포드가 생성replicas
필드에 지정된 숫자를 변경하여 포드의 수를 조정할 수 있다.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>
EXTERNAAL-IP 생성되고 나서 응답 확인
curl의 한 줄 명령어
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`
spec.replicas
필드를 업데이트한다.
kubectl explain deployment.spec.replicas
kubectl scale deployment hello --replicas=5
배포가 업데이트된 후, Kubernetes는 연결된 ReplicaSet를 자동으로 업데이트하고 새로운 pod를 시작하여 pod의 총 개수를 5로 만든다.
hello
포드가 5개 실행되고 있는지 확인kubectl get pods | grep hello- | wc -l
kubectl scale deployment hello --replicas=3
레플리카 3개로 축소
kubectl get pods | grep hello- | wc -l
배포는 순차적 업데이트 메커니즘을 통해 이미지를 새 버전으로 업데이트하도록 지원한다. 배포가 새 버전으로 업데이트되면 새 ReplicaSet가 만들어지고, 이전 ReplicaSet의 복제본이 감소하면서 새 ReplicaSet의 복제본 수가 천천히 증가한다.
kubectl edit deployment hello
image
를 다음과 같이 변경...
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
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
hello
및 hello-canary
의 두 가지 배포가 생긴다. 다음 kubectl
명령어로 확인한다.kubectl get deployments
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version
서비스 업데이트
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
kubectl apply -f services/hello-blue.yaml
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version