Cilium 官方文档翻译(11) BGP-结合BIRD运行BGP协议边界路由传播

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也是类似的。

安装 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场景如下:
![](https://img-blog.csdnimg.cn/img_convert/556744f59698e52447304f0b8499fb9f.png#clientId=u4fadd8d1-7686-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=ueb20208e&margin=[object Object]&originHeight=569&originWidth=484&originalType=url&ratio=1&rotation=0&showTitle=false&status=done&style=none&taskId=u54a36267-4aff-442b-84f6-4fd357db7e7&title=)

  • 物理网络: 简单的3层分词体系架构
  • 节点通过l2交换机连接物理网络
  • 每个节点通过bird向物理网络宣告PodCIDR
  • 节点不从物理网络导入路由宣告

这种设计下的BGP连接如下图所示:
![](https://img-blog.csdnimg.cn/img_convert/83171f7a1fc468a3e5cbdc0d358d4af2.png#clientId=u4fadd8d1-7686-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=u640a6f74&margin=[object Object]&originHeight=569&originWidth=484&originalType=url&ratio=1&rotation=0&showTitle=false&status=done&style=none&taskId=u315d9c2e-721b-4e9f-9037-d92b9231d24&title=)
这种方案简单在:

  • 核心路由器通过bird学习PodCIDR,使pod IP地址在全局网络中变得可路由。
  • bird不从核心路由器或其它节点学习路由,每个节点的内核路由表都保持足够小和清洁,不至于产生性能问题。

在该方案中,每个节点只向节点的默认网关(核心路由器)发送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 }}/<your node ip>/g'                /etc/bird.conf
sed -i 's/{{ POD_CIDR }}/<your pod cidr>/g'              /etc/bird.conf
sed -i 's/{{ NODE_ASN }}/<your node asn>/g'              /etc/bird.conf
sed -i 's/{{ NEIGHBOR_0_IP }}/<your neighbor 0 ip>/g'    /etc/bird.conf
sed -i 's/{{ NEIGHBOR_1_IP }}/<your neighbor 1 ip>/g'    /etc/bird.conf
sed -i 's/{{ NEIGHBOR_0_ASN }}/<your neighbor 0 asn>/g'  /etc/bird.conf
sed -i 's/{{ NEIGHBOR_1_ASN }}/<your neighbor 1 asn>/g'  /etc/bird.conf
sed -i 's/{{ NEIGHBOR_PWD }}/<your neighbor password>/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看起来像这样:
![](https://img-blog.csdnimg.cn/img_convert/f41837cb77e24ceefea75b50636be4a1.png#clientId=u4fadd8d1-7686-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=u59711597&margin=[object Object]&originHeight=588&originWidth=1885&originalType=url&ratio=1&rotation=0&showTitle=false&status=done&style=none&taskId=ubee7da36-05f7-4b74-9db3-f9ce71568ee&title=)

更多配置

您可能需要一些高级配置,以使BGP方案更好的生产就绪。本节列出了其中一些参数,但我们不会深入讨论细节,如需帮助请参考BIRD用户指南

BFD

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

ECMP

出于某些特殊需求(例如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]
'%<string>' in via output denotes VRF <string>

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;
}

参考资料

  1. 原文链接: https://docs.cilium.io/en/stable/gettingstarted/bird/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值