k8s版本(使用二进制安装):v1.15.7
点击查看代码
[root@k8s-master1 metrics-server]# kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.7", GitCommit:"6c143d35bb11d74970e7bc0b6c45b6bfdffc0bd4", GitTreeState:"clean", BuildDate:"2019-12-11T12:42:56Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.7", GitCommit:"6c143d35bb11d74970e7bc0b6c45b6bfdffc0bd4", GitTreeState:"clean", BuildDate:"2019-12-11T12:34:17Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
使用命令kubectl top node报错:
点击查看代码
[root@k8s-master1 metrics-server]# kubectl top node
Error from server (ServiceUnavailable): the server is currently unable to handle the request (get nodes.metrics.k8s.io)
查看 Kubernetes 集群中 v1beta1.metrics.k8s.io 这个 APIService 的详细信息:
点击查看代码
</details>
Name: v1beta1.metrics.k8s.io
Namespace:
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:{"apiVersion":"apiregistration.k8s.io/v1beta1","kind":"APIService","metadata":{"annotations":{},"name":"v1beta1.metrics.k8s.io"},"spec":{"...
API Version: apiregistration.k8s.io/v1
Kind: APIService
Metadata:Creation Timestamp: 2025-01-15T06:03:52ZResource Version: 495300447Self Link: /apis/apiregistration.k8s.io/v1/apiservices/v1beta1.metrics.k8s.ioUID: 70ed9328-3ae9-4907-a476-4197d079294a
Spec:Group: metrics.k8s.ioGroup Priority Minimum: 100Insecure Skip TLS Verify: trueService:Name: metrics-serverNamespace: kube-systemPort: 443Version: v1beta1Version Priority: 100
Status:Conditions:Last Transition Time: 2025-01-15T06:03:52Z**Message: failing or missing response from https://172.30.86.4:443/apis/metrics.k8s.io/v1beta1: Get https://172.30.86.4:443/apis/metrics.k8s.io/v1beta1: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)**Reason: FailedDiscoveryCheckStatus: FalseType: Available
Events: <none>
可以看到Message中访问metrics-server的service网络不通,原因是因为metrics-server的service的type为ClusterIP,该版本k8s使用二进制安装,master节点并未安装kubelet和kube-proxy导致
解决方法:
metrics-server配置文件中使用本机网络(deployment.spec.template.spec.hostNetwork: true),配置如下(新增加粗行):
点击查看代码
---
apiVersion: v1
kind: ServiceAccount
metadata:name: metrics-servernamespace: kube-system
---
apiVersion: apps/v1
kind: Deployment
metadata:name: metrics-servernamespace: kube-systemlabels:k8s-app: metrics-server
spec:selector:matchLabels:k8s-app: metrics-servertemplate:metadata:name: metrics-serverlabels:k8s-app: metrics-serverspec:** hostNetwork: true**serviceAccountName: metrics-servervolumes:# mount in tmp so we can safely use from-scratch images and/or read-only containers- name: tmp-diremptyDir: {}containers:- name: metrics-serverimage: registry:5000/metrics-server-amd64:v0.3.6imagePullPolicy: Alwaysargs:#- --cert-dir=/tmp#- --secure-port=4443- --kubelet-insecure-tls- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname- --v=6volumeMounts:- name: tmp-dirmountPath: /tmp