Kubernetes: kubectl top nodes/pods not working Kubernetes: kubectl top nodes/pods not working kubernetes kubernetes

Kubernetes: kubectl top nodes/pods not working


There are two ways to fix this problem:

1) using heapster :installing heapster will allow 'kubectl top nodes' to work out of the box. However heapster has been deprecated, so you probably should switch to metrics-server.

2) using metrics-server :unfortunately it may not work out of the box when installing metrics-server...in case it doesn't, you need to update the end of the metrics-server-deployment.yaml (1.8+) file you used for installation and add a command section with the right parameters as follow:

containers:- name: metrics-server  image: k8s.gcr.io/metrics-server-amd64:v0.3.1  imagePullPolicy: Always  volumeMounts:  - name: tmp-dir    mountPath: /tmp  command:      - /metrics-server      - --kubelet-insecure-tls      - --kubelet-preferred-address-types=InternalIP

then simply apply the changes:

kubectl apply -f metrics-server-deployment.yaml

you should then be able to get results with

kubectl top nodes

and

kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes"


Need add flags for metrics-sever:

--kubelet-insecure-tls=true--kubelet-port={YOU_KUBELET_PORT}--kubelet-preferred-address-types=InternalIP--v=5--logtostderr


Edit the deployment of metrics-server and add the following to arguments to its container.

--kubelet-insecure-tls--kubelet-preferred-address-types=InternalIP

For example,

kind: Deploymentmetadata:  name: metrics-server  ...spec:  template:    spec:      ...      containers:      - name: metrics-server        image: k8s.gcr.io/metrics-server-amd64:v0.3.6        args:          - --kubelet-insecure-tls          - --kubelet-preferred-address-types=InternalIP