k8s网络之calico

一、概述

前面我们部署calico由于集群规模不是很大,使用的是calico的bgp模式的node-to-node-mesh全节点互联,这种模式在小规模集群里面还可以用,3.4.0版本的calico支持到100多个节点。

但是随着集群规模的扩大,bgp的mesh会变得很混乱,因为node-to-node-mesh模式要求所有的node节点都要互联。所以大规模集群使用bgp route reflector,集中式的路由信息分发,当Calico BGP客户端将路由从其FIB通告到Route Reflector时,Route Reflector会将这些路由通告给部署集群中的其他节点。

 

二、部署

 

在官网下载最新的部署文件:https://docs.projectcalico.org/v3.4/getting-started/kubernetes/installation/calico

curl \
https://docs.projectcalico.org/v3.4/getting-started/kubernetes/installation/hosted/calico.yaml \
-O

需要修改几个地方具体参考:https://www.cnblogs.com/cuishuai/p/9897006.html

 

calico默认使用的是node-to-node-mesh,我们需要全局禁用这种模式,需要提前部署calicoctl。

参考:https://www.cnblogs.com/cuishuai/p/9897006.html、https://docs.projectcalico.org/v3.4/usage/calicoctl/install

参考:https://docs.projectcalico.org/v3.4/usage/configuration/bgp

1、禁用node-to-node-mesh

#cat off-node-mesh.yaml

apiVersion: projectcalico.org/v3
kind: BGPConfiguration
metadata:
  name: default
spec:
  logSeverityScreen: Info
  nodeToNodeMeshEnabled: false
  asNumber: 63400
calicoctl  apply -f  off-node-mesh.yaml

 

2、配置集群内路由反射器

# calicoctl get node
NAME
ku13-1
ku13-2
ku13-3
ku13-4

ku13-4是我们的kube-gateway,参考https://www.cnblogs.com/cuishuai/p/10310698.html

我们将这个节点作为bgp route reflector,建议选2-3个节点作为route reflector,这里我们就用这一个节点,前面已经知道这个节点上只部署了calico-node、kube-proxy,并且禁止调度。

 

1) 修改节点资源:

  • 将节点设置spec.bgp.routeReflectorClusterID为非空集群ID,例如 224.0.0.1

  • 添加一个标签,指示该节点是路由反射器

 

# calicoctl get node ku13-4  --export -o yaml  > node.yaml

 

ku13-4是要选择的节点名称,可以替换成任意的节点,这里我们选择kube-gateway节点。

修改为如下内容:

#cat node.yaml

apiVersion: projectcalico.org/v3
kind: Node
metadata:
  creationTimestamp: null
  labels:
    i-am-a-route-reflector: "true"
  name: ku13-4
spec:
  bgp:
    ipv4Address: 10.42.11.1/16
    routeReflectorClusterID: 224.0.0.1
  orchRefs:
  - nodeName: ku13-4
    orchestrator: k8s

 

使配置生效:

calicoctl apply -f node.yaml

 

2)配置BGPPeer资源,告诉其他Calico节点与路由反射器节点对等:

#cat bgp-calico.yaml

 

apiVersion: projectcalico.org/v3
kind: BGPPeer
metadata:
  name: peer-to-rrs
spec:
  nodeSelector: !has(i-am-a-route-reflector)
  peerSelector: has(i-am-a-route-reflector)

 

calicoctl  create -f bgp-calico.yaml

 

3)如果选择多个节点为route  reflector,还需要配置BGPPeer资源,告诉路由反射器节点互相对等:

#cat bgp-reflector.yaml

 

apiVersion: projectcalico.org/v3
kind: BGPPeer
metadata:
  name: rr-mesh
spec:
  nodeSelector: has(i-am-a-route-reflector)
  peerSelector: has(i-am-a-route-reflector)

 

calicoctl  create  -f  bgp-reflector.yaml 

 

 

 

 

 

https://www.cnblogs.com/cuishuai/p/9897006.html

posted @ 2019-01-24 16:28  诗码者  阅读(4927)  评论(0编辑  收藏  举报