K8s 网络插件选型与 Calico/Cilium 部署(CNI 对比)
一、背景
CNI 网络插件决定了集群的性能、安全策略与可观测性能力。大模型平台常涉及跨节点 GPU 通信(NCCL)、东西向大流量,选型尤为关键。本文对比 Calico 与 Cilium 并给出部署。
二、环境信息
- Kubernetes v1.28,containerd
- 候选:Calico 3.26(BGP/Overlay,NetworkPolicy 成熟);Cilium 1.14(eBPF,性能/L3-L7 策略/可观测强)
三、操作要点
方案 A:Calico(BGP 模式,适合有路由交换能力的数据中心)
1 2
| kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/calico.yaml
|
方案 B:Cilium(eBPF,推荐新集群,可替代 kube-proxy)
1 2 3 4 5
| curl -L --remote-name https://github.com/cilium/cilium-cli/releases/download/v1.14.0/cilium-linux-amd64.tar.gz tar xzvf cilium-linux-amd64.tar.gz && mv cilium /usr/local/bin/
cilium install --set kubeProxyReplacement=strict --set k8sServiceHost=192.168.0.100 --set k8sServicePort=6443
|
网络策略示例
1 2 3 4 5 6 7
| apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: { name: allow-inference } spec: podSelector: { matchLabels: { app: vllm } } ingress: - from: [{ podSelector: { matchLabels: { app: gateway } } }]
|
四、验证方式
1 2 3 4 5
| kubectl run nettool --image=busybox -it --rm -- wget -qO- <pod-ip> calicoctl node status cilium status --wait cilium connectivity test
|
五、常见问题
- 防火墙未关导致 Pod 不通:统一放行或配置对应规则;不要与 CNI 的 iptables 规则冲突
- MTU 不匹配:Overlay 场景需调小(如 1440/1400)
- Cilium 与 kube-proxy 冲突:用
kubeProxyReplacement=strict 时确认已移除 kube-proxy
- BGP peer 未建立:检查 ASN、邻居 IP 与 ToR 交换机配置
- overlay 性能差:大流量推理/训练优先 BGP/直连路由