我可以不吃啊 发表于 2023-7-31 09:47:48

Cilium系列-8-绕过 IPTables 连接跟踪

系列文章


[*]Cilium 系列文章
前言

将 Kubernetes 的 CNI 从其他组件切换为 Cilium, 已经可以有效地提升网络的性能. 但是通过对 Cilium 不同模式的切换/功能的启用, 可以进一步提升 Cilium 的网络性能. 具体调优项包括不限于:

[*]启用本地路由(Native Routing)
[*]完全替换 KubeProxy
[*]IP 地址伪装(Masquerading)切换为基于 eBPF 的模式
[*]Kubernetes NodePort 实现在 DSR(Direct Server Return) 模式下运行
[*]绕过 iptables 连接跟踪(Bypass iptables Connection Tracking)
[*]主机路由(Host Routing)切换为基于 BPF 的模式 (需要 Linux Kernel >= 5.10)
[*]启用 IPv6 BIG TCP (需要 Linux Kernel >= 5.19)
[*]禁用 Hubble(但是不建议, 可观察性比一点点的性能提升更重要)
[*]修改 MTU 为巨型帧(jumbo frames) (需要网络条件允许)
[*]启用带宽管理器(Bandwidth Manager) (需要 Kernel >= 5.1)
[*]启用 Pod 的 BBR 拥塞控制 (需要 Kernel >= 5.18)
[*]启用 XDP 加速 (需要 支持本地 XDP 驱动程序)
[*](高级用户可选)调整 eBPF Map Size
[*]Linux Kernel 优化和升级

[*]CONFIG_PREEMPT_NONE=y

[*]其他:

[*]tuned network-* profiles, 如: tuned-adm profile network-latency 或 network-throughput
[*]CPU 调为性能模式
[*]停止 irqbalance,将网卡中断引脚指向特定 CPU

在网络/网卡设备/OS等条件满足的情况下, 我们尽可能多地启用这些调优选项, 相关优化项会在后续文章逐一更新. 敬请期待.
今天我们来调优 Cilium, 设置绕过 IPTables 连接跟踪以提升网络性能.
测试环境


[*]Cilium 1.13.4
[*]K3s v1.26.6+k3s1
[*]OS

[*]3 台 Ubuntu 23.04 VM, Kernel 6.2, x86

绕过 IPTables 连接跟踪

在无法使用 eBPF 主机路由(Host-Routing)的情况下,网络数据包仍需在主机命名空间中穿越常规网络堆栈,iptables 会增加大量成本。通过禁用所有 Pod 流量的连接跟踪(connection tracking)要求,从而绕过 iptables 连接跟踪器(iptables connection tracker),可将这种遍历成本降至最低。
需求


[*]内核 >= 4.19.57, >= 5.1.16, >= 5.2
[*]直接路由(Direct-routing)配置
[*]基于 eBPF 的 kube-proxy 替换
[*]基于 eBPF 的伪装(masquerading)或无伪装
实施步骤

helm upgrade cilium cilium/cilium --version 1.13.4 \
--namespace kube-system \
--reuse-values \
--set installNoConntrackIptablesRules=true总结

本文我们调优 Cilium, 设置绕过 IPTables 连接跟踪以提升网络性能.
至此,性能调优已完成:

[*]✔️ 启用本地路由 (Native Routing)
[*]✔️ 完全替换 KubeProxy
[*]✔️ IP 地址伪装 (Masquerading) 切换为基于 eBPF 的模式
[*]✔️ Kubernetes NodePort 实现在 DSR(Direct Server Return) 模式下运行
[*]✔️ 绕过 iptables 连接跟踪 (Bypass iptables Connection Tracking)
[*]主机路由 (Host Routing) 切换为基于 BPF 的模式 (需要 Linux Kernel >= 5.10)
[*]启用 IPv6 BIG TCP (需要 Linux Kernel >= 5.19)
[*]修改 MTU 为巨型帧 (jumbo frames) (需要网络条件允许)
[*]启用带宽管理器 (Bandwidth Manager) (需要 Kernel >= 5.1)
[*]启用 Pod 的 BBR 拥塞控制 (需要 Kernel >= 5.18)
[*]启用 XDP 加速 (需要 支持本地 XDP 驱动程序)

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: Cilium系列-8-绕过 IPTables 连接跟踪