【问题标题】:kube-proxy in iptables mode is not working in routingiptables 模式下的 kube-proxy 在路由中不起作用
【发布时间】:2016-03-30 20:50:53
【问题描述】:

我拥有的是

  • Kubernetes:v.1.1.2
  • iptables v1.4.21
  • 内核:3.10.0-327.3.1.el7.x86_64 Centos
  • 网络是通过 flannel udp 完成的
  • 没有云提供商

我在做什么

我已使用 --proxy_mode=iptables 参数启用它。我检查了 iptables

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
KUBE-SERVICES  all  --  anywhere             anywhere             /* kubernetes service portals */
DOCKER     all  --  anywhere             anywhere             ADDRTYPE match dst-type LOCAL

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
KUBE-SERVICES  all  --  anywhere             anywhere             /* kubernetes service portals */
DOCKER     all  --  anywhere            !loopback/8           ADDRTYPE match dst-type LOCAL

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  SIDR26KUBEAPMORANGE-005/26  anywhere
MASQUERADE  all  --  172.17.0.0/16        anywhere
MASQUERADE  all  --  anywhere             anywhere             /* kubernetes service traffic requiring SNAT */ mark match 0x4d415351

Chain DOCKER (2 references)
target     prot opt source               destination

Chain KUBE-NODEPORTS (1 references)
target     prot opt source               destination

Chain KUBE-SEP-3SX6E5663KCZDTLC (1 references)
target     prot opt source               destination
MARK       all  --  172.20.10.130        anywhere             /* default/nc-service: */ MARK set 0x4d415351
DNAT       tcp  --  anywhere             anywhere             /* default/nc-service: */ tcp to:172.20.10.130:9000

Chain KUBE-SEP-Q4LJF4YJE6VUB3Y2 (1 references)
target     prot opt source               destination
MARK       all  --  SIDR26KUBEAPMORANGE-001.serviceengage.com  anywhere             /* default/kubernetes: */ MARK set 0x4d415351
DNAT       tcp  --  anywhere             anywhere             /* default/kubernetes: */ tcp to:10.62.66.254:9443

Chain KUBE-SERVICES (2 references)
target     prot opt source               destination
KUBE-SVC-6N4SJQIF3IX3FORG  tcp  --  anywhere             172.21.0.1           /* default/kubernetes: cluster IP */ tcp dpt:https
KUBE-SVC-362XK5X6TGXLXGID  tcp  --  anywhere             172.21.145.28        /* default/nc-service: cluster IP */ tcp dpt:commplex-main
KUBE-NODEPORTS  all  --  anywhere             anywhere             /* kubernetes service nodeports; NOTE: this must be the last rule in this chain */ ADDRTYPE match dst-type LOCAL

Chain KUBE-SVC-362XK5X6TGXLXGID (1 references)
target     prot opt source               destination
KUBE-SEP-3SX6E5663KCZDTLC  all  --  anywhere             anywhere             /* default/nc-service: */

Chain KUBE-SVC-6N4SJQIF3IX3FORG (1 references)
target     prot opt source               destination
KUBE-SEP-Q4LJF4YJE6VUB3Y2  all  --  anywhere             anywhere             /* default/kubernetes: */

当我从另一台机器向服务 ip 发出 nc 请求时,在我的情况下是 10.116.0.2 我收到如下错误 数控-v 172.21.145.28 5000 Ncat:版本 6.40 (http://nmap.org/ncat) 你好 Ncat:连接超时。

当我向 172.20.10.130:9000 服务器发出请求时,它工作正常。

nc -v 172.20.10.130 9000 Ncat:版本 6.40 (http://nmap.org/ncat) Ncat:连接到 172.20.10.130:9000。 你好 是的

从dmesg日志中可以看到

[10153.318195] DBG@OUTPUT: IN= OUT=eth0 SRC=10.62.66.223 DST=172.21.145.28 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=62466 DF PROTO=TCP SPT=59075 DPT=5000 WINDOW=29200 RES=0x00 SYN URGP=0
[10153.318282] DBG@OUTPUT: IN= OUT=eth0 SRC=10.62.66.223 DST=172.21.145.28 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=62466 DF PROTO=TCP SPT=59075 DPT=5000 WINDOW=29200 RES=0x00 SYN URGP=0
[10153.318374] DBG@POSTROUTING: IN= OUT=flannel0 SRC=10.62.66.223 DST=172.20.10.130 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=62466 DF PROTO=TCP SPT=59075 DPT=9000 WINDOW=29200 RES=0x00 SYN URGP=0

我发现我是否在运行 Pod 的机器上。我可以通过服务ip成功连接。

nc -v 172.21.145.28 5000
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Connected to 172.21.145.28:5000.
hello
yes

我想知道为什么以及如何解决它。

【问题讨论】:

  • 我还需要添加 --masquerade-all=true 吗?
  • 首先请尝试以下步骤来调试您的服务:github.com/kubernetes/kubernetes/blob/release-1.1/docs/…。然后注意 something 需要安装伪装规则。如果你告诉 Kubernetes 控制容器桥,它会这样做,但如果你在没有 --ip-masq 的情况下运行 flannel,这可能不会发生。完成此操作后,请回复调试服务文档中究竟出现了什么问题。

标签: proxy kubernetes


【解决方案1】:

我在 Kubernetes 1.1.7 和 1.2.0 上遇到了同样的问题。我在没有 --ip-masq 的情况下启动 flannel,并为 kube-proxy 添加参数 --masquerade-all=true,它会有所帮助。

【讨论】:

  • 这救了我,非常感谢。我什至没有想过看伪装!
【解决方案2】:

根据kube-proxy in iptables mode is not working,您可能需要添加一个路由,将您的服务 IP 路由到 docker 网桥。

【讨论】:

    猜你喜欢
    • 2016-03-04
    • 2019-02-28
    • 1970-01-01
    • 2015-05-22
    • 1970-01-01
    • 2019-07-21
    • 1970-01-01
    • 2016-12-28
    • 1970-01-01
    相关资源
    最近更新 更多