Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics-server 新增hostNetwork: true #1418

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rgwrgw555
Copy link

今天,当我使用kubectl top nodes 来检查节点负载时,我得到了一个错误:"error: Metrics API not available."
我使用了kubectl logs -f -n kube-system metrics-server-xxxxxx 和 systemctl status kube-apiserver-Service -l 查看日志,发现有很多访问失败的记录。
起初我一直认为rbac设置不正确。
经过仔细研究,我们发现是metrics-server端口不可访问。kube-apiserver和metrics-server都会报告如下错误。
909 available_controller. go:460] v1beta1.metrics.k8s. io failed with: failing or missing response from https://172.20.196.137:4443/apis/metrics.k8s.io/v1beta1: Get "https://172.20.196.137:4443/apis/metrics.k8s. io/v1beta1": context deadline exceeded
最后,我修改metrics server启动YAML文件:deployment.spec.template.spec.hostNetwork: true
发现问题已经解决。

@gjmzj
Copy link
Collaborator

gjmzj commented Oct 31, 2024

你用的什么版本,刚刚我测试了下本来就没问题啊

root@k8s-192-168-0-80:/etc/kubeasz# kubectl get node
NAME               STATUS   ROLES    AGE   VERSION
k8s-192-168-0-80   Ready    master   11m   v1.31.2
root@k8s-192-168-0-80:/etc/kubeasz# kubectl top node
NAME               CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%
k8s-192-168-0-80   100m         2%     1129Mi          7%
root@k8s-192-168-0-80:/etc/kubeasz# kubectl top pod -A
NAMESPACE     NAME                                         CPU(cores)   MEMORY(bytes)
kube-system   calico-kube-controllers-555d448d69-zgjcj     2m           13Mi
kube-system   calico-node-pzv6w                            17m          120Mi
kube-system   coredns-cf95c9588-dj75p                      2m           13Mi
kube-system   dashboard-metrics-scraper-58cf467b87-dxw8n   1m           6Mi
kube-system   kubernetes-dashboard-5945846449-pgrsd        1m           9Mi
kube-system   metrics-server-7cdd8c6d78-qcct4              2m           18Mi
kube-system   node-local-dns-dxh7d                         3m           9Mi

@gjmzj
Copy link
Collaborator

gjmzj commented Oct 31, 2024

集群刚刚创建,这个命令确实没有数据的,等一会就会有

@rgwrgw555
Copy link
Author

     我的kubernetes已经创建了一个多月了,一直没有用kubectl top nodes 来查看pod使用情况。今天突然来查看才发现这个问题的。这个应该无关版本,因为从原理上来说的话,应该是说得通的。如果我们需要从metrics-server 获取数据,但是我们现在使用的是二进制安装,kube-apiserver不是安装在kubernetes里面,所以应该是无法访问到metrics-server,需要增加hostNetwork: true 。
   但是我也不能完全确认,因为我安装kubeasz的次数并不多,并且我也没有多余的资源来做实验。也不知道是不是我这边的原因,如果下次我再安装我会多注意这个地方的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants