kubernetes API Server 没有 bind 0.0.0.0
今天早上改动态IP为静态IP,之前都是动态的,每次重启电脑IP虚拟机的IP就变了导致要修改master IP,所以改为静态的
切换到
cd /etc/sysconfig/network-scripts/
修改配置文件
ifcfg-ens160(当然这个文件每一个系统可能不一样),添加如下内容(为自己的ip,可以用ipconfig /all 或者ifconfig 查询下IP信息):
IPADDR="192.168.93.116" # 设置的静态IP地址
NETMASK="255.255.255.0" # 子网掩码
GATEWAY="192.168.93.255" # 网关地址
DNS1="192.168.93.1" # DNS服务器
修改完成之后,然后添加集群节点,就报错
15409 join.go:413] [preflight] found NodeName empty; using OS hostname as NodeName
I0903 04:12:18.403457 15409 join.go:417] [preflight] found advertiseAddress empty; using default interface's IP address as advertiseAddress
I0903 04:12:18.404096 15409 initconfiguration.go:117] detected and using CRI socket: unix:///var/run/containerd/containerd.sock
W0903 04:12:18.404239 15409 common.go:169] WARNING: could not obtain a bind address for the API Server: no default routes found in "/proc/net/route" or "/proc/net/ipv6_route"; using: 0.0.0.0
cannot use "0.0.0.0" as the bind address for the API Server
这个问题是由于没有正确添加网关造成的,route -n
Destination Gateway Genmask Flags Metric Ref Use Iface
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.93.0 0.0.0.0 255.255.255.0 U 100 0 0 ens160
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
因为我用的是虚拟机,用的是和主机一样的网络,所以ipconfig /all 查看所有的信息,找到了网关应该为192.168.93.1
修改网关地址为
GATEWAY="192.168.93.1" # 网关地址
重启。
重启之后发现多了一条路由。
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.93.1 0.0.0.0 UG 100 0 0 ens160
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.93.0 0.0.0.0 255.255.255.0 U 100 0 0 ens160
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
还有一种方式,直接添加路由:
估计执行如下命令也是可以的
route add default gw 192.168.93.1