如文档中所述,HPA apiVersion:autoscaling / v2beta1支持内存自动缩放,但不适用于我。我们非常感谢您的帮助。
HPA:
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: xxx
spec:
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: xxx
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 70
- type: Resource
resource:
name: memory
targetAverageValue: 1050Mi
Deployment.yml:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: xxx
spec:
replicas: 1
template:
metadata:
labels:
service: xxx
spec:
containers:
- name: xxx
image: xxx
imagePullPolicy: Always
resources:
requests:
memory: "1024M"
cpu: "500m"
limits:
memory: "2048M"
cpu: "1000m"
livenessProbe:
httpGet:
path: /swagger-ui.html
port: 9002
initialDelaySeconds: 5
periodSeconds: 180
readinessProbe:
httpGet:
path: /swagger-ui.html
port: 9002
initialDelaySeconds: 10
periodSeconds: 5
Kubectl描述HPA
Metrics: ( current / target )
resource memory on pods: 1343959859200m / 1050Mi
resource cpu on pods (as a percentage of request): 4% (28m) / 70%
Min replicas: 1
Max replicas: 10
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale the last scale time was sufficiently old as to warrant a new scale
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from memory resource
ScalingLimited False DesiredWithinRange the desired count is within the acceptable range
Events: <none>
kubectl获得hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
xxx Deployment/xxx 1551148373333m/1050Mi, 98%/70% 1 10 3 42m
Kubectl版本:
kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.7", GitCommit:"0c38c362511b20a098d7cd855f1314dad92c2780", GitTreeState:"clean", BuildDate:"2018-08-20T10:09:03Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.5-gke.5", GitCommit:"9aba9c1237d9d2347bef28652b93b1cba3aca6d8", GitTreeState:"clean", BuildDate:"2018-12-11T02:36:50Z", GoVersion:"go1.10.3b4", Compiler:"gc", Platform:"linux/amd64"}
Gcloud信息:
[compute]
region: [us-east1]
zone: [us-east1-b]
如图所示,K8S知道有多少内存超出了目标值,但是即使我等待了很长时间也无法自动缩放Pod。我只能通过CPU自动缩放。
答案 0 :(得分:0)
您提到Autoscaler仅适用于CPU,在部署HPA时,是否仅设置CPU指标?
在阅读了k8s中的HPA演练文档之后,我注意到在设置多个指标时必须达到所有指标才能进行缩放,请参阅本节:
因此,在您的情况下,自动缩放器必须同时满足CPU和内存使用率指标。