https://github.com/pratikshinde55/aws-eks-autoscaler-pod_node
The project ensures optimal resource allocation and system resilience through automated scaling mechanisms, driven by real-time CPU and RAM metrics.
https://github.com/pratikshinde55/aws-eks-autoscaler-pod_node
Last synced: 3 months ago
JSON representation
The project ensures optimal resource allocation and system resilience through automated scaling mechanisms, driven by real-time CPU and RAM metrics.
- Host: GitHub
- URL: https://github.com/pratikshinde55/aws-eks-autoscaler-pod_node
- Owner: Pratikshinde55
- Created: 2024-08-09T10:57:06.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-02-05T10:12:28.000Z (4 months ago)
- Last Synced: 2025-02-05T11:24:00.469Z (4 months ago)
- Homepage:
- Size: 131 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AWS EKS AutoScaler for Node & pod
**EKS master Node AutoScaling is fully managed by EKS.**There are two Scaling in EKS:
1. Node AutoScaling (Cluster AutoScaler & karpenter)
2. POD AutoScaling (Hpa)1. 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.2. 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. (In new Version v1.30 metrics-server is pre-configured)
## AutoScaler of Node:
Steps:
1. Create cluster with enabling asg access.
2. Download Cluster Autoscaler YAML file.
3. Edit Cluster Autoscaler YAML file.
4. Apply Cluster Autoscaler YAML file. (Start Pod)### Step-1: [This command is for create cluster with enable asg (--asg-access) (AutoScaler group)]
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")]
#### **What is cluster-autoscaler-autodiscover.yml in AWS EKS?**
The cluster-autoscaler-autodiscover.yml file is a Kubernetes manifest that deploys the Cluster Autoscaler in an EKS cluster.
It is responsible for automatically scaling worker nodes (EC2 instances) based on pod demand.#### **Why is cluster-autoscaler-autodiscover.yml Important?**
Even though AWS Auto Scaling Groups (ASG) handle scaling at the EC2 instance level, ASG alone does not understand Kubernetes pod scheduling.
Cluster Autoscaler (CA) is required to ensure the number of worker nodes dynamically adjusts based on pending pods.#### **Key Features of Cluster Autoscaler:**
- Monitors Pending Pods: If pods cannot be scheduled due to insufficient node capacity, CA requests ASG to scale out.
- Node Scale-In: If nodes are underutilized (empty), CA scales them down safely.
- Integrates with ASG: Uses AWS tags to discover and manage ASG dynamically.
- Works with K8s Scheduler: Ensures Kubernetes schedules pods efficiently.curl -O https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml
### Step-3: [Open and edit YAML file "cluster-autoscaler-autodiscover.yaml"]
The YAML file sets up permissions and deploys the Cluster Autoscaler, 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
### Step-4: [Apply file command(Create auto scaler pod)]
kubectl apply -f cluster-autoscaler-autodiscover.yaml
After apply check cluster-autoscaler 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
## AutoScaling of POD:
The manual Horizontal scaling of pods we can done using command:kubectl scale deployment myps1 --replicas=5
Steps: (Steps for Autoscaling of pods)
1. Install/Download Metrics server & check that is running.
2. 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### Step-1: [Install metrics server from YAML file]
Search on browser 'kubernetes metric server' [Metrics-server-pod-link](https://github.com/kubernetes-sigs/metrics-server)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

### Step-2: [Start Hpa for deployment]
- 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](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough)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

## See that Autoscaling of Pods and Nodes work:
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