Tuesday, November 12, 2024
GCP GKE Juara GCP

Understanding and Combining GKE Autoscaling Strategies

combining

“Understanding and Combining GKE Autoscaling Strategies”

Daftar Isi

Pengantar

Google Kubernetes Engine memiliki solusi horizontal dan vertikal untuk menskalakan pod dan infrastruktur Anda secara otomatis. Dalam hal pengoptimalan biaya, alat ini menjadi sangat berguna untuk memastikan bahwa beban kerja Anda dijalankan seefisien mungkin dan Anda hanya membayar apa yang Anda gunakan.

Praktikum

Task 1. Scale pods with Horizontal Pod Autoscaling

  • Cek deployment
kubectl get deployment
  • setting horizontal -autoscale deployment untuk php-apache
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
  • cek status scaling pod
kubectl get hpa

Task 2. Scale size of pods with Vertical Pod Autoscaling

  • cek demo scaling
gcloud container clusters describe scaling-demo | grep ^verticalPodAutoscaling -A 1
kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0
  • cek deployment
kubectl get deployment hello-server
kubectl set resources deployment hello-server --requests=cpu=450m
  • cek detail container
kubectl describe pod hello-server | sed -n "/Containers:$/,/Conditions:/p"
  • Buat manifest Vertical Pod Autoscaler
cat << EOF > hello-vpa.yaml
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: hello-server-vpa
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind:       Deployment
    name:       hello-server
  updatePolicy:
    updateMode: "Off"
EOF
  • apply manifest
kubectl apply -f hello-vpa.yaml
  • cek detail
kubectl describe vpa hello-server-vpa
sed -i 's/Off/Auto/g' hello-vpa.yaml
kubectl apply -f hello-vpa.yaml
  • buat scaling replica
kubectl scale deployment hello-server --replicas=2
  • cek pod
kubectl get pods -w

Task 3. HPA results

  • cek HPA
kubectl get hpa

Task 4. VPA results

  • detail pod
kubectl describe pod hello-server | sed -n "/Containers:$/,/Conditions:/p"

Task 5. Cluster autoscaler

  • enable autoscaling pada cluster
gcloud beta container clusters update scaling-demo --enable-autoscaling --min-nodes 1 --max-nodes 5
gcloud beta container clusters update scaling-demo \
--autoscaling-profile optimize-utilization
  • buka Navigation menu, select Kubernetes Engine > Clusters
  • pilih scaling-demo cluster
  • cek system kube
kubectl get deployment -n kube-system
  • Buat Pod Disruption Budget untuk semua kube-system
kubectl create poddisruptionbudget kube-dns-pdb --namespace=kube-system --selector k8s-app=kube-dns --max-unavailable 1
kubectl create poddisruptionbudget prometheus-pdb --namespace=kube-system --selector k8s-app=prometheus-to-sd --max-unavailable 1
kubectl create poddisruptionbudget kube-proxy-pdb --namespace=kube-system --selector component=kube-proxy --max-unavailable 1
kubectl create poddisruptionbudget metrics-agent-pdb --namespace=kube-system --selector k8s-app=gke-metrics-agent --max-unavailable 1
kubectl create poddisruptionbudget metrics-server-pdb --namespace=kube-system --selector k8s-app=metrics-server --max-unavailable 1
kubectl create poddisruptionbudget fluentd-pdb --namespace=kube-system --selector k8s-app=fluentd-gke --max-unavailable 1
kubectl create poddisruptionbudget backend-pdb --namespace=kube-system --selector k8s-app=glbc --max-unavailable 1
kubectl create poddisruptionbudget kube-dns-autoscaler-pdb --namespace=kube-system --selector k8s-app=kube-dns-autoscaler --max-unavailable 1
kubectl create poddisruptionbudget stackdriver-pdb --namespace=kube-system --selector app=stackdriver-metadata-agent --max-unavailable 1
kubectl create poddisruptionbudget event-pdb --namespace=kube-system --selector k8s-app=event-exporter --max-unavailable 1
kubectl get nodes

Task 6. Node Auto Provisioning

  • Enable node auto provisioning
gcloud container clusters update scaling-demo \
    --enable-autoprovisioning \
    --min-cpu 1 \
    --min-memory 2 \
    --max-cpu 45 \
    --max-memory 160

Task 7. Test with larger demand

kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"
  • cek hpa di terminal yg pertama
kubectl get hpa
  • monitor cluster hendle
kubectl get deployment php-apache

Task 8. Optimize larger loads

  • formula
Baca Juga :  App Dev: Storing Application Data in Cloud Datastore - Python
  • Buat manifest untuk pod yang di pause
cat << EOF > pause-pod.yaml
---
apiVersion: scheduling.k8s.io/v1beta1
kind: PriorityClass
metadata:
  name: overprovisioning
value: -1
globalDefault: false
description: "Priority class used by overprovisioning."
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: overprovisioning
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      run: overprovisioning
  template:
    metadata:
      labels:
        run: overprovisioning
    spec:
      priorityClassName: overprovisioning
      containers:
      - name: reserve-resources
        image: k8s.gcr.io/pause
        resources:
          requests:
            cpu: 1
            memory: 4Gi
EOF
  • apply di cluster
kubectl apply -f pause-pod.yaml

Penutup

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Understanding and Combining GKE Autoscaling Strategies. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

(Visited 63 times, 1 visits today)

Similar Posts