概括
在我们的 Kubernetes 集群中,我们引入了 HPA whit memory 和 cpu 限制。现在我们不明白为什么我们有一个服务的 2 个副本。
有问题的服务使用 57% / 85% 内存并且有 2 个副本而不是 1 个。我们认为这是因为当您将两个 pod 的内存加起来时,它超过了 85%,但如果只有一个 pod,则不会。那么这是否会阻止它缩小规模?我们可以在这里做什么?
当我们部署服务时,我们还观察到内存使用高峰。我们在 aks (azure) 中使用 spring-boot 服务,并认为它可能会在那里扩展,并且永远不会下降。我们错过了什么或有任何建议吗?
舵
帕:
{{- $fullName := include "app.fullname" . -}}
{{- $ := include "app.fullname" . -}}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ $fullName }}-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "app.name" . }}
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 50
- type: Resource
resource:
name: memory
targetAverageUtilization: 85
并在部署中:
# Horizontal-Pod-Auto-Scaler
resources:
requests:
memory: {{ $requestedMemory }}
cpu: {{ $requesteCpu }}
limits:
memory: {{ $limitMemory }}
cpu: {{ $limitCpu }}
使用服务默认值:
hpa:
resources:
request:
memory: 500Mi
cpu: 300m
limits:
memory: 1000Mi
cpu: 999m
kubectl 获取 hpa -n dev
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
xxxxxxxx-load-for-cluster-hpa Deployment/xxxxxxxx-load-for-cluster 34%/85%, 0%/50% 1 10 1 4d7h
xxx5-ccg-hpa Deployment/xxx5-ccg 58%/85%, 0%/50% 1 10 1 4d12h
iotbootstrapping-service-hpa Deployment/iotbootstrapping-service 54%/85%, 0%/50% 1 10 1 4d12h
mocks-hpa Deployment/mocks 41%/85%, 0%/50% 1 10 1 4d12h
user-pairing-service-hpa Deployment/user-pairing-service 41%/85%, 0%/50% 1 10 1 4d12h
aaa-registration-service-hpa Deployment/aaa-registration-service 57%/85%, 0%/50% 1 10 2 4d12h
webshop-purchase-service-hpa Deployment/webshop-purchase-service 41%/85%, 0%/50% 1 10 1 4d12h
kubectl 描述 hpa -n dev
Name: xxx-registration-service-hpa
Namespace: dev
Labels: app.kubernetes.io/managed-by=Helm
Annotations: meta.helm.sh/release-name: vwg-registration-service
meta.helm.sh/release-namespace: dev
CreationTimestamp: Thu, 18 Jun 2020 22:50:27 +0200
Reference: Deployment/xxx-registration-service
Metrics: ( current / target )
resource memory on pods (as a percentage of request): 57% (303589376) / 85%
resource cpu on pods (as a percentage of request): 0% (1m) / 50%
Min replicas: 1
Max replicas: 10
Deployment pods: 2 current / 2 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 False DesiredWithinRange the desired count is within the acceptable range
Events: <none>
如果需要任何进一步的信息,请随时询问!
非常感谢您抽出宝贵的时间!
干杯罗宾