Skip to main content

Configure HPA

Currently there are no resources in our cluster that enable horizontal pod autoscaling, which you can check with the following command:

~$kubectl get hpa -A
No resources found

In this case we're going to use the ui service and scale it based on CPU usage. The first thing we'll do is update the ui Pod specification to specify CPU request and limit values.

~/environment/eks-workshop/modules/autoscaling/workloads/hpa/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ui
spec:
template:
spec:
containers:
- name: ui
resources:
limits:
cpu: 250m

Next, we need to create a HorizontalPodAutoscaler resource which defines the parameters HPA will use to determine how to scale our workload.

~/environment/eks-workshop/modules/autoscaling/workloads/hpa/hpa.yaml
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: ui
namespace: ui
spec:
maxReplicas: 4
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: ui
targetCPUUtilizationPercentage: 80

Let's apply this configuration:

~$kubectl apply -k ~/environment/eks-workshop/modules/autoscaling/workloads/hpa