k8s指定外部ip暴露端口访问不通问题解决

k8s通过svc暴露端口

  跟着katacoda k8s教程走,自己换了一个external-ip发现访问不了,通过ifconfig查  
看,教程中的172.17.0.58,是一个配置好的网卡ip,但自己随意自定的没有网卡配置。之
所以随意指定ip,是感觉k8s划分的172.17的ip段,以为可以用,但这个ip段应该是k8s  
集群pod内使用的,而要暴露的ip应该是集群pod外,不经经过pause处理是发现不了的,
故可以通过ifconfig配置虚拟网卡,解决问题;或者通过容器解决?需要尝试。
  • 无法访问
$ curl 172.17.0.35:8000
curl: (7) Failed to connect to 172.17.0.35 port 8000: No route to host
$
  • 查看网卡
$ ifconfig
docker0   Link encap:Ethernet  HWaddr 02:42:fc:91:8d:32
          inet addr:172.18.0.1  Bcast:0.0.0.0  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ens3      Link encap:Ethernet  HWaddr 02:42:ac:11:00:43
          inet addr:172.17.0.67  Bcast:172.17.255.255  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:43/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1491 errors:0 dropped:0 overruns:0 frame:0
          TX packets:969 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:109810 (109.8 KB)  TX bytes:84330 (84.3 KB)
...
  • 配置虚拟网卡

$ ifconfig ens3:cka 172.17.0.35 up
$ ifconfig
docker0   Link encap:Ethernet  HWaddr 02:42:fc:91:8d:32
          inet addr:172.18.0.1  Bcast:0.0.0.0  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ens3      Link encap:Ethernet  HWaddr 02:42:ac:11:00:43
          inet addr:172.17.0.67  Bcast:172.17.255.255  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:43/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1594 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1025 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:118304 (118.3 KB)  TX bytes:91426 (91.4 KB)

ens3:cka  Link encap:Ethernet  HWaddr 02:42:ac:11:00:43
          inet addr:172.17.0.35  Bcast:172.17.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

  • 再次访问svc

你可能感兴趣的:(云计算/大数据,kubernetes)