kubectl top node cannot work, it shows: "error: You must be logged in to the server (Unauthorized)"

10/26/2018

I tried to demploy a k8s environment for ver1.12_rc.1. It includes one master and 2 nodes. All of them are CentOS Linux release 7.4.1708 (Core). The related info are follows:

[root@bogon174 dashboard]# kubectl get pods -n kube-system
NAME                                     READY   STATUS    RESTARTS   AGE
heapster-684777c4cb-fm6kd                1/1     Running   0          32m
kubernetes-dashboard-77fd78f978-khc4f    1/1     Running   0          32m
metrics-server-v0.3.1-6879897646-c7rwz   2/2     Running   0          37m
monitoring-grafana-56b668bccf-29277      1/1     Running   0          32m
monitoring-influxdb-5c5bf4949d-l8ttc     1/1     Running   0          32m

[root@bogon174 dashboard]# kubectl get services -n kube-system
NAME                   TYPE        CLUSTER-IP        EXTERNAL-IP   PORT(S)         AGE
heapster               ClusterIP   169.169.120.140   <none>        80/TCP          33m
kubernetes-dashboard   NodePort    169.169.151.109   <none>        443:26007/TCP   33m
metrics-server         NodePort    169.169.218.252   <none>        443:10521/TCP   38m
monitoring-grafana     ClusterIP   169.169.170.53    <none>        80/TCP          33m
monitoring-influxdb    ClusterIP   169.169.248.0     <none>        8086/TCP        33m

[root@bogon174 dashboard]# kubectl get nodes
NAME             STATUS     ROLES    AGE   VERSION
192.168.20.171   Ready      <none>   10d   v1.12.0-rc.1
192.168.20.172   NotReady   <none>   10d   v1.12.0-rc.1

enter image description here

I researched previous questions, but I cannot to get the correct solution.

-- eric_zhang
kubernetes

1 Answer

10/26/2018

Version 1.12 is no longer using heapster , and the top command is not yet ported to the new metrics system. There is a github issue for that , in order for the top to work with new metrics system.

Look at the options available , the only one is heapster but heapster is no more used.

[iahmad@web-prod-ijaz001 ~]$ kubectl top node --help
Display Resource (CPU/Memory/Storage) usage of nodes. 

The top-node command allows you to see the resource consumption of nodes.

Aliases:
node, nodes, no

Examples:
  # Show metrics for all nodes
  kubectl top node

  # Show metrics for a given node
  kubectl top node NODE_NAME

Options:
      --heapster-namespace='kube-system': Namespace Heapster service is located in
      --heapster-port='': Port name in service to use
      --heapster-scheme='http': Scheme (http or https) to connect to Heapster as
      --heapster-service='heapster': Name of Heapster service
  -l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)

Usage:
  kubectl top node [NAME | -l label] [options]
-- Ijaz Ahmad Khan
Source: StackOverflow