FabEdge项目简介:
FabEdge是博云在2021年8月发起,基于Kubernetes 构建的专注于边缘计算场景的容器网络方案,支持 KubeEdge 、SuperEdge、OpenYurt 等主流边缘计算框架。旨在解决边缘计算场景下容器网络配置管理复杂、网络割裂互不通信、缺少拓扑感知能力、无法提供就近访问等问题,适用于物联网,车联网、智慧城市、智慧园区等多种边缘场景。
此后产品不断迭代,在2022年3月8日,博云正式将FabEdge捐献给CNCF社区,并通过相关评定,成为 CNCF 沙箱中首个边缘容器网络项目。目前FabEdge社区已有200多位开发者。
FabEdge最近正式发布了 V0.8.0 版本,该版本增强了边缘侧的服务访问能力,改善了边缘节点的连通性。
边缘侧服务访问能力增强
这次更新主要是改善KubeEdge集群边缘侧的服务访问能力,因为默认情况下KubeEdge集群不会有kube-proxy运行,也不能访问coredns。
FabEdge以前内部实现了一个fab-proxy来实现服务代理,并在边缘侧使用nodelocaldns提供服务域名解析,但是fab-proxy能力有限,且不能及时响应服务信息变更,nodelocaldns的也不适合边缘场景,为了解决以上问题,FabEdge此次更新将kube-proxy和coredns整合至fabedge-agent内,并利用edgecore的metaServer组件向fabedge-agent内的kube-proxy和coredns组件提供数据,从而为边缘节点上运行的容器提供了服务域名解析能力和服务代理。
允许配置connector节点的公开端口
FabEdge v0.8.0添加了connector公开端⼝配置的能⼒。之前FabEdge利用strongswan来创建VPN隧道实现云边通信,strongswan默认的端口为500和4500,connector节点的strongswan占用的端口通常需要做公网端口映射,映射出来的端口很可能不是500和4500,这样限制了FabEdge的使用场景。
这次更新之后,用户可以直接设置connector节点的公开端口,让strongswan可以通过非500和非4500端口建立隧道。但边缘侧暂时不能也没有必要进行端口配置,边缘侧的此类问题可以通过打洞(本次也有更新)功能来解决。
示例
配置connector节点公开端口
环境信息
* kubernetes v1.22.5
* kubeedge v1.12.2
* flannel v0.19.2
* fabedge v0.8.0
kubernetes集群节点信息如下:
其中beijing节点要作为connector节点,它和node1位于同一个局域网,edge1、 edge2位于另一个局域网。
想让边缘侧访问云端,需要为beijing节点做端口映射,这里我们选择将4500 映射为45000。
具体的映射方法需要读者根据环境调整,本文的beijing节点使用vagrant创建的,其实际映射配置为:
```ruby
# stongswan的通信端口,注意这里的协议为UDP
config.vm.network "forwarded_port", guest: 4500, host: 45000, protocol: "udp"
```
笔者开发时也会因为环境限制偶尔使用iptables来实现端口映射,具体规则为:
```shell
$ iptables -t nat -A PREROUTING -p udp --dport 45000 -j REDIRECT --to-ports 4500
```
这里再强调一次,使用strongswan的客户端使用非500端口进行IKE及通信时,服务端的实际目标端口为4500。
安装FabEdge
本文采用quickstart.sh脚本来安装,重点介绍一些参数配置,具体的安装文档参考[快速安装](https://github.com/FabEdge/fabedge/blob/main/docs/get-started_zh.md)。
1. 用helm添加fabedge repo:
```shell
$ helm repo add fabedge https://fabedge.github.io/helm-chart
```
2. 执行安装命令:
```shell
$ curl https://fabedge.github.io/helm-chart/scripts/quickstart.sh | bash -s -- \
--cluster-name beijing \
--cluster-role host \
--cluster-zone beijing \
--cluster-region beijing \
--connectors beijing \
--edges edge1,edge2 \
--connector-public-addresses 10.40.20.181 \
--connector-public-port 45000 \
--chart fabedge/fabedge
```
注意,上面的**connector-public-addresses**参数没有配置为beijing节点的内网地址192.168.56.11 ,而是beijing节点对外的地址**10.40.20.181**,端口也是我们之前映射的**45000**端口。
如果您选择手动安装FabEdge, 相应的配置可以参考以下内容:
```yaml
cluster:
name: beijing
role: host
region: beijing
zone: beijing
cniType: "flannel"
connectorPublicPort: 45000
connectorPublicAddresses:
- 10.22.45.16
clusterCIDR:
- 10.233.64.0/18
serviceClusterIPRange:
- 10.233.0.0/18
agent:
args:
以下两个参数仅需要在kubeedge环境打开
ENABLE_PROXY: "true"
ENABLE_DNS: "true"
```
验证
来检查一下edge1, edge2跟connector创建的隧道信息:
```shell
$ fabctl swanctl list-sa edge1
========================== fabedge-agent-xfntz =================================
beijing.connector: #2, ESTABLISHED, IKEv2, aedd33719dd60b73_i* 1290e9570d67a570_r
local 'C=CN, O=fabedge.io, CN=beijing.edge1' @ 10.22.46.30[4500]
remote 'C=CN, O=fabedge.io, CN=beijing.connector' @ 10.40.20.181[45000]
AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/CURVE_25519
established 2682s ago, rekeying in 10461s
beijing.connector-p2p: #1, reqid 1, INSTALLED, TUNNEL-in-UDP, ESP:AES_GCM_16-128
installed 2682s ago, rekeying in 599s, expires in 1279s
in c056eddc, 0 bytes, 0 packets
out cba5947a, 0 bytes, 0 packets
local 10.233.66.0/24
remote 10.233.0.0/18 10.233.64.0/24 10.233.65.0/24
beijing.connector-p2n: #2, reqid 2, INSTALLED, TUNNEL-in-UDP, ESP:AES_GCM_16-128
installed 2681s ago, rekeying in 583s, expires in 1279s
in c60aff0c, 0 bytes, 0 packets
out cc298e3f, 0 bytes, 0 packets
local 10.233.66.0/24
remote 192.168.56.11/32 192.168.56.12/32
beijing.connector-n2p: #3, reqid 3, INSTALLED, TUNNEL-in-UDP, ESP:AES_GCM_16-128
installed 2681s ago, rekeying in 663s, expires in 1279s
in cc583570, 0 bytes, 0 packets
out c6a00d2f, 0 bytes, 0 packets
local 10.22.46.30/32
remote 10.233.0.0/18 10.233.64.0/24 10.233.65.0/24
$ fabctl swanctl list-sa edge2
========================== fabedge-agent-gb5qd =================================
beijing.connector: #1, ESTABLISHED, IKEv2, 68cc6b323a3d9fe1_i* a572ff308882d651_r
local 'C=CN, O=fabedge.io, CN=beijing.edge2' @ 10.22.46.28[4500]
remote 'C=CN, O=fabedge.io, CN=beijing.connector' @ 10.40.20.181[45000]
AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/CURVE_25519
established 2683s ago, rekeying in 10862s
beijing.connector-p2p: #1, reqid 1, INSTALLED, TUNNEL-in-UDP, ESP:AES_GCM_16-128
installed 2683s ago, rekeying in 625s, expires in 1277s
in c801df3f, 0 bytes, 0 packets
out cea754ac, 0 bytes, 0 packets
local 10.233.67.0/24
remote 10.233.0.0/18 10.233.64.0/24 10.233.65.0/24
beijing.connector-p2n: #2, reqid 2, INSTALLED, TUNNEL-in-UDP, ESP:AES_GCM_16-128
installed 2683s ago, rekeying in 655s, expires in 1277s
in cf9528de, 0 bytes, 0 packets
out c0785f9e, 0 bytes, 0 packets
local 10.233.67.0/24
remote 192.168.56.11/32 192.168.56.12/32
beijing.connector-n2p: #3, reqid 3, INSTALLED, TUNNEL-in-UDP, ESP:AES_GCM_16-128
installed 2683s ago, rekeying in 703s, expires in 1277s
in c6284776, 0 bytes, 0 packets
out c0eefea6, 0 bytes, 0 packets
local 10.22.46.28/32
remote 10.233.0.0/18 10.233.64.0/24 10.233.65.0/24
```
上面的输出结果包含这么一行:
```
remote 'C=CN, O=fabedge.io, CN=beijing.connector' @ 10.40.20.181[45000]
```
这就意味着edge1, edge2上的strongswan连接云端的strongswan时使用了10.40.20.181:45000这个地址,证明我们的配置成功了。下面让我们看看这个配置会影响edge1, edge2之间的通信吗?
先为edge1, edge2创建一个community:
```shell
cat > all-edges.yaml << EOF
apiVersion: fabedge.io/v1alpha1
kind: Community
metadata:
name: all-edges
spec:
members:
- beijing.edge1
- beijing.edge2
EOF
kubectl apply -f all-edges.yaml
```
然后检查edge1, edge2彼此之间的隧道信息:
```shell
$ fabctl swanctl list-sa edge1
========================== fabedge-agent-xfntz =================================
beijing.edge2: #4, ESTABLISHED, IKEv2, da14230995406a58_i* df83821754f9c263_r
local 'C=CN, O=fabedge.io, CN=beijing.edge1' @ 10.22.46.30[4500]
remote 'C=CN, O=fabedge.io, CN=beijing.edge2' @ 10.22.46.28[4500]
AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/CURVE_25519
established 62s ago, rekeying in 12926s
beijing.edge2-p2p: #4, reqid 4, INSTALLED, TUNNEL, ESP:AES_GCM_16-128
installed 62s ago, rekeying in 3245s, expires in 3898s
in cfeeafca, 0 bytes, 0 packets
out c8c1f7aa, 0 bytes, 0 packets
local 10.233.66.0/24
remote 10.233.67.0/24
beijing.edge2-p2n: #5, reqid 5, INSTALLED, TUNNEL, ESP:AES_GCM_16-128
installed 62s ago, rekeying in 3233s, expires in 3898s
in cfefe387, 0 bytes, 0 packets
out ccc83258, 0 bytes, 0 packets
local 10.233.66.0/24
remote 10.22.46.28/32
beijing.edge2-n2p: #6, reqid 6, INSTALLED, TUNNEL, ESP:AES_GCM_16-128
installed 62s ago, rekeying in 3420s, expires in 3898s
in c7f1a30b, 0 bytes, 0 packets
out cabd83c9, 0 bytes, 0 packets
local 10.22.46.30/32
remote 10.233.67.0/24
$ fabctl swanctl list-sa edge2
========================== fabedge-agent-gb5qd =================================
beijing.edge1: #3, ESTABLISHED, IKEv2, da14230995406a58_i df83821754f9c263_r*
local 'C=CN, O=fabedge.io, CN=beijing.edge2' @ 10.22.46.28[4500]
remote 'C=CN, O=fabedge.io, CN=beijing.edge1' @ 10.22.46.30[4500]
AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/CURVE_25519
established 213s ago, rekeying in 13060s
beijing.edge1-p2p: #4, reqid 4, INSTALLED, TUNNEL, ESP:AES_GCM_16-128
installed 213s ago, rekeying in 3137s, expires in 3747s
in c8c1f7aa, 0 bytes, 0 packets
out cfeeafca, 0 bytes, 0 packets
local 10.233.67.0/24
remote 10.233.66.0/24
beijing.edge1-n2p: #5, reqid 5, INSTALLED, TUNNEL, ESP:AES_GCM_16-128
installed 213s ago, rekeying in 3040s, expires in 3747s
in ccc83258, 0 bytes, 0 packets
out cfefe387, 0 bytes, 0 packets
local 10.22.46.28/32
remote 10.233.66.0/24
beijing.edge1-p2n: #6, reqid 6, INSTALLED, TUNNEL, ESP:AES_GCM_16-128
installed 213s ago, rekeying in 3209s, expires in 3747s
in cabd83c9, 0 bytes, 0 packets
out c7f1a30b, 0 bytes, 0 packets
local 10.233.67.0/24
remote 10.22.46.30/32
```
从上面的输出结果可以看出:edge1与edge2之间的隧道依然利用4500通信,不受connector配置的影响。如果希望边缘节点之间通过500, 4500端口外的值通信要怎么办?
答案是不能且没必要,因为边缘网络比较复杂,为每个边缘节点的strongswan都进行端口映射是个很麻烦的事,而且有些节点本身就在一个局域网,它们之间用500, 4500通信,却为外部通信配置不同的端口也会引入复杂的配置工作。但有些时候,边缘节点就是需要跨网通信,不能配置端口又该怎么做,那就需要使用FabEdge v0.8.0引入的新特性:打洞,见下文。
以上介绍了配置connector公开端口的方法和效果,需要一提的是,一旦使用500, 4500外的端口进行通信,strongswan就会利用non-esp格式,这种格式会一定程度上影响性能,所以能使用500, 4500的情况下最好还是使用。