Kubernetes Engine Deployments
1. Create deployment manifests and deploy to the cluster
Connect to the lab GKE cluster
환경 변수 설정
export my_zone=us-central1-aexport my_cluster=standard-cluster-1
설정 반영
source <(kubectl completion bash)
클러스터 구성
gcloud container clusters get-credentials $my_cluster --zone $my_zone
OUTPUT
Fetching cluster endpoint and auth data.kubeconfig entry generated for standard-cluster-1.
Repository 복제
git clone https://github.com/GoogleCloudPlatform/training-data-analyst
심볼릭 링크
ln -s ~/training-data-analyst/courses/ak8s/v1.1 ~/ak8s
ak8s 디렉토리로 이동
cd ~/ak8s/Deployments/
Create a deployment manifest
nginx-deployment.yaml
apiVersion: apps/v1kind: Deploymentmetadata:name: nginx-deploymentlabels:app: nginxspec:replicas: 3selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginx:1.7.9ports:- containerPort: 80
kubectl apply
kubectl apply -f ./nginx-deployment.yaml
kubectl get deployments
Output
NAME READY UP-TO-DATE AVAILABLE AGEnginx-deployment 3/3 3 3 11s
2. Manually scale up and down the number of Pods in deployments
끄고 싶을 때가 있음..
Scale Pods up and down in the console
☰ > Kubernetes Engine > Workloads.
Scale Pods up and down in the shell
replicas 갯수 커맨드로 늘이기
현재 deployments보기
kubectl get deployments
Output
NAME READY UP-TO-DATE AVAILABLE AGEnginx-deployment 1/1 1 1 4m24s
replicas 3개로 늘이기
kubectl scale --replicas=3 deployment nginx-deployment
결과
$kubectl get deploymentsNAME READY UP-TO-DATE AVAILABLE AGEnginx-deployment 3/3 3 3 4m53s
3. Trigger a deployment rollout and a deployment rollback
Trigger a deployment rollout
$kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.9.1 --recordFlag --record has been deprecated, --record will be removed in the futuredeployment.apps/nginx-deployment image updated
To view the rollout status, execute the following command:
kubectl rollout status deployment.v1.apps/nginx-deployment
확인
kubectl get deployments
rollout history 보기
kubectl rollout history deployment nginx-deploymentkubectl rollout history deployment nginx-deployment
Output
deployment.apps/nginx-deploymentREVISION CHANGE-CAUSE1 <none>2 kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.9.1 --record=true
최신 배포판 상세 보기
$kubectl rollout history deployment/nginx-deployment --revision=3
4. Define the service type in the manifest
메니패스트에서 버시스 유형 정의
yaml
apiVersion: v1kind: Servicemetadata:name: nginxspec:type: LoadBalancerselector:app: nginxports:- protocol: TCPport: 60000targetPort: 80
로드 반렌스 확인
$kubectl get service nginxNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEnginx LoadBalancer 10.12.7.221 <pending> 60000:30953/TCP 28s
5. 배포
yaml
apiVersion: apps/v1kind: Deploymentmetadata:name: nginx-canarylabels:app: nginxspec:replicas: 1selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxtrack: canaryVersion: 1.9.1spec:containers:- name: nginximage: nginx:1.9.1ports:- containerPort: 80
kubectl
kubectl apply -f nginx-canary.yaml
kubectl get deploymentsNAME READY UP-TO-DATE AVAILABLE AGEnginx-canary 1/1 1 1 38snginx-deployment 3/3 3 3 14m
replicas 0으로 줄이기
kubectl scale --replicas=0 deployment nginx-deploymentNAME READY UP-TO-DATE AVAILABLE AGEnginx-canary 1/1 1 1 84snginx-deployment 0/0 0 0 15m