使用Mac的docker从Pod获取指标

时间:2019-03-12 09:21:55

标签: kubernetes kubectl minikube docker-for-mac

我尝试将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。我认为这是问题所在,但我不知道如何改变价值

1 个答案:

答案 0 :(得分:0)

好像您缺少指标服务器。

  

Horizo​​ntalPodAutoscaler通常从一系列聚合的API(metrics.k8s.iocustom.metrics.k8s.ioexternal.metrics.k8s.io)中获取指标。 metrics.k8s.io API通常由metrics-server提供,需要单独启动。有关说明,请参见metrics-server。 Horizo​​ntalPodAutoscaler也可以直接从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