Autoscaling
Setting up Auto Scaling
Horizontal Pod Autoscaler
Prerequisite
Make sure Metrics Server is installed on the cluster
You can check this using:
kubectl top pods -n kube-systemTo install, apply the metrics server manifest:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yamlThis can be verified using:
kubectl get deployment metrics-server -n kube-systemStep 1
Create a HPA manifest
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: uplevyl-api
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: uplevyl-api
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 75
- type: Resource
resource:
name: memory
target:
type: AverageValue
averageValue: 1Gi
Apply this using:
Step 2
Verify the HPA is running correctly using
Cluster Autoscaler
Cluster Autoscaling scales the Node Group the nodes in the cluster run on. Each cluster has at least one Node Group, which defines a template for nodes. When we scale up, we spin up more Nodes (ec2 instances) inside that Node Group.
Prerequisite
Make sure you have created a Node Group via eksctl with an Auto Scaling Group.
Step 1
Create a new IAM policy (if eksctl has not already) called AmazonEKSClusterAutoscalerPolicy.
Give it the policy:
Step 2
Create an IAM role using eksctl and attach the policy from Step 1
Step 3
Download the autoscaler from the source if you do not have it already.
Replace all instances of <YOUR CLUSTER NAME> with the name of the cluster.
Apply the config
Load Testing
To test the autoscaling capabilities, you can use Artillery. This is an npm tool that can run a test plan.
This can be run locally, but may be constrained by local networking resources.
A better option is to run it on an EC2 instance, or on the Kubernetes cluster itself.
SSH into a node image on the cluster:
Install Artillery globally:
Create a test plan on the image:
This will create 1000 users every second for 500 seconds.
To run this test plan:
Last updated
Was this helpful?