title | description |
---|---|
GCP Google Kubernetes Engine Horizontal Pod Autoscaling |
Implement GKE Cluster Horizontal Pod Autoscaling |
- Verify if GKE Cluster is created
- Verify if kubeconfig for kubectl is configured in your local terminal
# Configure kubeconfig for kubectl
gcloud container clusters get-credentials <CLUSTER-NAME> --region <REGION> --project <PROJECT>
# Replace Values CLUSTER-NAME, REGION, PROJECT
gcloud container clusters get-credentials standard-cluster-private-1 --region us-central1 --project kdaida123
- Implement a Sample Demo with Horizontal Pod Autoscaler
- Primarily review
HorizontalPodAutoscaler
Resource in file03-kubernetes-hpa.yaml
- 01-kubernetes-deployment.yaml
- 02-kubernetes-cip-service.yaml
- 03-kubernetes-hpa.yaml
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: hpa-myapp1
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp1-deployment
minReplicas: 1
maxReplicas: 10
targetCPUUtilizationPercentage: 50
# Deploy Sample
kubectl apply -f kube-manifests
# List Pods
kubectl get pods
Observation:
1. Currently only 1 pod is running
# List HPA
kubectl get hpa
# Run Load Test (New Terminal)
kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- https://myapp1-cip-service; done"
# List Pods (SCALE UP EVENT)
kubectl get pods
Observation:
1. New pods will be created to reduce the CPU spikes
# List HPA (after few mins - approx 10 mins)
kubectl get hpa
# List Pods (SCALE IN EVENT)
kubectl get pods
Observation:
1. Only 1 pod should be running
# Delete Load Generator Pod which is in Error State
kubectl delete pod load-generator
# Delete Sample App
kubectl delete -f kube-manifests