Site icon Learning & Doing

Exploring Cost-optimization for GKE Virtual Machines

exploring

“Exploring Cost-optimization for GKE Virtual Machines”

Daftar Isi

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

gcloud container clusters get-credentials hello-demo-cluster --zone us-central1-a
kubectl scale deployment hello-server --replicas=2
gcloud container clusters resize hello-demo-cluster --node-pool node \
    --num-nodes 3 --zone us-central1-a

Examine your cluster

Migrate to optimized node pool

gcloud container node-pools create larger-pool \
  --cluster=hello-demo-cluster \
  --machine-type=e2-standard-2 \
  --num-nodes=1 \
  --zone=us-central1-a
for node in $(kubectl get nodes -l cloud.google.com/gke-nodepool=node -o=name); do
  kubectl cordon "$node";
done
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
kubectl get pods -o=wide
gcloud container node-pools delete node --cluster hello-demo-cluster --zone us-central1-a

Cost analysis

Task 3. Managing a regional cluster

gcloud container clusters create regional-demo --region=us-central1 --num-nodes=1
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
kubectl apply -f pod-1.yaml
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
kubectl apply -f pod-2.yaml
kubectl get pod pod-1 pod-2 --output wide

Simulate traffic

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

Examine flow logs

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.
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

Move a chatty pod to minimize cross-zonal traffic costs

sed -i 's/podAntiAffinity/podAffinity/g' pod-2.yaml
kubectl delete pod 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.

Exit mobile version