Automatic Scaling Process of Apinizer Pods
This document explains how to configure horizontal auto-scaling of pods.
This horizontal scaling feature optimizes resource usage by automatically increasing or decreasing the number of pods based on the demands of the application.
To use the scaling feature in your Kubernetes cluster, you must have a metric-server installed. If it is not available, you can click here to install it.
vi hpa-autoscaling.yaml
POWERSHELL
Edit the Namespace and Deployment Name fields in Yaml according to your application.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: apinizer-hpa
namespace: <NAMESPACE>
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: <DEPLOYMENT_NAME>
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 70
behavior:
scaleDown:
selectPolicy: Max
policies:
- type: Pods
value: 1
periodSeconds: 60
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Pods
value: 1
periodSeconds: 60
selectPolicy: Max
POWERSHELL
kubectl apply -f manager-hpa-autoscaling.yaml
POWERSHELL
Alan | Açıklama |
---|---|
scaleTargetRef | In this field, it is specified for which deployment the scaling will work. Example: manager. |
minReplicas | It is the minimum number of pods. |
maxReplicas | It is the maximum number of pods that can be in the system. |
averageUtilization | In this field, you can enter a percentage value for CPU and memory usage. As a result of rising above the specified level, a pod will be created. |
scaleDown | If it falls below the target usage level, it will reduce the number of newly created pods by the amount given every 60 seconds. |
scaleUp | If it exceeds the target usage level, the specified stabilizationWindowSeconds value is checked for 60 seconds. If the condition is met, a pod will be added to your cluster every 60 seconds. |
To turn off the scaleDown feature, change selectPolicy: Disabled.