Sunday, February 5, 2023
GCP GKE Juara GCP VMware

Exploring Cost-optimization for GKE Virtual Machines

exploring

“Exploring Cost-optimization for GKE Virtual Machines”

Pengantar

Infrastruktur yang mendasari cluster Google Kubernetes Engine terdiri dari node yang merupakan instance VM Compute individual. Lab ini menunjukkan bagaimana pengoptimalan infrastruktur klaster Anda dapat membantu menghemat biaya dan menghasilkan arsitektur yang lebih efisien untuk aplikasi Anda.

Praktikum

Task 1. Understanding Node machine types

Task 2. Choosing the right machine type for the Hello app

  • Klik Navigation Menu dan click pada Kubernetes Engine
  • Klik hello-demo-cluster.
  • Cek helo-server -> 400 mCpu
  • Akes credensial via cloudshell
gcloud container clusters get-credentials hello-demo-cluster --zone us-central1-a
  • Scale up hello-server
kubectl scale deployment hello-server --replicas=2
  • Pilih Workloads
  • Muncul error -> Does not have minimum availability
  • naikan node pool
gcloud container clusters resize hello-demo-cluster --node-pool node \
    --num-nodes 3 --zone us-central1-a
  • Cek lagi hello-server pada menu workload , status OK

Examine your cluster

  • Klik hello-demo-cluster
  • Klik nodes

Migrate to optimized node pool

  • Buat node pool baru
gcloud container node-pools create larger-pool \
  --cluster=hello-demo-cluster \
  --machine-type=e2-standard-2 \
  --num-nodes=1 \
  --zone=us-central1-a
  • cordon pool
for node in $(kubectl get nodes -l cloud.google.com/gke-nodepool=node -o=name); do
  kubectl cordon "$node";
done
  • drain pool
for node in $(kubectl get nodes -l cloud.google.com/gke-nodepool=node -o=name); do
  kubectl drain --force --ignore-daemonsets --delete-local-data --grace-period=10 "$node";
done
  • cek node
kubectl get pods -o=wide
  • delete pool yang lama
gcloud container node-pools delete node --cluster hello-demo-cluster --zone us-central1-a

Cost analysis

Task 3. Managing a regional cluster

  • Buat cluster baru
gcloud container clusters create regional-demo --region=us-central1 --num-nodes=1
  • Buat manifest
cat << EOF > pod-1.yaml
apiVersion: v1
kind: Pod
metadata:
  name: pod-1
  labels:
    security: demo
spec:
  containers:
  - name: container-1
    image: gcr.io/google-samples/hello-app:2.0
EOF
  • Buat pod baru
kubectl apply -f pod-1.yaml
  • Buat manifest untuk pod ke 2
cat << EOF > pod-2.yaml
apiVersion: v1
kind: Pod
metadata:
  name: pod-2
spec:
  affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: security
            operator: In
            values:
            - demo
        topologyKey: "kubernetes.io/hostname"
  containers:
  - name: container-2
    image: gcr.io/google-samples/node-hello:1.0
EOF
  • Buat pod yang ke 2
kubectl apply -f pod-2.yaml
  • Cek list pod
kubectl get pod pod-1 pod-2 --output wide

Simulate traffic

  • Masuk ke pod 1
kubectl exec -it pod-1 -- sh
ping [POD-2-IP]:8080

Examine flow logs

  • Klik Edit enable Flow Logs
  • Klik save
  • Klik View Flow Logs
  • Klik More actions > Create Sink
  • Tambahkan nama -> klik Next

Sink destination

For your Sink Service, select BigQuery Dataset.
For your BigQuery Dataset, select Create new BigQuery dataset.
Name your dataset us_central_flow_logs, and click CREATE DATASET.
  • Click Create Sink
  • buka Navigation Menu -> Big Data -> click BigQuery.
  • Pilih project name dan pilih us_central_flow_logs
  • klik compute_googleapis_com_vpc_flows_xxx
  • Klik Query > In new tab
  • Pada bigquery editor masukan
jsonPayload.src_instance.zone AS src_zone, jsonPayload.src_instance.vm_name AS src_vm, jsonPayload.dest_instance.zone AS dest_zone, jsonPayload.dest_instance.vm_name
  • Klik Run

Move a chatty pod to minimize cross-zonal traffic costs

  • Edit pod 2 mainfest
sed -i 's/podAntiAffinity/podAffinity/g' pod-2.yaml
  • delete pod 2 yang running
kubectl delete pod pod-2
  • Recreate pod 2
kubectl create -f pod-2.yaml
kubectl get pod pod-1 pod-2 --output wide
kubectl exec -it pod-1 -- sh
ping [POD-2-IP]:8080

Cost analysis

Lihat pada VM-VM egress pricing within Google Cloud:

Penutup

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Exploring Cost-optimization for GKE Virtual Machines. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

(Visited 17 times, 1 visits today)
Baca Juga :  Install Google Cloud SDK pada Linux Mint 20 | Ubuntu 20.04

Similar Posts