无法通过IP连接到kubernetes的服务

无法通过IP连接到kubernetes的服务

我按照 k8s 留言簿示例中的步骤进行操作(https://github.com/GoogleCloudPlatform/kubernetes/tree/master/examples/guestbook) 并且我对本例中描述的前端服务存在问题。

frontend-controller-182tv   10.148.3.4          ...  Running             4 minutes 
frontend-controller-i7hvs   10.148.4.3          ...  Running             4 minutes 
frontend-controller-zwk1b   10.148.1.4          ...  Running             4 minutes

服务内容如下:

frontend name=frontend name=frontend 10.151.244.58 8000

因此看起来不错,但实际上我无法连接到服务 IP 的 8000 端口(从 master 进行 telnet):

telnet 10.151.244.58 8000
Trying 10.151.244.58...

ifconfig 的输出:

cbr0      Link encap:Ethernet  HWaddr 12:1b:36:19:22:26
      inet addr:10.148.0.1  Bcast:0.0.0.0  Mask:255.255.255.0
      UP BROADCAST RUNNING MULTICAST  MTU:1460  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)

docker0   Link encap:Ethernet  HWaddr 56:84:7a:fe:97:99
      inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
      BROADCAST MULTICAST  MTU:1460  Metric:1
      RX packets:8 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:536 (536.0 B)  TX bytes:0 (0.0 B)

eth0      Link encap:Ethernet  HWaddr 42:01:0a:f0:f8:b7
      inet addr:10.240.248.183  Bcast:10.240.248.183  Mask:255.255.255.255
      UP BROADCAST RUNNING MULTICAST  MTU:1460  Metric:1
      RX packets:76763 errors:0 dropped:0 overruns:0 frame:0
      TX packets:48794 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:143685366 (137.0 MiB)  TX bytes:7641852 (7.2 MiB)

lo        Link encap:Local Loopback
      inet addr:127.0.0.1  Mask:255.0.0.0
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:250900 errors:0 dropped:0 overruns:0 frame:0
      TX packets:250900 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:98458614 (93.8 MiB)  TX bytes:98458614 (93.8 MiB)

不确定我的错误在哪里或者我还需要做什么......

答案1

其实我找到了答案https://stackoverflow.com/questions/27932594/can-my-vm-directly-access-services-in-the-google-container-engine

在我的例子中命令看起来像

gcloud 计算路由创建前端服务-1-1 --目标范围 10.151.244.0/24 --下一跳实例 k8s-k8s-tds-example-node-1 --下一跳实例区域 us-central1-c

看起来您必须为所有节点创建路由才能使其正常工作。

附言

此外,如果您在服务中使用“createExternalLoadBalancer”,请确保在云防火墙设置中允许从 0.0.0.0/0 到此端口的连接。

相关内容