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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM