[英]Kubernetes: kubectl top nodes/pods not working
When I do kubectl top pods/nodes
I am getting the following error:当我执行
kubectl top pods/nodes
时,出现以下错误:
metrics not available yet
指标尚不可用
When I check the logs I am getting当我检查日志时,我得到
$ kubectl logs metrics-server-7df4c4484d-h75wr -n kube-system -c metrics-server
I1008 12:02:55.159069 1 serving.go:273] Generated self-signed cert(apiserver.local.config/certificates/apiserver.crt, apiserver.local.config/certificates/apiserver.key)
[restful] 2018/10/08 12:02:56 log.go:33: [restful/swagger] listing is available at https://:443/swaggerapi
[restful] 2018/10/08 12:02:56 log.go:33: [restful/swagger] https://:443/swaggerui/ is mapped to folder /swagger-ui/
I1008 12:02:56.358063 1 serve.go:96] Serving securely on [::]:443
E1008 12:03:04.225519 1 reststorage.go:101] unable to fetch node metrics for node "hpa-test": no metrics known for node "hpa-test"
E1008 12:03:07.619489 1 reststorage.go:101] unable to fetch node metrics for node "hpa-test": no metrics known for node "hpa-test"
Also, I am able to ping to hpa-test node from:此外,我可以从以下位置 ping 到 hpa-test 节点:
$ kubectl exec -it metrics-server-7df4c4484d-h75wr -n kube-system sh
Also, I have tried looking for solution everywhere but nothing fixed the issue另外,我尝试过到处寻找解决方案,但没有解决问题
There are two ways to fix this problem:有两种方法可以解决此问题:
1) using heapster : installing heapster will allow 'kubectl top nodes' to work out of the box. 1) 使用heapster :安装 heapster 将允许“kubectl top nodes”开箱即用。 However heapster has been deprecated, so you probably should switch to metrics-server.
但是 heapster 已被弃用,因此您可能应该切换到 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: 2) 使用metrics-server :不幸的是,在安装 metrics-server 时它可能无法开箱即用......如果没有,您需要更新 metrics-server-deployment.yaml (1.8+) 的末尾用于安装的文件并添加具有正确参数的命令部分,如下所示:
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
kubectl apply -f metrics-server-deployment.yaml
you should then be able to get results with然后你应该能够得到结果
kubectl top nodes
kubectl 顶级节点
and和
kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes"
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
These issue arises because you don't have metric server enabled in your cluster出现这些问题是因为您没有在集群中启用指标服务器
The top command will only be running if the metric server installed on your cluser只有在您的集群上安装了度量服务器时,top 命令才会运行
Download metric server in Kubernetes API from the git从 git 下载 Kubernetes API 中的度量服务器
Step:1 git clone https://github.com/kubernetes-incubator/metrics-server.git
步骤:1
git clone https://github.com/kubernetes-incubator/metrics-server.git
Step:2 cd metrics-server/
步骤:2
cd metrics-server/
Step:3 Deploy步骤:3部署
Kubernetes 1.7 kubectl create -f deploy/1.7/
Kubernetes 1.7
kubectl create -f deploy/1.7/
Kubernetes 1.8 Kubernetes 1.8
kubectl create -f deploy/1.8+/
Setp :4 Check status of metric server pod Setp :4检查指标服务器 pod 的状态
kubectl get po -n kube-system |grep metrics
Step5: Now your top command will be running步骤 5:现在您的 top 命令将运行
kubectl top pod --all-namespaces
Edit the deployment of metrics-server and add the following to arguments to its container.编辑 metrics-server 的部署并将以下内容添加到其容器的参数中。
--kubelet-insecure-tls
--kubelet-preferred-address-types=InternalIP
For example,例如,
kind: Deployment
metadata:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.