这里提供俩种创建yaml文件,第一种只监控你的CPU使用率,第二种监控你的CPU和内存。
前提:1.HPA需要依赖K8S中一些监控插件如heapster或metrics。
2.deployment中需指定resources,例如:
resources:
limits:
cpu: 1024m
memory: 512Mi
requests:
cpu: 256m
memory: 256Mi
否则HPA不会知道你的资源何时是上限。
---注意你的namespace,以及scaleTargetRef中你的deployment---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: nginx-ingress-controller
namespace: xltest-lyz
spec:
maxReplicas: 5
minReplicas: 3
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: nginx-ingress-controller
targetCPUUtilizationPercentage: 80
--------------------------------------------------------------------------------
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: xlppc-follow-api
namespace: xlppc
spec:
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: follow-release
minReplicas: 5
maxReplicas: 30
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 85
- type: Resource
resource:
name: memory
targetAverageUtilization: 80
效果如下: