rootsongjc / kubernetes-handbook

Kubernetes中文指南/云原生应用架构实战手册
https://jimmysong.io/book/kubernetes-handbook
Creative Commons Attribution 4.0 International
11.11k stars 2.95k forks source link

externalIPs 具体是做啥用的? 设置后外部访问不到 #292

Closed hxzhao527 closed 5 years ago

hxzhao527 commented 6 years ago

环境

$ kubectl get node -o wide
NAME                STATUS    ROLES     AGE       VERSION   EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION               CONTAINER-RUNTIME
no.010.novalocal    Ready     master    28d       v1.10.0   <none>        CentOS Linux 7 (Core)   3.10.0-327.el7.x86_64        docker://1.12.6
no.011.novalocal    Ready     master    28d       v1.10.0   <none>        CentOS Linux 7 (Core)   3.10.0-862.11.6.el7.x86_64   docker://18.6.1
no.012.novalocal    Ready     master    28d       v1.10.0   <none>        CentOS Linux 7 (Core)   3.10.0-862.11.6.el7.x86_64   docker://18.6.1
node032-bjb-xfyun   Ready     <none>    5h        v1.10.0   <none>        Ubuntu 16.04.5 LTS      4.4.0-137-generic            docker://17.3.3
senhua103           Ready     <none>    19h       v1.10.0   <none>        Ubuntu 16.04.5 LTS      4.4.0-137-generic            docker://17.3.3
senhua104           Ready     <none>    47m       v1.10.0   <none>        Ubuntu 16.04.5 LTS      4.4.0-137-generic            docker://17.3.3
senhua103 172.21.161.103 # 跳转机登录使用ip地址
senhua104 172.21.161.104 # 跳转机登录使用ip地址

版本和配置信息

Server: Engine: Version: 18.06.1-ce API version: 1.38 (minimum version 1.12) Go version: go1.10.3 Git commit: e68fc7a Built: Tue Aug 21 17:25:29 2018 OS/Arch: linux/amd64 Experimental: false

node:
```sh
$ docker version
Client:
 Version:      17.03.3-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   e19b718
 Built:        Thu Aug 30 01:04:51 2018
 OS/Arch:      linux/amd64

Server:
 Version:      17.03.3-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   e19b718
 Built:        Thu Aug 30 01:04:51 2018
 OS/Arch:      linux/amd64
 Experimental: false

导致该问题的操作或现象 集群内机器执行:

$ curl --resolve a.com:80:172.21.161.103 -o - -I http://a.com
HTTP/1.1 200 OK
Server: nginx/1.15.3
Date: Tue, 09 Oct 2018 08:02:46 GMT
Content-Type: text/html
Content-Length: 1915
Connection: keep-alive
Vary: Accept-Encoding
Last-Modified: Sun, 30 Sep 2018 10:44:12 GMT
ETag: "5bb0a8fc-77b"
Expires: Wed, 10 Oct 2018 08:02:46 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes

跳转机执行:

$ curl --resolve a.com:80:172.21.161.103 -o - -I http://a.com
curl: (7) Failed connect to a.com:80; Connection timed out

日志

senhua103节点执行

$ netstat -ntulp | grep 80
tcp        0      0 127.0.0.1:10249         0.0.0.0:*               LISTEN      180051/kube-proxy
tcp        0      0 172.21.161.103:80       0.0.0.0:*               LISTEN      180051/kube-proxy
tcp        0      0 172.21.161.103:443      0.0.0.0:*               LISTEN      180051/kube-proxy
tcp6       0      0 :::10256                :::*                    LISTEN      180051/kube-proxy

通过tcpdump -i tunl0tcpdump -i enp26s0f0 # ip 172.21.161.103在这个网卡发现,103收到了跳转机的请求,并转给了k8s内nginx-controller-pod,但是经过tunl0的都是tcp握手包, tim 20181009161815

问题

  1. externalIPs 具体有啥用?
  2. 怎么配置nginx这种特殊服务配置公网出口才是合理的?
hxzhao527 commented 6 years ago

根据tcpdump-on-kubernetes-pod-using-calico-as-cni,使用tcpdump抓包。

hxzhao527 commented 6 years ago

将前面使用externalIPsnginx-svc删掉,在senhua103(172.21.161.103)机器上使用ipvsadm确认没有service后,通过apt install nginx部署了一个nginx并配置好(upstream 使用 a.com对应的service-clusterIP), 发现跳转机再次执行curl是通的,初步怀疑是nginx-ingress出了问题。

nginx-ingress 版本为: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.19.0

rootsongjc commented 6 years ago

这个Nginx Ingress Controller根据反馈貌似问题不少。

hxzhao527 commented 6 years ago

emmmm, 事实证明,自己前面怀疑错了,应该不是Nginx Ingress Controller的问题。


搜到 现象相似的 IPVS proxier doesn't handle nodes with iptables policy FORWARD DROPkube-proxy in ipvs mode doesn not correctly work with load balancer

手动执行了下 iptables -P FORWARD ACCEPT, 跳转机 curl 就成功了。

具体原因在前面两个链接里有提,不过我没有升级版本去测试,有兴趣的可以自己试下。

rootsongjc commented 6 years ago

还是你自己的跳转机的iptables设置问题咯?

hxzhao527 commented 6 years ago

还是你自己的跳转机的iptables设置问题咯?

不是,是在senhua103(172.21.161.103)机器上 执行的

iptables -P FORWARD ACCEPT