在 GKE 上使用 HPA(Horizontal Pod Autoscaler)和 Cluster Autoscaler,Pod 和节点按预期扩展。但是,当需求减少时,似乎会从随机节点中删除 pod。它导致使用较少的节点。这不划算...
编辑:HPA 基于 targetCPUUtilizationPercentage 单一指标。不使用 VPA。
这是用于部署和 HPA 的简化 yaml 文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: foo
spec:
replicas: 1
templates:
spec:
containers:
- name: c1
resources:
requests:
cpu: 200m
memory: 1.2G
- name: C2
resources:
requests:
cpu: 10m
volumeMounts:
- name: log-share
mountPath: /mnt/log-share
- name: C3
resources:
requests:
cpu: 10m
limits:
cpu: 100m
- name: log-share
mountPath: /mnt/log-share
volumes:
- name: log-share
emptyDir: {}
---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: foo
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: foo
minReplicas: 1
maxReplicas: 60
targetCPUUtilizationPercentage: 80
...
EDIT2:添加一个 emptyDir 卷作为有效示例。
我该如何改善这种情况?
有一些想法,但没有一个能完全解决问题......
- 配置节点池机器类型和 pod 资源请求,以便在一个节点上只容纳一个 pod。如果一个 pod 被 HPA 从一个节点中删除,该节点会在一段时间后被删除,但它不适用于各种资源请求的部署。
- 如果可能,使用抢占式节点...