我很难理解我的水平 pod 自动缩放器发生了什么。
如果内存或 CPU 使用率超过 80%,我正在尝试扩大我的部署。
这是我的 HPA 模板:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: my-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-deployment
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
问题是,即使使用率低于 80%,它也已经坐了 3 个副本好几天了,我不明白为什么。
$ kubectl get hpa --all-namespaces
NAMESPACE NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
my-ns my-hpa Deployment/my-deployment 61%/80%, 14%/80% 2 10 3 2d15h
这是 top 命令的输出:
$ kubectl top pods
NAME CPU(cores) MEMORY(bytes)
my-deployment-86874588cc-chvxq 3m 146Mi
my-deployment-86874588cc-gkbg9 5m 149Mi
my-deployment-86874588cc-nwpll 7m 149Mi
每个 pod 消耗大约 60% 的请求内存(因此它们低于 80% 的目标):
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "200m"
这是我的部署:
kind: Deployment
apiVersion: apps/v1
metadata:
name: my-deployment
labels:
app: my-app
spec:
replicas: 2
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: ...
imagePullPolicy: Always
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "200m"
livenessProbe:
httpGet:
path: /liveness
port: 3000
initialDelaySeconds: 10
periodSeconds: 3
timeoutSeconds: 3
readinessProbe:
httpGet:
path: /readiness
port: 3000
initialDelaySeconds: 10
periodSeconds: 3
timeoutSeconds: 3
ports:
- containerPort: 3000
protocol: TCP
我手动缩小到 2 个副本,它会无缘无故地立即恢复到 3 个:
Normal SuccessfulRescale 28s (x4 over 66m) horizontal-pod-autoscaler New size: 3; reason:
有人知道发生了什么吗?