Kubenetes
Kubernetes 自动扩缩容
· ☕ 1 分钟

本文状态:草稿

image-20210323153341945

配置例子

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: php-apache
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50

算法

desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]

currentMetricValue 为相关 pod 的 metric 平均数。