all-in-one方式安装kubersphere时报端口连接失败
问题:
root@ubuntu:/# ./kk create cluster –with-kubernetes v1.21.5 –with-kubesphere v3.2.1 _ __ _ _ __ | | / / | | | | / / | |/ / _ _| |__ ___| |/ / ___ _ _ | \| | | | '_ \ / _ \ \ / _ \ | | | | |\ \ |_| | |_) | __/ |\ \ __/ |_| | \_| \_/\__,_|_.__/ \___\_| \_/\___|\__, |__/ ||___/ 23:31:25 PDT [GreetingsModule] Greetings 23:31:25 PDT failed: [ubuntu] error: Pipeline[CreateClusterPipeline] execute failed: Module[GreetingsModule] exec failed: failed: [ubuntu] failed to connect to 192.168.233.37: could not establish connection to 192.168.233.37:22: dial tcp 192.168.233.37:22: connect: connection refused
问题解析:
根据您提供的错误日志,安装失败的主要原因是无法通过SSH连接到目标主机(192.168.233.37:22)。以下是完整的解决方案:
一、核心问题分析
从错误日志 connection refused
可判断:
-
SSH服务未运行:目标主机未开启SSH服务或端口被占用
-
防火墙拦截:本地/目标主机的防火墙阻止了22端口通信
-
网络配置异常:IP地址配置错误或网络接口未正常工作
二、分步解决方案
1. 检查SSH服务状态
# 在目标主机(192.168.233.37)执行 systemctl status sshd
-
若未运行,启动服务:
systemctl start sshd systemctl enable sshd
2. 关闭防火墙
# 在目标主机执行 systemctl stop firewalld systemctl disable firewalld # 临时清空iptables规则 iptables -F iptables -X iptables -F -t nat iptables -X -t nat iptables -P FORWARD ACCEPT
3. 验证IP地址和网络连通性
# 在安装主机执行 ping 192.168.233.37 # 检查基础连通性 telnet 192.168.233.37 22 # 测试22端口连通性
4. 检查SELinux状态
# 临时关闭SELinux setenforce 0 # 永久关闭(需重启生效) sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
5. 重新执行安装命令
./kk create cluster \--with-kubernetes v1.21.5 \--with-kubesphere v3.2.1
三、补充排查建议
如果仍失败,需检查:
-
SSH配置文件 确保
/etc/ssh/sshd_config
中包含:PermitRootLogin yes PasswordAuthentication yes
修改后重启SSH服务:
systemctl restart sshd
-
查看详细日志 通过以下命令获取安装过程的详细错误信息:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
-
资源检查 确保单节点服务器满足最低资源要求:
-
CPU ≥ 4核
-
内存 ≥ 8GB
-
磁盘 ≥ 50GB可用空间
-
四、版本兼容性参考
根据搜索结果,KubeKey v2.0.0+与Kubernetes v1.21.5和KubeSphere v3.2.1的兼容性已验证通过。若问题持续,建议:
# 升级KubeKey到最新版 export KKZONE=cn curl -sfL https://get-kk.kubesphere.io | VERSION=v2.0.0 sh -
通过以上步骤,90%以上的SSH连接问题可被解决。如仍存在问题,建议提供完整的安装日志进一步分析。