Vote on a wish each week for four consecutive weeks.
In modern cloud environments, application traffic is never constant. Sometimes an application receives hundreds of requests, while during peak hours, that number can increase to thousands or even millions.
So, how do we ensure that our application continues running smoothly without wasting cloud resources?
This is where Amazon Elastic Kubernetes Service (Amazon EKS) and Kubernetes Scaling come into the picture.
1. What is Amazon EKS Scaling?
Amazon EKS is a managed Kubernetes service provided by AWS that helps us deploy, manage, and scale containerized applications.
Scaling means increasing or decreasing resources based on application requirements.
In EKS, scaling mainly happens at two levels:
- Pod Scaling: Increasing or decreasing the number of application Pods.
- Node Scaling: Increasing or decreasing the number of worker nodes in the Kubernetes cluster.
For example, if your application normally runs with 2 Pods but suddenly receives heavy traffic, Kubernetes can increase the number of Pods to handle the additional requests.
If the existing worker nodes don't have enough resources to run those Pods, the cluster can also add more nodes.
2. Understanding the Two Types of Scaling
A. Horizontal Pod Autoscaler (HPA)
HPA automatically adjusts the number of Pods based on metrics such as CPU utilization and memory utilization.
Example:
Imagine your application is running with 2 Pods, and CPU utilization reaches 80%.
If your HPA is configured with a target CPU utilization of 50%, Kubernetes may increase the number of Pods to handle the workload.
Example configuration:
apiVersion: autoscaling/v2kind: HorizontalPodAutoscalermetadata: name: app-hpaspec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: nginx-deployment minReplicas: 2 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 50Here:
-
minReplicas: 2means at least 2 Pods will run.
-
maxReplicas: 10means HPA can scale up to 10 Pods.
-
averageUtilization: 50sets the target average CPU utilization to 50%.
B. Cluster Scaling
What happens when the existing worker nodes don't have enough CPU or memory to run additional Pods?
This is where cluster scaling becomes important.
Cluster scaling automatically adjusts the number of worker nodes according to workload requirements.
For example:
- Initially, your EKS cluster has 2 worker nodes.
- Application traffic increases.
- HPA creates additional Pods.
- Existing nodes don't have enough resources.
- A node autoscaling solution adds more worker nodes.
- Kubernetes schedules the pending Pods on the available nodes.
3. Tools Used for EKS Cluster Scaling
Two commonly used solutions are:
1. Cluster Autoscaler
Cluster Autoscaler monitors whether Pods are unable to get scheduled because of insufficient cluster resources.
If additional capacity is required, it can increase the size of an AWS Auto Scaling Group associated with the worker nodes.
It can also reduce the number of nodes when they are no longer required and can be safely removed.
2. Karpenter
Karpenter is an open-source Kubernetes node provisioning solution that works with AWS.
It observes unscheduled Pods and provisions suitable compute capacity to run them.
It can select instance types based on the resource requirements of the workload and can consolidate workloads to reduce unnecessary infrastructure costs.
In simple words:
- Cluster Autoscaler generally works with configured node groups or Auto Scaling Groups.
- Karpenter can dynamically select and provision suitable EC2 instances based on workload requirements.
4. How Does EKS Scaling Work Together?
Let's understand the complete workflow:
- Users send requests to your application.
- Application traffic increases.
- HPA detects increased resource utilization.
- HPA increases the number of Pods.
- If existing worker nodes lack sufficient capacity, some Pods remain Pending.
- Karpenter or Cluster Autoscaler detects the need for additional capacity.
- New EC2 worker nodes are provisioned.
- Kubernetes schedules the pending Pods on the new nodes.
- When traffic decreases, unnecessary Pods and nodes can be scaled down.
5. Real-World Example
Imagine you are running an e-commerce application on Amazon EKS.
During normal days:
- 2 worker nodes
- 3 application Pods
During a major sale:
- Traffic increases significantly.
- HPA increases the number of Pods from 3 to 10.
- Existing nodes run out of available resources.
- Karpenter provisions additional EC2 instances.
- New Pods are scheduled on the additional nodes.
After the sale:
- Traffic decreases.
- HPA reduces the number of Pods.
- Karpenter can consolidate workloads and remove unnecessary nodes.
This helps maintain application performance while avoiding unnecessary infrastructure costs.
6. Why Is EKS Scaling Important?
- High Availability: Helps applications handle changing workloads.
- Performance: Provides additional resources when demand increases.
- Cost Optimization: Reduces unnecessary infrastructure when demand decreases.
- Automation: Reduces the need for manual intervention.
- Flexibility: Supports applications with unpredictable traffic patterns.
Conclusion
Amazon EKS scaling is not just about increasing the number of Pods or EC2 instances. It is about maintaining the right balance between application performance, infrastructure availability, and cloud costs.
Understanding HPA, Cluster Autoscaler, and Karpenter is an important step toward building scalable and production-ready Kubernetes applications on AWS.
My Key Learning: HPA scales Pods, while Karpenter or Cluster Autoscaler helps scale the underlying worker-node capacity. Together, they make EKS more flexible and efficient.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article