Metrics

https://medium.com/@cagri.ersen/kubernetes-metrics-server-installation-d93380de008

$ kubectl get apiservices |egrep metrics
v1beta1.metrics.k8s.io                 kube-system/metrics-server   True        1h
$ kubectl get deploy,svc -n kube-system
NAME                                                          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.extensions/coredns                                 2         2         2            2           79d
deployment.extensions/eks-autoscaler-aws-cluster-autoscaler   1         1         1            1           79d
deployment.extensions/metrics-server                          1         1         1            1           117m
deployment.extensions/tiller-deploy                           1         1         1            1           79d

NAME                                            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)         AGE
service/eks-autoscaler-aws-cluster-autoscaler   ClusterIP   172.20.2.211     <none>        8085/TCP        79d
service/kube-dns                                ClusterIP   172.20.0.10      <none>        53/UDP,53/TCP   79d
service/metrics-server                          ClusterIP   172.20.154.226   <none>        443/TCP         117m
service/tiller-deploy                           ClusterIP   172.20.52.34     <none>        44134/TCP       79d
$ kubectl top node
NAME                                          CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%
ip-10-158-53-105.us-west-2.compute.internal   145m         3%     3088Mi          19%
ip-10-158-53-22.us-west-2.compute.internal    129m         3%     3497Mi          22%
$ kubectl get --raw "/apis/metrics.k8s.io" | jq .
{
  "kind": "APIGroup",
  "apiVersion": "v1",
  "name": "metrics.k8s.io",
  "versions": [
    {
      "groupVersion": "metrics.k8s.io/v1beta1",
      "version": "v1beta1"
    }
  ],
  "preferredVersion": {
    "groupVersion": "metrics.k8s.io/v1beta1",
    "version": "v1beta1"
  }
}

$ kubectl get --raw "/apis/metrics.k8s.io/v1beta1" | jq .
{
  "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"
      ]
    }
  ]
}

$ kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes" |jq .
{
  "kind": "NodeMetricsList",
  "apiVersion": "metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes"
  },
  "items": [
    {
      "metadata": {
        "name": "ip-10-158-53-22.us-west-2.compute.internal",
        "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes/ip-10-158-53-22.us-west-2.compute.internal",
        "creationTimestamp": "2019-06-16T22:22:48Z"
      },
      "timestamp": "2019-06-16T22:22:09Z",
      "window": "30s",
      "usage": {
        "cpu": "128506930n",
        "memory": "3580948Ki"
      }
    },
    {
      "metadata": {
        "name": "ip-10-158-53-105.us-west-2.compute.internal",
        "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes/ip-10-158-53-105.us-west-2.compute.internal",
        "creationTimestamp": "2019-06-16T22:22:48Z"
      },
      "timestamp": "2019-06-16T22:22:07Z",
      "window": "30s",
      "usage": {
        "cpu": "144727026n",
        "memory": "3162612Ki"
      }
    }
  ]
}
$ kubectl get --raw "/apis/metrics.k8s.io/v1beta1/pods" | jq .
{
  "kind": "PodMetricsList",
  "apiVersion": "metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/metrics.k8s.io/v1beta1/pods"
  },
  "items": [
    {
      "metadata": {
        "name": "rstudio-deployment-jeevandk-e414a8-5dcd8dd45b-vksml",
        "namespace": "rstudio",
        "selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/rstudio/pods/rstudio-deployment-jeevandk-e414a8-5dcd8dd45b-vksml",
        "creationTimestamp": "2019-06-16T22:26:42Z"
      },
      "timestamp": "2019-06-16T22:26:08Z",
      "window": "30s",
      "containers": [
        {
          "name": "rstudio-jeevandk-e414a8",
          "usage": {
            "cpu": "735846n",
            "memory": "92960Ki"
          }
        }
      ]
    },
    {
      "metadata": {
        "name": "prometheus-cluster-monitoring-0",
        "namespace": "cattle-prometheus",
        "selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/cattle-prometheus/pods/prometheus-cluster-monitoring-0",
        "creationTimestamp": "2019-06-16T22:26:42Z"
      },
      "timestamp": "2019-06-16T22:25:56Z",
      "window": "30s",
      "containers": [
        {
          "name": "prometheus-agent",
          "usage": {
            "cpu": "579514n",
            "memory": "14732Ki"
          }
        },
        {
          "name": "rules-configmap-reloader",
          "usage": {
            "cpu": "32015n",
            "memory": "1780Ki"
          }
        },
        {
          "name": "prometheus-proxy",
          "usage": {
            "cpu": "2835n",
            "memory": "5688Ki"
          }
        },
        {
          "name": "prometheus",
          "usage": {
            "cpu": "9060978n",
            "memory": "438920Ki"
          }
        },
        {
          "name": "prometheus-config-reloader",
          "usage": {
            "cpu": "0",
            "memory": "3556Ki"
          }
        }
      ]
    }
    ```

!!! Troubleshooting
If kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes" command returns empty response and metrics-server pod throw an error like
E0903 1 manager.go:102] unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:: unable to fetch metrics from Kubelet (): Get https:// :10250/stats/summary/: dial tcp: lookup on 10.96.0.10:53: no such host
To fix the issue, you need to edit metrics-server-deployment.yaml and add the parameters below right after image: k8s.gcr.io/metrics-server-amd64:v0.3.1 line:
command: - /metrics-server - --kubelet-insecure-tls - --kubelet-preferred-address-types=InternalIP `` then re-apply it askubectl apply -f metrics-server-deployment.yaml`

After few seconds, you can get metrics via kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes" or kubectl top node commands.