> kubectl get service -n ingress-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ingress-nginx-controller LoadBalancer 10.102.19.97 192.168.2.10 80:31396/TCP,443:30578/TCP 39m ingress-nginx-controller-admission ClusterIP 10.106.187.197 <none> 443/TCP 39
> kubectl get pods -n ingress-nginx NAME READY STATUS RESTARTS AGE ingress-nginx-admission-create-67q5b 0/1 Completed 0 40m ingress-nginx-admission-patch-mnxk5 0/1 Completed 0 40m ingress-nginx-controller-b858dc8dd-qsr2g 1/1 Running 0 40m
> kubectl get services -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5d21h <none> test-k8s ClusterIP 10.108.251.159 <none> 80/TCP 170m app=test-k8s
在宿主主机上进行测试: curl 192.168.2.10
这里在我的MacBook上通过 arp -a 显示
1 2 3 4 5 6 7 8 9
arp -a ? (10.37.129.255) at ff:ff:ff:ff:ff:ff on bridge101 ifscope [bridge] ? (172.18.0.203) at 0:1c:42:4f:fe:16 on bridge100 ifscope [bridge] pandorabox.lan (192.168.1.1) at 64:9:80:5e:7b:2a on en5 ifscope [ethernet] ? (192.168.1.255) at ff:ff:ff:ff:ff:ff on en5 ifscope [ethernet] ? (192.168.2.104) at 0:1c:42:b0:f6:f8 on bridge100 ifscope [bridge] ? (192.168.2.10) at 0:1c:42:b0:f6:f8 on bridge100 ifscope [bridge] ? (192.168.2.255) at ff:ff:ff:ff:ff:ff on bridge100 ifscope [bridge] ? (224.0.0.251) at 1:0:5e:0:0:fb on en5 ifscope permanent [ethernet]
可以发现其中的 ? (192.168.2.10) at 0:1c:42:b0:f6:f8 on bridge100 ifscope [bridge] 实际上就是虚拟IP地址
249 upstream upstream_balancer { 250 ### Attention!!! 251 # 252 # We no longer create "upstream" section for every backend. 253 # Backends are handled dynamically using Lua. If you would like to debug 254 # and see what backends ingress-nginx has in its memory you can 255 # install our kubectl plugin https://kubernetes.github.io/ingress-nginx/kubectl-plugin. 256 # Once you have the plugin you can use "kubectl ingress-nginx backends" command to 257 # inspect current backends. 258 # 259 ### 260 261 server 0.0.0.1; # placeholder 262 263 balancer_by_lua_block { 264 balancer.balance() 265 } 266 267 keepalive 320; 268 269 keepalive_timeout 60s; 270 keepalive_requests 10000; 271 272 }