EKS master Node AutoScaling is fully managed by EKS.
- There are two Scaling in EKS:
- Node AutoScaling (Cluster AutoScaler & karpenter)
- POD AutoScaling (Hpa)
-
Node AutoScaling: It is "Cluster AutoScaler" means increases worker node, For this EKS use aws ASG service(Auto scaling group).
There are two Autoscaling are available for Node that is "Cluster AutoScaler" & "karpenter".
for Autoscaling metrics is important, EKS uses aws "Cloud Watch" for matrics the node.
Matrics means the program keep on monitoring the CPU,RAM of Nodes.
-
POD AutoScaling:
For Pod AutoScaling Hpa(Horizontal Pod AutoScaling) is used.
Kubernetes give metrics server for pod autoscaling, we need to download that metrics server which helps us for AutoScaling.
Steps:
- Create cluster with enabling asg access.
- Download Cluster Autoscaler YAML file.
- Edit Cluster Autoscaler YAML file.
- Apply Cluster Autoscaler YAML file. (Start Pod)
eksctl create cluster --name pscluster2 --region ap-south-1 --version 1.30 --nodegroup-name psnodegp --instance-types t2.micro --nodes 3 --nodes-min 3 --nodes-max 6 --node-volume-size 8 --node-volume-type gp3 --ssh-access --enable-ssm --instance-name psworkernode --asg-access --managed
Step-2: [Download asg file (This command download GitHub file named as "cluster-autoscaler-autodiscover.yaml")]
curl -O https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml
The YAML file sets up permissions and deploys the Cluster Autoscaler pod, which automatically scales our Kubernetes cluster based on workload demands.
notepad cluster-autoscaler-autodiscover.yaml
Check right version of image as compare to kubernetes version while creating cluster:
Set Auto scale down time:
In this file we replace "" > "pscluster2" my cluster name
kubectl apply -f cluster-autoscaler-autodiscover.yaml
After apply check cluster-autoscaler pod run:
kubectl get pods -n kube-system
Check lastest version or on which version our kubernetes work and use that image for autoscaler pod: (https://github.com/kubernetes/autoscaler/releases)
In my case i use version -->> --version 1.30 so i use image version ":v1.30.1"
command for deployment.apps/cluster-autoscaler image updated: (Optional commad/not needed)
kubectl set image deployment cluster-autoscaler -n kube-system cluster-autoscaler=registry.k8s.io/autoscaling/cluster:v1.30.1
we can check nodes details info using command:
kubectl describe nodes
we can check specific nodes details info using command:
kubectl describe nodes <nodeName>
The manual Horizontal scaling of pods we can done using command:
kubectl scale deployment myps1 --replicas=5
- Steps: (Steps for Autoscaling of pods)
- Install/Download Metrics server & check that is running.
- Start Hps for deployment.
-
Note:
There is no program running which give metrics of pods, without metrics server we can't use AutoScaling because of this Kubernetes provide "Metrics server".
Metrics server keep on monitoring on all pods(CPU, RAM), If load come then auto horizontal scaling done by using Hpa.
Metrics server is one kind of program running as pod.
Hpa: Horizontal pod AutoScaling
Search on browser 'kubernetes metric server' Metrics-server-pod-link
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
Check running metrics server pod command:
kubectl get pods -n kube-system
kubectl get deployment -n kube-system
We can launch a pod with Hpa, it means we set that pod/deployment as Hpa which autoscale according to load.
Hpa is just progarm which attach to Pod/deployment.
for thid i use load generator app which provided by Kubernetes for checking AutoScaling working Load-generator-app-link
To demonstrate a HorizontalPodAutoscaler, you will first start a Deployment that runs a container using the hpa-example image, and expose it as a Service using the following manifest:
kubectl apply -f https://k8s.io/examples/application/php-apache.yaml
Create the HorizontalPodAutoscaler:
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
Here we use autoscale keyword which start hpa and set cpu limit=50 and minimum and maximum replicas/scale limit.
Check Hpa start cmd:
kubectl get hpa
-
Now Increase load (This command need fresh terminal or clear terminal):
kubectl run -i --tty load-generator --rm --image=busybox:1.28 --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"
-
We can check the the our load increases by watch command:
kubectl get hpa php-apache --watch
- Pods: The metrics server keep on monitoring on pod as soon as load increases on pod/deployment, It send information to hpa (Horizontal pod autoscaler) and based upon that information Hpa keeps on launching & terminating pods.
- Nodes: "Cluster Autoscaler"(YMAl file) keep on monitoring and send information to "asg". It capture information & that information send to asg and based upon information it keeps in launching and terminating Nodes(Instances).
-
Note:
as soon as we stop load generator then 1st pods scale-in to 1 and then Nodes Scale-in to 3 because min=3