11
votes

Kubernetes not able to find metric-server api.I am using Kubernetes with Docker on Mac. I was trying to do HPA from following example [https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/]. However, when I execute command kubectl get hpa, My target still was unknown. Then I tried, kubectl describe hpa. Which gave me error like below:

  Name:                                                  php-apache
  Namespace:                                             default
  Labels:                                                <none>
  Annotations:                                           <none>
  CreationTimestamp:                                     Sun, 07 Oct 2018 12:36:31 -0700
  Reference:                                             Deployment/php-apache
  Metrics:                                               ( current / target )
    resource cpu on pods  (as a percentage of request):  <unknown> / 5%
  Min replicas:                                          1
  Max replicas:                                          10
  Conditions:
    Type           Status  Reason                   Message
    ----           ------  ------                   -------
    AbleToScale    True    SucceededGetScale        the HPA controller was able to get the target's current scale
    ScalingActive  False   FailedGetResourceMetric  the HPA was unable to compute the replica count: unable to get metrics for resource cpu: no metrics returned from resource metrics API
  Events:
    Type     Reason                        Age               From                       Message
    ----     ------                        ----              ----                       -------
    Warning  FailedComputeMetricsReplicas  1h (x34 over 5h)  horizontal-pod-autoscaler  failed to get cpu utilization: unable to get metrics for resource cpu: no metrics returned from resource metrics API
    Warning  FailedGetResourceMetric       1m (x42 over 5h)  horizontal-pod-autoscaler  unable to get metrics for resource cpu: no metrics returned from resource metrics API

I am using [https://github.com/kubernetes-incubator/metrics-server] as suggested in Kubernetes documentation. I also tried doing same just using Minikube. But that also didn't work.

Running kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes outputs :

{
  "kind": "NodeMetricsList",
  "apiVersion": "metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes"
  },
  "items": []
}
6
Solved the problem using metrics-server and minikube. Still, it's an issue if using Kubernetes with Docker for MacVivek
Could you please describe your solution as an answer to this question? It might be helpful for other community members.VASャ
First I changed my context of Kubernetes to Minikube. Then I enabled metrics-server and disabled heapster in minikube. minikube addons disable metrics-server. minikube addons enable metrics-server. I found this (kubernetes.io/docs/tasks/configure-pod-container/…) resource helpful.Vivek

6 Answers

8
votes

Solution(if using Minikube):

Changed context of Kubernetes to Minikube.

Enabled metrics-server and Disabled heapster in minikube.

minikube addons disable heapster

minikube addons enable metrics-server

Deploy metrics-server in your cluster using the following steps:

git clone https://github.com/kubernetes-incubator/metrics-server.git

cd metrics-server

kubectl create -f deploy/1.7/ (if Kubernetes version 1.7)

OR

kubectl create -f deploy/1.8+/(if Kubernetes version 1.8+)

Start minikube dashboad and minikube service [your service].

Try kubectl top node.

I found this (https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/) resource helpful.

2
votes

I know this is a late answer, but I have had some issues with Docker Kubernetes and Autoscaler myself without finding a good answer on the internet. After many days of debugging, I found out that there were some connectivity issues with the metrics-server (couldn't connect to the pods).

I turned off TLS in metrics-server and it started working.. I answered my own post here if someone else is experiencing the same issue:

Docker Kubernetes (Mac) - Autoscaler unable to find metrics

1
votes

Use the below command in your cluster to setup Metrics Server:

kubectl apply -f https://raw.githubusercontent.com/pythianarora/total-practice/master/sample-kubernetes-code/metrics-server.yaml

This should work just fine.

I turned off TLS in metrics-server and it started working after so I updated the YAML and reposted.

1
votes

Run this command to create the metrics-server:

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.4.2/components.yaml

and then try this command again

kubectl top nodes

you can get the result:

NAME          CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
0
votes

When using minikube 1.4.0, there is no need to do anything else than minikube start: kubectl top node/pod should work out-of-the box.

0
votes

Make sure that you are using the latest metrics-server on your Kubernetes cluster. The below command helped me.

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

reference link: https://github.com/kubernetes-sigs/metrics-server