3

1.背景

原来在使用kubernetes(v1.6.2)集群网络时,一直使用flannel,今天尝试使用calico(v2.5.1)三层网络路由模式进行部署安装。

2.安装

完全参考官网手工搭建模式(Integration Guide)即可正常安装,也可以选择官方推荐的hosted方式更加简洁。官方指南:
https://docs.projectcalico.or...

3.Troubleshooting

(1)kubelet配置
第一个小插曲是kubelet的配置问题:

--cni-bin-dir=/opt/cni/bin

官网说如果是v1.4.0以上版本,cni-conf-dir和cni-bin-dir参数已经not supported了,需要使用--network-plugin-dir=/etc/cni/net.d参数配置。但是实际部署时,发现如果不配置cni-bin-dir程序会报错:

Sep 25 12:28:42 datanode10 kubelet: E0925 12:28:42.979143  176648 remote_runtime.go:109] StopPodSandbox "d00d2e5c3579775ded32f9dc0099510b879c4facedafce462a7e07ce1700090f" from runtime service failed: rpc error: code = 2 desc = NetworkPlugin cni failed to teardown pod "kubernetes-dashboard-2445590520-xd1gv_kube-system" network: failed to find plugin "calico" in path [/etc/cni/net.d /opt/calico/bin]

kubernetes默认(可能是待研究)会查找/opt/calico/bin路径,配置好cni-bin-dir后不再报错啦。

(2)calico启动参数
calicoctl启动时的命令是:

calicoctl node run

比较有价值的参数是--node-image和--ip。第一次安装时安装官方文档指定了--node-image=quay.io/calico/node:v2.5.1,没有指定--ip,然后calico一直不能正常建立连接,使用calicoctl node diags查看日志/tmp/calico230225863/diagnostics/logs/bird/current(需要自行解压,在/tmp目录下):

2017-09-25_05:09:34.42961 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 37890)
2017-09-25_05:09:39.43958 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 51894)
2017-09-25_05:09:44.45164 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 33414)
2017-09-25_05:09:48.46058 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 57101)
2017-09-25_05:09:52.46944 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 46725)
2017-09-25_05:09:57.47937 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 55515)
2017-09-25_05:10:02.49236 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 40148)
2017-09-25_05:10:06.50045 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 44207)
2017-09-25_05:10:10.51034 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 56880)
2017-09-25_05:10:15.52110 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 33334)
2017-09-25_05:10:19.53213 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 41658)
2017-09-25_05:10:24.54219 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 38064)
2017-09-25_05:10:29.55189 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 60790)
2017-09-25_05:10:33.56258 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 50308)
2017-09-25_05:10:37.57183 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 38529)
2017-09-25_05:10:42.58203 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 52686)
2017-09-25_05:10:47.59242 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 38432)
2017-09-25_05:10:52.60446 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 36509)
2017-09-25_05:10:56.61362 bird: BGP: Unexpected connect from unknown address 10.1.8.103 (port 41643)

执行命令calicoctl node status后的状态是connect和active *#$%,不是正常的established。后来仔细看了命令的内容,PEER ADDRESS被默认指定到另一个ip上,果断添加--ip参数,完美解决。

[root@datanode10 ~]# calicoctl node status
Calico process is running.

IPv4 BGP status
+--------------+-------------------+-------+----------+-------------+
| PEER ADDRESS |     PEER TYPE     | STATE |  SINCE   |    INFO     |
+--------------+-------------------+-------+----------+-------------+
| 10.1.8.103   | node-to-node mesh | up    | 10:26:38 | Established |
+--------------+-------------------+-------+----------+-------------+

(3)ping不通
一切部署顺利完成,然后开始ping啦~ 但是发现一切都ping不通...不通... 那岂不是白安装calico了... 然后慢慢地抓包发现连本机都ping不通(容器ping宿主机),但是可以从veth pair抓到imcp的数据包。

接着查看ip forwarding也是正常配置,没有问题。

再接下来觉得可能是iptables的问题。果然... 在iptables中发现若干个DROP规则...一定是这里...

:KUBE-MARK-DROP - [0:0]
-A KUBE-MARK-DROP -j MARK --set-xmark 0x8000/0x8000
-A DOCKER-ISOLATION -i docker0 -o br-dcd8c151afdd -j DROP
-A DOCKER-ISOLATION -i br-dcd8c151afdd -o docker0 -j DROP
-A KUBE-FIREWALL -m comment --comment "kubernetes firewall for dropping marked packets" -m mark --mark 0x8000/0x8000 -j DROP
-A cali-from-wl-dispatch -m comment --comment "cali:0CzWdDTPLgBBz6Ll" -m comment --comment "Unknown interface" -j DROP
-A cali-fw-cali2feb0dad56a -m comment --comment "cali:A3N5_YNzOIpK7HpM" -m conntrack --ctstate INVALID -j DROP
-A cali-fw-cali2feb0dad56a -m comment --comment "cali:80T7Du_D0q6hU5kt" -m comment --comment "Drop if no profiles matched" -j DROP
-A cali-pri-k8s_ns.default -m comment --comment "cali:yVw1jR_AsGFo9Rpe" -j DROP
-A cali-pro-k8s_ns.default -m comment --comment "cali:YnsVE8VOF5QMzGPk" -j DROP
-A cali-to-wl-dispatch -m comment --comment "cali:qpABzRADIk3YxZik" -m comment --comment "Unknown interface" -j DROP
-A cali-tw-cali2feb0dad56a -m comment --comment "cali:MGvDdzDcopAPnoXN" -m conntrack --ctstate INVALID -j DROP
-A cali-tw-cali2feb0dad56a -m comment --comment "cali:WCfHewdVqzxx80YL" -m comment --comment "Drop if no profiles matched" -j DROP

删除calico的DROP规则后,跨主机的网络就可以正常通信了。但是,到这里还没有结束,正在思考为什么会有这些规则准备开放规则解决时,这些DROP又回来了,网络又不通了...

没关系继续查看calico的配置,此处还发现calicoctl完全模仿了kubectl的操作方式...更加方便啦~ 查看calico的各种状态,发现profile内容是空的,但是规则里有cali-pri-k8s_ns.default项(pri是profile inbound,pro是profile outbound),kubernetes和calico结合时没有自动配置上(不理解)。

# calicoctl get profile
NAME

查看calico workloadEndpoint信息证实节点是属于k8s_ns.default这个profile的。

- apiVersion: v1
  kind: workloadEndpoint
  metadata:
    activeInstanceID: e903eae04edbe9152d924c610121d62f02242c0791ec2e7d849975a2ea919922
    labels:
      calico/k8s_ns: default
    name: eth0
    node: datanode10
    orchestrator: k8s
    workload: default.nginx
  spec:
    interfaceName: calic440f455693
    ipNetworks:
    - 192.168.250.192/32
    mac: 22:4b:61:ee:e3:54
    profiles:
    - k8s_ns.default

没有就自己动手添加一个...规则全放开...然后就通了...

apiVersion: v1
kind: profile
metadata:
  name: k8s_ns.default
  labels:
    calico/k8s_ns: default
spec:
  ingress:
  - action: allow
  egress:
  - action: allow

4.小结

以上是今天安装部署时遇到的真实问题,暂时还不清楚是不是因为使用的不当导致的这些问题:(,后续会再学习calico的网络原理,研究一段calico的配置使用。


小神david
16 声望1 粉丝