我尝试将Horizontal Pod Autosclaer
用于nginx
广告连播。
描述我的hpa时,我收到此消息horizontal-pod-autoscaler failed to get cpu utilization: unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource
我在Mac上使用 docker 。我不知道是否会产生影响
我的部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-app
spec:
selector:
matchLabels:
run: demo-app
replicas: 1
template:
metadata:
labels:
run: demo-app
spec:
containers:
- name: demo-app
image: my-demo-app:v3
imagePullPolicy: Never
resources:
requests:
cpu: 250m
limits:
cpu: 300m
ports:
- containerPort: 80
我的HPA
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: demo-app-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: demo-app
minReplicas: 1
maxReplicas: 3
targetCPUUtilizationPercentage: 3
kubectl get hpa 命令的输出:
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
demo-app-hpa Deployment/demo-app <unknown>/3% 1 3 1 20m
kubectl get --raw /apis/metrics.k8s.io/v1beta1
命令的输出
{"kind":"APIResourceList","apiVersion":"v1","groupVersion":"metrics.k8s.io/v1beta1","resources":[{"name":"nodes","singularName":"","namespaced":false,"kind":"NodeMetrics","verbs":["get","list"]},{"name":"pods","singularName":"","namespaced":true,"kind":"PodMetrics","verbs":["get","list"]}]}
我用this配置了度量服务器,但是不起作用
Scaling active
设置为False。我认为这是问题所在,但我不知道如何改变价值
答案 0 :(得分:0)
好像您缺少指标服务器。
HorizontalPodAutoscaler通常从一系列聚合的API(
metrics.k8s.io
,custom.metrics.k8s.io
和external.metrics.k8s.io
)中获取指标。metrics.k8s.io
API通常由metrics-server提供,需要单独启动。有关说明,请参见metrics-server。 HorizontalPodAutoscaler也可以直接从Heapster获取指标。
您可以检查kubectl get --raw /apis/metrics.k8s.io/v1beta1
是否部署了指标。
要安装metrics-server,只需克隆存储库并运行kubectl create -f deploy/1.8+/
如果您仍然遇到问题,建议您检查Docker Kubernetes (Mac) - Autoscaler unable to find metrics。