Autoscale application
Horizontal Pod Autoscaler and Vertical Pod Autoscaler should not be used together to scale the same metric. See using HPA & VPA in conjunction
For more details on how autoscaling works see Autoscaling in depth.
Core Platform app templates enable Horizontal Pod Autoscaling by default for new applications. The generated defaults are two to eight replicas, scaling on 80% CPU utilization, with a 30 second scale-up stabilization window and a 300 second scale-down stabilization window.
Configure Autoscaling In P2P
For generated applications, configure autoscaling through the app config and P2P Helm values rather than creating a standalone HPA manifest.
The root app.yaml contains the defaults used by P2P:
config:
replicas: 2
autoscaling:
enabled: true
minReplicas: 2
maxReplicas: 8
targetCPUUtilizationPercentage: 80
behavior:
scaleUp:
stabilizationWindowSeconds: 30
scaleDown:
stabilizationWindowSeconds: 300The generated p2p/config/common.yaml passes those values to the Core Platform app chart:
replicaCount: ${p2p_app_config_replicas}
autoscaling:
enabled: ${p2p_app_config_autoscaling_enabled}
minReplicas: ${p2p_app_config_autoscaling_minReplicas}
maxReplicas: ${p2p_app_config_autoscaling_maxReplicas}
targetCPUUtilizationPercentage: ${p2p_app_config_autoscaling_targetCPUUtilizationPercentage}
behavior:
scaleUp:
stabilizationWindowSeconds: ${p2p_app_config_autoscaling_behavior_scaleUp_stabilizationWindowSeconds}
scaleDown:
stabilizationWindowSeconds: ${p2p_app_config_autoscaling_behavior_scaleDown_stabilizationWindowSeconds}P2P stages that clean up by scaling workloads to zero should disable HPA in their stage override file:
autoscaling:
enabled: falseThis prevents HPA from reconciling the deployment back to minReplicas during cleanup.
Horizontal Scaling using CPU
Increase pod replicas if cpu of pod exceeds 60%
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: reference-app
labels:
app.kubernetes.io/name: reference-app
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: reference-app
minReplicas: 1
maxReplicas: 30
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60Horizontal Scaling using Memory
Increase pod replicas if memory usage exceeds 60%
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: reference-app
labels:
app.kubernetes.io/name: reference-app
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: reference-app
minReplicas: 1
maxReplicas: 30
metrics:
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 60Vertical Scaling
Pod cpu/memory requests will automatically be updated based on utilisation. If you do not wish VPA to update pod requests, set updateMode: Off
apiVersion: autoscaling.k8s.io/v1beta2
kind: VerticalPodAutoscaler
metadata:
name: reference-app
labels:
app.kubernetes.io/name: reference-app
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: reference-app
updatePolicy:
updateMode: "Auto"
resourcePolicy:
containerPolicies:
- containerName: "*"
minAllowed:
cpu: 100m
memory: 50Mi
maxAllowed:
cpu: 1
memory: 1Gi
controlledResources: ["cpu", "memory"]