calicoctl 工具可以通过命令行读取、创建、更新和删除 Calico 的存储对象。
Calico 对象可以存储在 Etcd 服务或者 Kubernetes 服务中;在安装 Calico 的时候,需要选择其数据存储的位置。
在使用 calicoctl 管理工具时,你也可以选择工具部署的位置。
curl -O -L https://github.com/projectcalico/calicoctl/releases/download/v3.21.5/calicoctl-linux-amd64
mv calicoctl-linux-amd64 /usr/bin/calicoctl
chmod +x /usr/bin/calicoctl
官方提供了 calicoctl 的容器和 Kubernetes yaml 文件,我们可以直接使用:
#数据存储在 etcd 服务中,对应2.1
kubectl apply -f https://docs.projectcalico.org/manifests/calicoctl-etcd.yaml
#数据存储在 Kubernetes API datastore 服务中,对应2.2
kubectl apply -f https://docs.projectcalico.org/manifests/calicoctl.yaml
calicoctl 在使用过程中,需要从配置文件中读取 Calico 对象存储地址等信息。
以下2选1
calicoctl 客户端连接 Etcd 服务进行管理, 配置文件示例:
apiVersion: projectcalico.org/v3
kind: CalicoAPIConfig
metadata:
spec:
etcdEndpoints: https://etcd1:2379,https://etcd2:2379,https://etcd3:2379
etcdKeyFile: /etc/kubernetes/pki/etcd/server.key
etcdCertFile: /etc/kubernetes/pki/etcd/server.crt
etcdCACertFile: /etc/kubernetes/pki/etcd/ca.crt
calicoctl 客户端连接 Kubernetes 服务进行管理,配置文件示例:
apiVersion: projectcalico.org/v3
kind: CalicoAPIConfig
metadata:
spec:
datastoreType: "kubernetes"
kubeconfig: "/path/to/.kube/config"
这里有一个简单的命令用于验证 calicoctl 的安装和配置是否正确。
calicoctl node status
calicoctl get nodes
如果一切正常,则会返回已经注册的主机节点列表。
如果返回为空,则可能配置了错误的数据存储地址datastore或者 Calico 服务还没有主机注册。
如果返回错误信息,则请修复后重试。
安装quagga
yum install quagga telnet -y
拷贝配置文件:
cp /usr/share/doc/quagga-0.99.22.4/zebra.conf.sample /etc/quagga/zebra.conf
cp /usr/share/doc/quagga-*/bgpd.conf.sample /etc/quagga/bgpd.conf
编辑bgpd.conf文件:
router bgp 65186
bgp router-id 192.168.3.53
network 192.168.10.0
neighbor 192.168.3.81 remote-as 65186
neighbor 192.168.3.81 route-reflector-client
neighbor 192.168.3.82 remote-as 65186
neighbor 192.168.3.82 route-reflector-client
neighbor 192.168.3.83 remote-as 65186
neighbor 192.168.3.83 route-reflector-client
启动服务:
systemctl enable zebra --now
systemctl enable bgpd --now
进入路由器console:
cd /etc/quagga
vtysh
提示一下:
Hello, this is Quagga (version 0.99.22.4).
Copyright 1996-2005 Kunihiro Ishiguro, et al.
进入配置模式,配置端口地址并保存
docker01# conf t
docker01(config)#hostname bgp-RR
bgp-RR(config)#int eth0
bgp-RR(config-if)# ip add 192.168.3.53/24
bgp-RR(config-if)# no shutdown
bgp-RR(config-if)#end
bgp-RR#wr
创建2个yaml文件:
# cat calico1.yaml
apiVersion: projectcalico.org/v3
kind: BGPConfiguration
metadata:
name: default
spec:
logSeverityScreen: Info
nodeToNodeMeshEnabled: false
asNumber: 65186
cat calico2.yaml
apiVersion: projectcalico.org/v3
kind: BGPPeer
metadata:
name: bgppeer-global-211
spec:
peerIP: 192.168.3.53
asNumber: 65186
备注:k8s 19.0以上版本apiVersion需要更改为:crd.projectcalico.org/v1
应用:
calicoctl create -f calico1.yaml
calicoctl create -f calico2.yaml
路由器查看配置:
bgp-RR# show ip bgp summary
BGP router identifier 192.168.3.53, local AS number 65186
RIB entries 7, using 784 bytes of memory
Peers 3, using 13 KiB of memory
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.3.81 4 65186 6 11 0 0 0 00:03:41 1
192.168.3.82 4 65186 6 11 0 0 0 00:03:43 1
192.168.3.83 4 65186 6 11 0 0 0 00:03:41 1
Total number of neighbors 3
bgp-RR# show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP,
O - OSPF, I - IS-IS, B - BGP, A - Babel,
> - selected route, * - FIB route
K>* 0.0.0.0/0 via 192.168.3.1, eth0
B>* 10.255.30.0/26 [200/0] via 192.168.3.82, eth0, 00:03:47
B>* 10.255.91.128/26 [200/0] via 192.168.3.83, eth0, 00:03:45
B>* 10.255.126.192/26 [200/0] via 192.168.3.81, eth0, 00:03:45
C>* 127.0.0.0/8 is directly connected, lo
C>* 172.17.0.0/16 is directly connected, docker0
C>* 192.168.3.0/24 is directly connected, eth0
k8s master节点查看路由:
[root@k8s21-master01 ~]# ip route
default via 192.168.3.1 dev eth0 proto static metric 100
10.255.30.0/26 via 192.168.3.82 dev tunl0 proto bird onlink
10.255.91.128/26 via 192.168.3.83 dev tunl0 proto bird onlink
blackhole 10.255.126.192/26 proto bird
10.255.126.253 dev calic5f7b738d4b scope link
10.255.126.254 dev cali25736fd0fdb scope link
10.255.126.255 dev cali5344222d830 scope link
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
192.168.3.0/24 dev eth0 proto kernel scope link src 192.168.3.81 metric 100
192.168.10.0/24 via 192.168.3.53 dev eth0 proto bird
[root@k8s21-master01 ~]# calicoctl node status
Calico process is running.
IPv4 BGP status
+--------------+-----------+-------+----------+-------------+
| PEER ADDRESS | PEER TYPE | STATE | SINCE | INFO |
+--------------+-----------+-------+----------+-------------+
| 192.168.3.53 | global | up | 04:07:59 | Established |
+--------------+-----------+-------+----------+-------------+
IPv6 BGP status
No IPv6 peers found.
[root@k8s21-master01 ~]# calicoctl get bgpconfig default
NAME LOGSEVERITY MESHENABLED ASNUMBER
default Info false 65186