BIRD是在Internet网络中路由数据包协议在类UNIX系统上的开源实现,它是一个守护进程。
BIRD BIRD Internet Routing Daemon。它是一个程序(一个守护进程),它在互联网类型的网络(即,运行IPv4或IPv6协议的网络)中充当动态路由器。路由器是在互连网络之间转发数据包的设备,以便允许未直接连接到同一局域网的主机相互通信。它们还与互联网中的其他路由器进行通信,以发现网络拓扑结构,从而允许它们找到用于转发数据包(称为路由表)的最佳(根据某些度量)规则,并适应不断变化的条件,如网络链路中断、建立新连接等。这些路由器大多是昂贵的专用设备,运行不透明的固件,难以配置,且不易更改(另一方面,其特殊的硬件设计使其能够跟接近线速在高速网络接口之间转发数据,比通用计算机更好)。UNIX系列的大多数操作系统允许普通计算机充当路由器并转发属于其他主机的数据包,但只能静态配置路由表。
BIRD提供了一种使用传统网络协议发布路由的方法,以允许在集群外部访问Cilium管理的结点。本文档假设Cilium已经部署在集群中,问题是如何确保集群pod CIDR范围在外部可路由可访问。
BIRD目前维护两个版本系列:1.x和2.x,它们之间的配置格式差异很大。除非您已经大量部署了1.x,否则建议直接使用2.x,因为2.x的维护周期更长。以下示例将bird表示为bird2软件,并以bird2理解的格式使用配置。
本文档介绍如何在CentOS 7.x上安装和配置bird,使其与Cilium协作。其他平台上的安装和配置bird也是类似的。
$ yum install -y bird2
$ systemctl enable bird
$ systemctl restart bird
验证安装:
$ birdc show route
BIRD 2.0.6 ready.
$ birdc # interactive shell
BIRD 2.0.6 ready.
bird> show bfd sessions
There is no BFD protocol running
bird>
bird> show protocols all
Name Proto Table State Since Info
device1 Device --- up 10:53:40.147
direct1 Direct --- down 10:53:40.147
Channel ipv4
State: DOWN
Input filter: ACCEPT
Output filter: REJECT
...
如果不考虑特定的BGP方案,很难讨论bird配置。然而,BGP方案设计超出了本指南的范围。如果您对此主题感兴趣,请参考数据中心的BGP(O'Reilly,2017)。
下面我们将限制BGP场景如下:
这种设计下的BGP连接如下图所示:
这种方案简单在:
在该方案中,每个节点只向节点的默认网关(核心路由器)发送pod出口流量,并让后者进行路由。
下面给出实现上述设计的参考配置:
$ cat /etc/bird.conf
log syslog all;
router id {{ NODE_IP }};
protocol device {
scan time 10; # Scan interfaces every 10 seconds
}
# Disable automatically generating direct routes to all network interfaces.
protocol direct {
disabled; # Disable by default
}
# Forbid synchronizing BIRD routing tables with the OS kernel.
protocol kernel {
ipv4 { # Connect protocol to IPv4 table by channel
import none; # Import to table, default is import all
export none; # Export to protocol. default is export none
};
}
# Static IPv4 routes.
protocol static {
ipv4;
route {{ POD_CIDR }} via "cilium_host";
}
# BGP peers
protocol bgp uplink0 {
description "BGP uplink 0";
local {{ NODE_IP }} as {{ NODE_ASN }};
neighbor {{ NEIGHBOR_0_IP }} as {{ NEIGHBOR_0_ASN }};
password {{ NEIGHBOR_PWD }};
ipv4 {
import filter {reject;};
export filter {accept;};
};
}
protocol bgp uplink1 {
description "BGP uplink 1";
local {{ NODE_IP }} as {{ NODE_ASN }};
neighbor {{ NEIGHBOR_1_IP }} as {{ NEIGHBOR_1_ASN }};
password {{ NEIGHBOR_PWD }};
ipv4 {
import filter {reject;};
export filter {accept;};
};
}
将上面的配置保存到文件/etc/bird.conf,并替换其中变量:
sed -i 's/{{ NODE_IP }}//g' /etc/bird.conf
sed -i 's/{{ POD_CIDR }}//g' /etc/bird.conf
sed -i 's/{{ NODE_ASN }}//g' /etc/bird.conf
sed -i 's/{{ NEIGHBOR_0_IP }}//g' /etc/bird.conf
sed -i 's/{{ NEIGHBOR_1_IP }}//g' /etc/bird.conf
sed -i 's/{{ NEIGHBOR_0_ASN }}//g' /etc/bird.conf
sed -i 's/{{ NEIGHBOR_1_ASN }}//g' /etc/bird.conf
sed -i 's/{{ NEIGHBOR_PWD }}//g' /etc/bird.conf
重启bird并检查日志:
$ systemctl restart bird
# check logs
$ journalctl -u bird
-- Logs begin at Sat 2020-02-22 16:11:44 CST, end at Mon 2020-02-24 18:58:35 CST. --
Feb 24 18:58:24 node systemd[1]: Started BIRD Internet Routing Daemon.
Feb 24 18:58:24 node systemd[1]: Starting BIRD Internet Routing Daemon...
Feb 24 18:58:24 node bird[137410]: Started
验证变更,你应该得到类似下面的日志:
$ birdc show route
BIRD 2.0.6 ready.
Table master4:
10.5.48.0/24 unicast [static1 20:14:51.478] * (200)
dev cilium_host
这说明了节点上的PodCIDR 10.5.48.0/24已经成功导入到BIRD。
$ birdc show protocols all uplink0 | grep -A 3 -e "Description" -e "stats"
Description: BGP uplink 0
BGP state: Established
Neighbor address: 10.4.1.7
Neighbor AS: 65418
--
Route change stats: received rejected filtered ignored accepted
Import updates: 0 0 0 0 0
Import withdraws: 10 0 --- 10 0
Export updates: 1 0 0 --- 1
在这里,我们看到上行链路0 BGP会话已建立,我们的PodCIDR已从上面导出并被BGP对等方接受。
bird_exporter收集bird 守护进程指标,并导出为prometheus格式的度量指标。
它还提供了一个简单的Grafana仪表板,但您也可以创建自己的仪表板,例如Trip.com看起来像这样:
您可能需要一些高级配置,以使BGP方案更好的生产就绪。本节列出了其中一些参数,但我们不会深入讨论细节,如需帮助请参考BIRD用户指南。
Bidirectional Forwarding Detection (BFD) 双向转发检测是一种用于加速路径故障检测的检测协议。该特性需要在双端都做以下配置:
protocol bfd {
interface "{{ grains['node_mgnt_device'] }}" {
min rx interval 100 ms;
min tx interval 100 ms;
idle tx interval 300 ms;
multiplier 10;
password {{ NEIGHBOR_PWD }};
};
neighbor {{ NEIGHBOR_0_IP] }};
neighbor {{ NEIGHBOR_1_IP] }};
}
protocol bgp uplink0 {
...
bfd on;
}
通过以下日志验证是否配置成功:
$ birdc show bfd sessions
BIRD 2.0.6 ready.
bfd1:
IP address Interface State Since Interval Timeout
10.5.40.2 bond0 Up 20:14:51.479 0.300 0.000
10.5.40.3 bond0 Up 20:14:51.479 0.300 0.000
出于某些特殊需求(例如L4LB),您可以在多个节点上配置相同的CIDR。在这种情况下,您需要配置 Equal-Cost Multi-Path (ECMP)等成本多路径路由。该功能也需要在双端都做配置:
protocol kernel {
ipv4 { # Connect protocol to IPv4 table by channel
import none; # Import to table, default is import all
export none; # Export to protocol. default is export none
};
# Configure ECMP
merge paths yes limit {{ N }} ;
}
您需要检查物理网络上的ECMP正确性(上述场景中的核心路由器):
CORE01# show ip route 10.5.2.0
IP Route Table for VRF "default"
'*' denotes best ucast next-hop
'**' denotes best mcast next-hop
'[x/y]' denotes [preference/metric]
'%' in via output denotes VRF
10.5.2.0/24, ubest/mbest: 2/0
*via 10.4.1.7, [200/0], 13w6d, bgp-65418, internal, tag 65418
*via 10.4.1.8, [200/0], 12w4d, bgp-65418, internal, tag 65418
该功能也需要在每个bird节点上配置。
protocol bgp uplink0 {
...
graceful restart;
}
留言与评论(共有 0 条评论) “” |