容器網絡限速
更新時間 2025-05-27 09:13:25
最近更新時間: 2025-05-27 09:13:25
分享文章
本節介紹使容器網絡限速的用戶指南。
在離線應用混部中通過使用容器網絡限速,幫助用戶為不同應用配置網絡帶寬限制與優先級,提升集群資源隔離與網絡體驗。
適用場景
需要對容器的入站/出站網絡帶寬進行限制,防止單一業務占用過多帶寬。
希望為延遲敏感或大帶寬業務設置網絡優先級,實現更優的流量調度。
功能說明
帶寬限制
網絡優先級控制
配置方法
啟用網絡優先級能力(可選)
如需使用網絡優先級控制,請確保集群已啟用 Cubecni 的優先級功能:
編輯 Cubecni 配置:
kubectl -n kube-system edit cm cubecni-config在
10-cubecni.conflist下添加/修改enable_network_priority為true:{ "cniVersion": "0.3.1", "name": "cubecni", "plugins": [ { "type": "cubecni", "capabilities": {"bandwidth": true}, "enable_network_priority": true } ]}滾動重啟 Cubecni Pod:
kubectl -n kube-system rollout restart ds/cubecni kubectl -n kube-system get po -l app=cubecni -owide -w
配置帶寬與優先級注解
在 Pod/Deployment YAML 的 metadata.annotations 字段中添加帶寬和優先級注解。例如:
apiVersion: apps/v1kind: Deploymentmetadata:
name: netperf-client-8000
namespace: demospec:
replicas: 2
template:
metadata:
annotations:
kubernetes.io/egress-bandwidth: 10M
kubernetes.io/ingress-bandwidth: 20M
k8s.ctyun.com/network-priority: guaranteed
spec:
containers:
- name: netperf
image: cilium-netperf:2.0操作步驟
測試與驗證流程
部署帶寬限制測試 server(hostNetwork)
apiVersion: apps/v1kind: Deploymentmetadata: name: netserver-hostnet namespace: demospec: replicas: 1 template: metadata: labels: app: netserver-hostnet spec: hostNetwork: true containers: - name: netserver image: cilium-netperf:2.0 command: ["netserver", "-4", "-p", "8000", "-D"]部署帶寬限制 client,設置帶寬注解
apiVersion: apps/v1kind: Deploymentmetadata: name: netperf-client-8000 namespace: demospec: replicas: 2 template: metadata: annotations: kubernetes.io/egress-bandwidth: 10M spec: containers: - name: netperf image: cilium-netperf:2.0 command: ["sleep", "infinity"]進入 client Pod,使用
netperf工具測試帶寬kubectl exec -it <client-pod> -n demo -- netperf -H <server-ip> -l 60 -t TCP_STREAM可通過宿主機
tc命令進一步驗證帶寬限制規則tc qdisc show tc class show dev <ethX>
常見問題與說明
注解配置無效?
請確認集群網絡插件為 Cubecni,且已啟用帶寬/優先級能力。
檢查注解拼寫及 YAML 縮進。
優先級控制未生效?
需確保 Cubecni 配置項
enable_network_priority為true并已重啟插件。帶寬限制未達到預期?
實際帶寬受節點網絡、Pod 資源等多因素影響,建議多次測試取均值。
注意
帶寬與優先級注解僅對支持的網絡插件(如 Cubecni)生效。
修改插件配置需謹慎,避免影響生產流量。
測試時建議隔離環境,避免干擾其他業務。