【问题标题】:Get metrics from pod with docker for mac使用 docker for mac 从 pod 获取指标
【发布时间】:2019-03-12 09:21:55
【问题描述】:

我尝试将Horizontal Pod Autosclaer 用于nginx pod。

当我描述我的 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

我使用 docker for mac。不知道会不会有影响

我的部署

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 配置metric-server 但不起作用

Scaling active 设置为 False。我认为这是问题,但我不知道如何改变价值

【问题讨论】:

    标签: kubernetes kubectl minikube docker-for-mac


    【解决方案1】:

    您好像缺少指标服务器。

    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

    【讨论】:

    • 感谢您的回复。我试过这个没有成功。当我描述我的 HPA 时,我有:ScalingActive False FailedGetResourceMetric HPA 无法计算副本计数:无法获取资源 cpu 的指标:无法获取 pod 资源指标:服务器找不到请求的资源(获取服务http:heapster:)
    • @M.Hol 您是否按照54106725 中提到的所有步骤进行操作。删除以前的指标服务器并再次删除和添加自动缩放器?
    • 当我使用 kubectl top pods 时,我得到了 CPU .. 但不是 HPA
    • @M.Hol The top command allows you to see the resource consumption for nodes or pods. 可以在kubectl-top man page上阅读
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多