1.问题
当node节点当node节点kubectl 命令无法连接到 Kubernetes API 服务器
[root@node1 ~]# kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?
2. 确认 kubeconfig 文件
确保节点上有有效的 kubeconfig 文件,并且 Kubernetes API 服务器的地址正确。你可以将 Master 节点上的 kubeconfig 文件复制到节点上:
scp /etc/kubernetes/admin.conf user@node2:/etc/kubernetes/admin.conf
3. 在节点上设置 KUBECONFIG 环境变量:
export KUBECONFIG=/etc/kubernetes/admin.conf
4. 重启kubelet服务
[root@node1 ~]# systemctl restart kubelet.service
[root@node1 ~]# systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: active (running) since Fri 2024-08-09 02:17:33 EDT; 1s ago
Docs: https://kubernetes.io/docs/
Main PID: 2519656 (kubelet)
Tasks: 23 (limit: 10654)
Memory: 67.2M
CGroup: /system.slice/kubelet.service
└─2519656 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --network-plugin=cni --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6
8月 09 02:17:34 node1 kubelet[2519656]: I0809 02:17:34.988241 2519656 reconciler.go:221] "operationExecutor.VerifyControllerAttachedVolume started for volume \"xtables-lock\" (UniqueName: \"kubernetes.io/host-path/36c16f24-07e9-45b0-96af-e44a9b30d3c5-xtables-lock\") pod \"kube-flannel-ds-7qlgm\" (UID: \"36c16f24-0>
8月 09 02:17:34 node1 kubelet[2519656]: I0809 02:17:34.988295 2519656 reconciler.go:221] "operationExecutor.VerifyControllerAttachedVolume started for volume \"kube-api-access-7bjrd\" (UniqueName: \"kubernetes.io/projected/36c16f24-07e9-45b0-96af-e44a9b30d3c5-kube-api-access-7bjrd\") pod \"kube-flannel-ds-7qlgm\" >
8月 09 02:17:34 node1 kubelet[2519656]: I0809 02:17:34.988337 2519656 reconciler.go:221] "operationExecutor.VerifyControllerAttachedVolume started for volume \"kube-proxy\" (UniqueName: \"kubernetes.io/configmap/0933f367-d6ca-498f-9d3e-48cdeb29845f-kube-proxy\") pod \"kube-proxy-44mr4\" (UID: \"0933f367-d6ca-498f->
8月 09 02:17:34 node1 kubelet[2519656]: I0809 02:17:34.988384 2519656 reconciler.go:221] "operationExecutor.VerifyControllerAttachedVolume started for volume \"xtables-lock\" (UniqueName: \"kubernetes.io/host-path/0933f367-d6ca-498f-9d3e-48cdeb29845f-xtables-lock\") pod \"kube-proxy-44mr4\" (UID: \"0933f367-d6ca-4>
8月 09 02:17:34 node1 kubelet[2519656]: I0809 02:17:34.988425 2519656 reconciler.go:221] "operationExecutor.VerifyControllerAttachedVolume started for volume \"lib-modules\" (UniqueName: \"kubernetes.io/host-path/0933f367-d6ca-498f-9d3e-48cdeb29845f-lib-modules\") pod \"kube-proxy-44mr4\" (UID: \"0933f367-d6ca-498>
8月 09 02:17:34 node1 kubelet[2519656]: I0809 02:17:34.988457 2519656 reconciler.go:221] "operationExecutor.VerifyControllerAttachedVolume started for volume \"run\" (UniqueName: \"kubernetes.io/host-path/36c16f24-07e9-45b0-96af-e44a9b30d3c5-run\") pod \"kube-flannel-ds-7qlgm\" (UID: \"36c16f24-07e9-45b0-96af-e44a>
8月 09 02:17:34 node1 kubelet[2519656]: I0809 02:17:34.988496 2519656 reconciler.go:221] "operationExecutor.VerifyControllerAttachedVolume started for volume \"cni\" (UniqueName: \"kubernetes.io/host-path/36c16f24-07e9-45b0-96af-e44a9b30d3c5-cni\") pod \"kube-flannel-ds-7qlgm\" (UID: \"36c16f24-07e9-45b0-96af-e44a>
8月 09 02:17:34 node1 kubelet[2519656]: I0809 02:17:34.988539 2519656 reconciler.go:221] "operationExecutor.VerifyControllerAttachedVolume started for volume \"kube-api-access-hnfqb\" (UniqueName: \"kubernetes.io/projected/0933f367-d6ca-498f-9d3e-48cdeb29845f-kube-api-access-hnfqb\") pod \"kube-proxy-44mr4\" (UID:>
8月 09 02:17:34 node1 kubelet[2519656]: I0809 02:17:34.988579 2519656 reconciler.go:221] "operationExecutor.VerifyControllerAttachedVolume started for volume \"cni-plugin\" (UniqueName: \"kubernetes.io/host-path/36c16f24-07e9-45b0-96af-e44a9b30d3c5-cni-plugin\") pod \"kube-flannel-ds-7qlgm\" (UID: \"36c16f24-07e9->
8月 09 02:17:34 node1 kubelet[2519656]: I0809 02:17:34.988604 2519656 reconciler.go:157] "Reconciler: start to sync state"
[root@node1 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready control-plane,master 3h36m v1.23.12
master2 Ready control-plane,master 3h34m v1.23.12
master3 Ready control-plane,master 3h27m v1.23.12
node1 Ready <none> 3h14m v1.23.12
node2 Ready <none> 3h15m v1.23.12
[root@node1 ~]#
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » 当node节点kubectl 命令无法连接到 Kubernetes API 服务器
发表评论 取消回复