解决 Calico 报错 Felix eBPF dataplane fails to attach 网格失败修复
排查 Calico 切换为 eBPF 数据面时,Felix Pod 报错 failed to attach BPF program to interface: Operation not supported,分析 内核版本、BPF 文件系统挂载与 cgroup2 支持。
问题现象
在 K8s 集群中启用 Calico eBPF 模式后,网络插件崩溃处于 CrashLoopBackOff:
[FATAL][1] felix/bpf.go 340: Failed to attach BPF program to interface cali1209a error=operation not supported
[ERROR][1] felix/int_dataplane.go: BPF data plane failed to initialize
触发根因
- 宿主机 Linux 内核版本低于 5.3,缺乏 BPF tc-bpf 或特定辅助函数的完整内核特性支持;
- 宿主机未挂载 BPF 文件系统(
/sys/fs/bpf),导致 Felix 无法持久化 BPF Maps; - Cgroups v2 未挂载或权限不足,导致基于 Socket 的负载均衡程序无法挂载到根 Cgroup。
解决步骤
在所有 Kubernetes Node 节点上挂载 BPF 文件系统
执行挂载并在 /etc/fstab 中持久化:
mount -t bpf bpffs /sys/fs/bpf
echo 'bpffs /sys/fs/bpf bpf defaults 0 0' >> /etc/fstab
核对宿主机 Linux 内核版本并升级至现代 LTS 内核(5.15+ 或 6.x)
检查内核:uname -r。
检查并配置 Felix 的 eBPF 模式兼容性参数
编辑 FelixConfiguration:
kubectl patch felixconfiguration default --type='merge' -p '{"spec":{"bpfEnabled":true,"bpfLogLevel":"Info"}}'
验证确认
重启 Calico Felix 守护集:
Felix 秒级完成 BPF 程序向网络接口挂载,Pod 间流量全面切换至极速 eBPF 数据面。


