gcloud config set compute/zone asia-southeast1-a
gcloud container cluster create autoscaled
gcloud config set container/cluster autoscaled
gcloud container node-pools update default-pool --enable-autoscaling --min-nodes=0 --max-nodes=10
gcloud container clusters get-credentials autoscaled
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=LoadBalancer
The HPA config reference is as below
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: nginx
spec:
maxReplicas: 50
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nginx
targetCPUUtilizationPercentage: 10
# cd learn-gcp/content/solutions/container/files/
kubectl apply -f nginx-hpa-autoscaled.yaml
Deploy https://pkg.go.dev/github.com/rakyll/hey. On Red Hat yum install -y hey
kubectl get svc
hey -z 20m -c 250 http://$SVC_IP
kubectl get pods
kubectl get pods -w
kubectl get pods | grep nginx | wc -l
kubectl get pods | grep nginx | grep Running | wc -l
kubectl get nodes
Verify that the number of nodes scale up fast to 8, then slowly to 10.
gcloud container clusters delete autoscaled
kubectl get pods -o wide -A | grep kube-dns
This default setting can be changed to remove kube-system pods blocking node’s scale down. These kube-systems pods then can be placed on other nodes. Refer to this article for more details.
kubectl create poddisruptionbudget pdb-event --namespace=kube-system --selector k8s-app=event-exporter --max-unavailable 1 &&
kubectl create poddisruptionbudget pdb-fluentd-scaler --namespace=kube-system --selector k8s-app=fluentd-gcp-scaler --max-unavailable 1 &&
kubectl create poddisruptionbudget pdb-heapster --namespace=kube-system --selector k8s-app=heapster --max-unavailable 1 &&
kubectl create poddisruptionbudget pdb-dns --namespace=kube-system --selector k8s-app=kube-dns --max-unavailable 1 &&
kubectl create poddisruptionbudget pdb-dnsauto --namespace=kube-system --selector k8s-app=kube-dns-autoscaler --max-unavailable 1 &&
kubectl create poddisruptionbudget pdb-glbc --namespace=kube-system --selector k8s-app=glbc --max-unavailable 1
resource.type="k8s_cluster"
log_name="projects/addo-demo/logs/container.googleapis.com%2Fcluster-autoscaler-visibility"
resource.labels.cluster_name="autoscaled"