type=Utilization &&
type = AverageValue,,
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: backend-hpa
spec:
maxReplicas: 10
minReplicas: 3
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: backend
metrics:
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Pods
value: 1
periodSeconds: 100
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Pods
value: 2
periodSeconds: 35
我对如何计算内存利用率感到困惑?70%是基于什么阈值?
➜ kd hpa
Name: prod-backend-hpa-v1
Namespace: prod
Labels: argocd.argoproj.io/instance=ccl-backend-prod
Annotations: <none>
CreationTimestamp: Mon, 13 Sep 2021 17:39:44 -0700
Reference: Deployment/prod-backend-v1
Metrics: ( current / target )
resource memory on pods (as a percentage of request): 31% (85408426666m) / 70%
resource cpu on pods (as a percentage of request): 0% (1m) / 70%
Min replicas: 3
Max replicas: 10
Behavior:
Scale Up:
Stabilization Window: 60 seconds
Select Policy: Max
Policies:
- Type: Pods Value: 2 Period: 35 seconds
Scale Down:
Stabilization Window: 300 seconds
Select Policy: Max
Policies:
- Type: Pods Value: 1 Period: 100 seconds
Deployment pods: 3 current / 3 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale recommended size matches current size
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from memory resource utilization (percentage of request)
ScalingLimited True TooFewReplicas the desired replica count is less than the minimum replica count
Events: <none>
resource memory on pods (as a percentage of request): 31% (85408426666m) / 70%
计算?
我的部署有以下请求/限制设置
Containers:
backend:
Port: 8080/TCP
Host Port: 0/TCP
Command:
web
Limits:
cpu: 1
memory: 1Gi
Requests:
cpu: 200m
memory: 256Mi
my current pods
➜ k top po
W0914 13:38:13.793286 3006942 top_pod.go:140] Using json format to get metrics. Next release will switch to protocol-buffers, switch early by passing --use-protocol-buffers flag
NAME CPU(cores) MEMORY(bytes)
prod-backend-v1-7858bddc4-5t8r5 1m 80Mi
prod-backend-v1-7858bddc4-67llh 1m 81Mi
prod-backend-v1-7858bddc4-98wj2 1m 82Mi
所以似乎31%被计算为81/256 ~31%.
但是这样做正确吗?
我认为期望81/LIMIT = 81/1024 = ~8%.
type=Utilization &&averageUtilization:70
是所有相关pod中资源度量的平均值的目标值,表示为请求值的百分比。为pod提供资源。当前仅对资源度量源类型
有效type = AverageValue,,averageValue: 500Mi
averageValue是所有相关pod(作为数量)的度量平均值的目标值
所以我的HPA内存指标变成了:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: backend-hpa
spec:
maxReplicas: 10
minReplicas: 3
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: backend
metrics:
- type: Resource
resource:
name: memory
target:
type: AverageValue
averageValue: 500Mi # averageValue is the target value of the average of the metric across all relevant pods (as a quantity), https://www.pulumi.com/docs/reference/pkg/kubernetes/autoscaling/v2beta2/horizontalpodautoscalerlist/#metrictarget
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70 # represented as a percentage of the requested value of the resource for the pods.
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Pods
value: 1
periodSeconds: 100
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Pods
value: 2
periodSeconds: 35
更多信息:https://www.pulumi.com/docs/reference/pkg/kubernetes/autoscaling/v2beta2/horizontalpodautoscalerlist/metrictarget