简体   繁体   English

Kubernetes - HPA 指标 - 内存和 CPU

[英]Kubernetes - HPA metrics - memory & cpu together

Is it possible to keep 'cpu' and 'memory' metrics together as shown below ?是否可以将“cpu”和“内存”指标保持在一起,如下所示? This seems to be not working.这似乎不起作用。 I tried below script as HPA.我尝试了以下脚本作为 HPA。 But instently pods has grown upto 5. That's not what i was expecting.但是 pods 很快就长到了 5 个。这不是我所期望的。

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: myservice-metrics
  namespace: myschema
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myservice
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - type: Resource
    resource:
      name: memory
      targetAverageValue: 500Mi
  - type: Resource
    resource:
      name: cpu
      targetAverageUtilization: 70

If i keep it individually, it is not complaining.如果我单独保存它,它不会抱怨。 Is it the best practice to set both the metrics for a service ?为服务设置两个指标是最佳实践吗? is there any other way to set both the metrics.有没有其他方法可以设置这两个指标。

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: myservice-metrics-memory
  namespace: myschema
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myservice
  minReplicas: 1
  maxReplicas: 3
  metrics:
  - type: Resource
    resource:
      name: memory
      targetAverageValue: 500Mi


apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: myservice-metrics-cpu
  namespace: myschema
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myservice
  minReplicas: 1
  maxReplicas: 3
  metrics:
  - type: Resource
    resource:
      name: cpu
      targetAverageUtilization: 70

Starting from Kubernetes v1.6 support for scaling based on multiple metrics has been added.从 Kubernetes v1.6 开始,添加了基于多个指标的扩展支持。 I would suggest to try and switch to the autoscaling/v2beta2 API.我建议尝试切换到autoscaling/v2beta2 API。

https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-multiple-metrics https://kubernetes.io/docs/tasks/run-application/horizo​​ntal-pod-autoscale/#support-for-multiple-metrics

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM