searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

高性能ilium LB应用及分析

2023-09-26 04:31:59
71
0

背景

Cilium是一个开源的网络和安全项目,旨在提供高效的容器网络连接和强大的网络安全功能。而Cilium Load Balancer(CiliumLB)是Cilium项目中的一部分,它提供了用于负载均衡的功能。

CiliumLB通过使用Linux内核中的eBPF(extended Berkeley Packet Filter)技术,实现了高性能的负载均衡功能。它可以直接在主机或云环境中与Cilium和Kubernetes集成,并为其提供负载均衡服务。

应用

通过docker启动CiliumLB

docker run \
-it \
--cap-add NET_ADMIN \
--cap-add SYS_MODULE \
--cap-add CAP_SYS_ADMIN \
--privileged \
-v /sys/fs/bpf:/sys/fs/bpf \
-v /lib/modules \
--name l4lb \
--entrypoint=bash \
--ip 172.17.0.2 \
quay.io/cilium/cilium:v1.12.2

进入到容器内执行以下指令启动lb

cilium-agent \
--devices=eth0 \
--datapath-mode=lb-only \
--enable-l7-proxy=false \
--tunnel=disabled \
--install-iptables-rules=false \
--enable-bandwidth-manager=false \
--enable-local-redirect-policy=false \
--enable-hubble=false \
--enable-l7-proxy=false \
--preallocate-bpf-maps=false \
--disable-envoy-version-check=true \
--auto-direct-node-routes=false \
--enable-ipv4=true \
--enable-ipv6=false

配置ciliumLB

cilium service update --id 1 --frontend "172.17.0.2:80" --backends "172.17.0.3:80,172.17.0.4:80" --k8s-node-port

 

以上的配置添加一个id为lb配置,前端监听器为:172.17.0.2:80,后端服务组为:172.17.0.3:80/172.17.0.4:80。

启动nginx作为后端

docker run -it --rm --ip 172.17.0.3  -d nginx
docker run -it --rm --ip 172.17.0.4  -d nginx

使用curl测试

(base) ➜  ~ curl 172.17.0.2:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
 
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
 
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

可以看到cilium已经正常工作。

代码分析(FullNAT为例)

lb正向流量首包

反向流量

总结

文章给出了cilium的应用使用例子,后续分析了cilium的关键代码流程。

0条评论
0 / 1000
罗****鹤
5文章数
0粉丝数
罗****鹤
5 文章 | 0 粉丝
原创

高性能ilium LB应用及分析

2023-09-26 04:31:59
71
0

背景

Cilium是一个开源的网络和安全项目,旨在提供高效的容器网络连接和强大的网络安全功能。而Cilium Load Balancer(CiliumLB)是Cilium项目中的一部分,它提供了用于负载均衡的功能。

CiliumLB通过使用Linux内核中的eBPF(extended Berkeley Packet Filter)技术,实现了高性能的负载均衡功能。它可以直接在主机或云环境中与Cilium和Kubernetes集成,并为其提供负载均衡服务。

应用

通过docker启动CiliumLB

docker run \
-it \
--cap-add NET_ADMIN \
--cap-add SYS_MODULE \
--cap-add CAP_SYS_ADMIN \
--privileged \
-v /sys/fs/bpf:/sys/fs/bpf \
-v /lib/modules \
--name l4lb \
--entrypoint=bash \
--ip 172.17.0.2 \
quay.io/cilium/cilium:v1.12.2

进入到容器内执行以下指令启动lb

cilium-agent \
--devices=eth0 \
--datapath-mode=lb-only \
--enable-l7-proxy=false \
--tunnel=disabled \
--install-iptables-rules=false \
--enable-bandwidth-manager=false \
--enable-local-redirect-policy=false \
--enable-hubble=false \
--enable-l7-proxy=false \
--preallocate-bpf-maps=false \
--disable-envoy-version-check=true \
--auto-direct-node-routes=false \
--enable-ipv4=true \
--enable-ipv6=false

配置ciliumLB

cilium service update --id 1 --frontend "172.17.0.2:80" --backends "172.17.0.3:80,172.17.0.4:80" --k8s-node-port

 

以上的配置添加一个id为lb配置,前端监听器为:172.17.0.2:80,后端服务组为:172.17.0.3:80/172.17.0.4:80。

启动nginx作为后端

docker run -it --rm --ip 172.17.0.3  -d nginx
docker run -it --rm --ip 172.17.0.4  -d nginx

使用curl测试

(base) ➜  ~ curl 172.17.0.2:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
 
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
 
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

可以看到cilium已经正常工作。

代码分析(FullNAT为例)

lb正向流量首包

反向流量

总结

文章给出了cilium的应用使用例子,后续分析了cilium的关键代码流程。

文章来自个人专栏
文章 | 订阅
0条评论
0 / 1000
请输入你的评论
0
0