我最近开始尝试K3并想知道这一点。 您的笔记本电脑(主机)在容器中运行的专用网络具有一个桥接网络接口。 您的主机的IP在该专用网络上是
cni0
。
10.42.0.1
这些容器的每个容器都有一个名称空间和路由表,其默认网关到任何其他IP是您的主机:
$ ip addr show dev cni0
188: cni0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default qlen 1000
link/ether 06:d3:9b:0c:ee:be brd ff:ff:ff:ff:ff:ff
inet 10.42.0.1/24 brd 10.42.0.255 scope global cni0
valid_lft forever preferred_lft forever
inet6 fe80::4d3:9bff:fe0c:eebe/64 scope link
valid_lft forever preferred_lft forever
10.42.0.1
因此,您会发现流量将首先通过您的主机,然后在访问Internet的路上说,您的房屋路由器。
$ sudo ip -all netns exec route
...
netns: cni-bd52b5cc-b724-fd82-01c7-bcf0f0d97f49
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.42.0.1 0.0.0.0 UG 0 0 0 eth0
10.42.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.42.0.0 10.42.0.1 255.255.0.0 UG 0 0 0 eth0
services和Pods具有IP地址。
$ kubectl exec -it dnsutils -- traceroute google.com
traceroute to google.com (142.250.114.101), 30 hops max, 46 byte packets
1 10.42.0.1 (10.42.0.1) 0.017 ms 0.014 ms 0.013 ms
2 192.168.1.1 (192.168.1.1) 4.172 ms 1.658 ms 0.721 ms
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 syn-035-146-031-064.res.spectrum.com (35.146.31.64) 82.547 ms 94.083 ms 417.137 ms
9 lag-63.rcr01hstqtx02.netops.charter.com (24.164.209.122) 21.506 ms 523.018 ms 30.659 ms
10 syn-131-150-063-015.res.spectrum.com (131.150.63.15) 42.605 ms syn-024-093-037-083.inf.spectrum.com (24.93.37.83) 40.012 ms syn-131-150-063-015.res.spectrum.com (131.150.63.15) 39.808 ms
11 * * *
12 142.251.237.112 (142.251.237.112) 38.418 ms 72.14.237.46 (72.14.237.46) 45.226 ms 142.251.76.36 (142.251.76.36) 43.672 ms
13 108.170.233.119 (108.170.233.119) 28.496 ms 142.250.60.238 (142.250.60.238) 38.363 ms 108.170.228.91 (108.170.228.91) 28.948 ms
14 108.170.228.82 (108.170.228.82) 39.146 ms 108.170.233.119 (108.170.233.119) 80.752 ms 108.170.233.117 (108.170.233.117) 30.590 ms
15 142.251.76.47 (142.251.76.47) 39.273 ms 108.170.229.87 (108.170.229.87) 32.167 ms 142.250.233.171 (142.250.233.171) 34.306 ms
16 142.250.224.11 (142.250.224.11) 36.546 ms 216.239.43.144 (216.239.43.144) 32.527 ms 209.85.252.210 (209.85.252.210) 28.142 ms
17 142.250.224.27 (142.250.224.27) 40.756 ms 142.250.224.25 (142.250.224.25) 33.482 ms 142.250.224.13 (142.250.224.13) 32.428 ms
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 rr-in-f101.1e100.net (142.250.114.101) 30.500 ms * 36.067 ms