使用 kubeadm join 命令无法将新虚拟机连接到 K8S 集群

使用 kubeadm join 命令无法将新虚拟机连接到 K8S 集群

我的 K8s 集群由 1 个主节点和 2 个工作节点组成,运行良好,操作系统为 Rocky Linux。我添加了另一个相同操作系统的虚拟机,并安装了所有依赖项,例如 docker、containerd、kubelet、kubeadm、kubectl。它已正确安装。

在新虚拟机中,当我运行 kubeadm join 命令时,出现以下错误:

$ sudo kubeadm join <IP>:6443 --token <> --discovery-token-ca-cert-hash sha256:<> --v=5
I1030 12:03:59.363310   25914 join.go:412] [preflight] found NodeName empty; using OS hostname as NodeName
I1030 12:03:59.364950   25914 initconfiguration.go:117] detected and using CRI socket: unix:///var/run/containerd/containerd.sock
[preflight] Running pre-flight checks
I1030 12:03:59.365331   25914 preflight.go:93] [preflight] Running general checks
I1030 12:03:59.365492   25914 checks.go:280] validating the existence of file /etc/kubernetes/kubelet.conf
I1030 12:03:59.365580   25914 checks.go:280] validating the existence of file /etc/kubernetes/bootstrap-kubelet.conf
I1030 12:03:59.365695   25914 checks.go:104] validating the container runtime
I1030 12:03:59.420041   25914 checks.go:639] validating whether swap is enabled or not
I1030 12:03:59.420235   25914 checks.go:370] validating the presence of executable crictl
I1030 12:03:59.420284   25914 checks.go:370] validating the presence of executable conntrack
I1030 12:03:59.420402   25914 checks.go:370] validating the presence of executable ip
I1030 12:03:59.420493   25914 checks.go:370] validating the presence of executable iptables
I1030 12:03:59.420753   25914 checks.go:370] validating the presence of executable mount
I1030 12:03:59.420841   25914 checks.go:370] validating the presence of executable nsenter
I1030 12:03:59.420870   25914 checks.go:370] validating the presence of executable ebtables
I1030 12:03:59.420900   25914 checks.go:370] validating the presence of executable ethtool
I1030 12:03:59.420920   25914 checks.go:370] validating the presence of executable socat
I1030 12:03:59.420945   25914 checks.go:370] validating the presence of executable tc
I1030 12:03:59.420964   25914 checks.go:370] validating the presence of executable touch
I1030 12:03:59.420987   25914 checks.go:516] running all checks
I1030 12:03:59.433785   25914 checks.go:401] checking whether the given node name is valid and reachable using net.LookupHost
I1030 12:03:59.434080   25914 checks.go:605] validating kubelet version
I1030 12:03:59.501080   25914 checks.go:130] validating if the "kubelet" service is enabled and active
I1030 12:03:59.536842   25914 checks.go:203] validating availability of port 10250
I1030 12:03:59.538879   25914 checks.go:280] validating the existence of file /etc/kubernetes/pki/ca.crt
I1030 12:03:59.539290   25914 checks.go:430] validating if the connectivity type is via proxy or direct
I1030 12:03:59.539347   25914 checks.go:329] validating the contents of file /proc/sys/net/bridge/bridge-nf-call-iptables
I1030 12:03:59.539418   25914 checks.go:329] validating the contents of file /proc/sys/net/ipv4/ip_forward
I1030 12:03:59.539463   25914 join.go:529] [preflight] Discovering cluster-info
I1030 12:03:59.539494   25914 token.go:80] [discovery] Created cluster-info discovery client, requesting info from "<IP>:6443"
I1030 12:04:09.540512   25914 token.go:217] [discovery] Failed to request cluster-info, will try again: Get "https://10.150.0.3:6443/api/v1/namespaces/kube-public/configmaps/cluster-info?timeout=10s": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
I1030 12:04:25.143764   25914 token.go:217] [discovery] Failed to request cluster-info, will try again: Get "<IP>:6443/api/v1/namespaces/kube-public/configmaps/cluster-info?timeout=10s": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

我尝试从新 VM 使用 Telnet 访问主 k8s VM:它可以正常工作,防火墙已打开并且 kube-api-server 也在运行。

[4px@k8s-master ~]$ telnet <master ip> 6443
Trying <IP>...
Connected to <IP>.
Escape character is '^]'.
[4px@k8s-master ~]$ sudo netstat -tulpn | grep LISTEN | grep kube-apiserver
tcp6       0      0 :::6443                 :::*                    LISTEN      1982/kube-apiserver

我安装了 kubeadm、kubelet、kubectl:sudo dnf install kubelet kubeadm kubectl --disableexcludes=kubernetes具有 kubelet 和 kubeadm 的版本:1.27.7-150500.1.1.x86_64和 kubctl:kubectl-1.28.2-0.x86_64

安装后运行成功:sudo systemctl enable --now kubelet 启动 kubelet 后,其停止,日志:Kubelet 日志

● kubelet.service - Kubernetes Kubelet
     Loaded: loaded (/etc/systemd/system/kubelet.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/system/kubelet.service.d
             └─10-kubeadm.conf
     Active: activating (auto-restart) (Result: exit-code) since Mon 2023-10-30 12:36:39 UTC; 5ms ago
       Docs: https://github.com/kubernetes/kubernetes
    Process: 73832 ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS (code=exited, status=1/FAILURE)
   Main PID: 73832 (code=exited, status=1/FAILURE)
        CPU: 79ms

Oct 30 12:36:39 rnd-7 systemd[1]: kubelet.service: Main process exited, code=exited, status=1/FAILURE
Oct 30 12:36:39 rnd-7 systemd[1]: kubelet.service: Failed with result 'exit-code'.
journalctl -xeu kubelet
Oct 30 12:36:52 rnd-7 systemd[1]: Started Kubernetes Kubelet.
░░ Subject: A start job for unit kubelet.service has finished successfully
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ A start job for unit kubelet.service has finished successfully.
░░
░░ The job identifier is 900080.
Oct 30 12:36:52 rnd-7 kubelet[74147]: E1030 12:36:52.404538   74147 run.go:74] "command failed" err="failed to load kubelet config file, error: failed to load Kubelet >
Oct 30 12:36:52 rnd-7 systemd[1]: kubelet.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ An ExecStart= process belonging to unit kubelet.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Oct 30 12:36:52 rnd-7 systemd[1]: kubelet.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ The unit kubelet.service has entered the 'failed' state with result 'exit-code'.

相关内容