“Optimize Costs for Google Kubernetes Engine: Challenge Lab”
Daftar Isi
Pengantar
Di lab tantangan, Anda diberi skenario dan serangkaian tugas. Alih-alih mengikuti petunjuk langkah demi langkah, Anda akan menggunakan keterampilan yang dipelajari dari lab dalam misi untuk mengetahui cara menyelesaikan tugas sendiri! Sistem penilaian otomatis (ditampilkan di halaman ini) akan memberikan umpan balik apakah Anda telah menyelesaikan tugas dengan benar.
Praktikum
Task 1. Create our cluster and deploy our app
- set timezone
ZONE=us-central1-a
- Create cluster
gcloud container clusters create onlineboutique-cluster \
--project=${DEVSHELL_PROJECT_ID} --zone=${ZONE} \
--machine-type=n1-standard-2 --num-nodes=2
- Setup namespace
kubectl create namespace dev
kubectl create namespace prod
- switch ke dev
kubectl config set-context --current --namespace dev
- copy dan deploy app
git clone https://github.com/GoogleCloudPlatform/microservices-demo.git &&
cd microservices-demo && kubectl apply -f ./release/kubernetes-manifests.yaml --namespace dev
- tunggu sampai muncul frontend external IP
kubectl get svc -w --namespace dev
Task 2: Migrate to an Optimized Nodepool
- Create node pool
gcloud container node-pools create optimized-pool \
--cluster=onlineboutique-cluster \
--machine-type=custom-2-3584 \
--num-nodes=2 \
--zone=$ZONE
- cordon dan drain default-pool
for node in $(kubectl get nodes -l cloud.google.com/gke-nodepool=default-pool -o=name); do
kubectl cordon "$node";
done
for node in $(kubectl get nodes -l cloud.google.com/gke-nodepool=default-pool -o=name); do
kubectl drain --force --ignore-daemonsets --delete-local-data --grace-period=10 "$node";
done
- cek running pod
kubectl get pods -o=wide --namespace dev
- delete default pool
gcloud container node-pools delete default-pool \
--cluster onlineboutique-cluster --zone $ZONE
Task 3: Apply a Frontend Update
- setting pod disruption budget
kubectl create poddisruptionbudget onlineboutique-frontend-pdb \
--selector app=frontend --min-available 1 --namespace dev
- update resource
KUBE_EDITOR="nano" kubectl edit deployment/frontend --namespace dev
Ganti konfigurasi
image to gcr.io/qwiklabs-resources/onlineboutique-frontend:v2.1, and
imagePullPolicy to Always
- masuk menu Kubernetes Engine > Workloads dan click
frontend
Task 4: Autoscale from Estimated Traffic
- buat horizontal pod autoscaling
kubectl autoscale deployment frontend --cpu-percent=50 \
--min=1 --max=13 --namespace dev
- cek status
kubectl get hpa --namespace dev
- update cluster autoscaler
gcloud beta container clusters update onlineboutique-cluster \
--enable-autoscaling --min-nodes 1 --max-nodes 6 --zone $ZONE
- test autoscaler
kubectl exec $(kubectl get pod --namespace=dev | grep 'loadgenerator' | cut -f1 -d ' ') \
-it --namespace=dev -- bash -c "export USERS=8000; sh ./loadgen.sh"
- cek overview di frontend
- scroll ke manage pods
Penutup
Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Optimize Costs for Google Kubernetes Engine: Challenge Lab. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.