GCP上強大的K8S engine線上研討會 ====== ###### tags: `kubernetes` # Container # Kubernetes & Key Concept + cluster + pod + deployment + service ## pod ![](https://i.imgur.com/H1rNoGD.png =350x) ![](https://i.imgur.com/PZco2De.png =350x) ## deployment ![](https://i.imgur.com/ojtUEW3.png =350x) ![](https://i.imgur.com/r38gyYl.png =350x) ## service ![](https://i.imgur.com/cpGqXZ2.png =350x) ![](https://i.imgur.com/fTF3lRW.png =350x) # GKE ![](https://i.imgur.com/ByFnu8q.png =400x) # Demo ### 1. package docker image ```shell= https://github.com/GoogleCloudPlatform/kubernetes-engine-samples.git cd kubernetes-engine-samples/hello-app docker build -t gcr.io/{GCP_PROJECT_ID}/hello-app:v1 . docker images ``` ### 2. upload the image to a registry ```shell= gcloud auth configure-docker docker push gcr.io/{GCP_PROJECT_ID}/hello-app:v1 ``` ### 3. create a GKE cluster ```shell= gcloud container clusters create hello-cluster --num-nodes=2 --machine-type=f1-micro --region=asia-east1 --preemptible gcloud compute instances list ``` ###### preemptible vs ondemand + preemptible 相較便宜 + 不過 GCP 在因應其他工作的資源調度需求時,可能會終止這些執行個體 ### 4. deploy containerized app to the cluster ```shell= kubectl run hello-web --image=gcr.io/${GCP_PROJECT_ID}/hello-app:v1 --port 8080 kubtectl get pods ``` ### 5. expose app to the internet ```shell= kubtectl expose deployement hello-web --type=LoadBalancer --port 80 --target-port 8080 kubectl get service ``` ### 6. scale up/down your deployment ```shell= kubectl scale deployment hello-web --replicas=3 ``` ### 7. deploy a new version of your app ```shell= # ...after modify docker build -t gcr.io/{GCP_PROJECT_ID}/hello-app:v2 . docker push gcr.io/{GCP_PROJECT_ID}/hello-app:v2 kubectl set image deployment/hello-web=gcr.io/{GCP_PROJECT_ID}/hello-app:v2 kubtctl rollout status deployment hello-web ``` ### 8. roll-back deployment ```shell= kubectl rollout undo deployment hello-web ```