惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
罗磊的独立博客
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
The Register - Security
The Register - Security
J
Java Code Geeks
V2EX - 技术
V2EX - 技术
Vercel News
Vercel News
N
News and Events Feed by Topic
腾讯CDC
P
Proofpoint News Feed
N
News | PayPal Newsroom
www.infosecurity-magazine.com
www.infosecurity-magazine.com
爱范儿
爱范儿
O
OpenAI News
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
Martin Fowler
Martin Fowler
Engineering at Meta
Engineering at Meta
D
Docker
Y
Y Combinator Blog
博客园 - 聂微东
G
Google Developers Blog
S
Security @ Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
阮一峰的网络日志
阮一峰的网络日志
C
CXSECURITY Database RSS Feed - CXSecurity.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
CERT Recently Published Vulnerability Notes
I
Intezer
G
GRAHAM CLULEY
有赞技术团队
有赞技术团队
Attack and Defense Labs
Attack and Defense Labs
V
Visual Studio Blog
博客园 - Franky
博客园 - 三生石上(FineUI控件)
W
WeLiveSecurity
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hugging Face - Blog
Hugging Face - Blog
Scott Helme
Scott Helme
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
LINUX DO - 最新话题
C
Cybersecurity and Infrastructure Security Agency CISA

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 使用 Docker 运行 Tensorflow 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19) 使用 Velero 备份 Kubernetes 集群 Kubernetes Cheat Sheet 开发 Tips(18) 如何构建一个 Java 工程 开发 Tips(17) KubeSpray 安装 Kubernetes 报错 ip in ansible_all_ipv4_addresses 基于 Kubernetes 和 Jenkins 搭建自动化测试系统 在 Kubernetes 上动态创建 Jenkins Slave 使用 Jenkins 进行服务拨测 开发 Tips(16) Kubernetes 签发 Ingress 证书及日常故障运维 Kubernetes 中 Deployment 的基本操作 Kubernetes 中的证书 如何使用 KubeBuilder 开发一个 Operator Kubernetes 1.6.0 安装问题汇总 镜像管理工具 -- Harbor 开发 Tips(15) Docker 如何拉取镜像 开发 Tips(14) 使用 Helm 安装 harbor 开发 Tips(13) 使用 S2I 构建云原生应用 在 Kubernetes 中使用 emptyDir、hostPath、localVolume 开发 Tips(12) 开发 Tips(11) 代码质量分析工具 SonarQube 使用 Kubeadm 安装 Kubernetes 集群 一起来学 Go --(4)常用函数 Kubernetes 中的 Ceph Kubernetes 之 Volumes Kubernetes 之 Labels、Selectors 开发 Tips(10) 开源正在重构商业模式 Kubernetes 之网络 Kubernetes 之 API 使用 Helm 和 Operator 快速部署 Prometheus Kubernetes 复杂有状态应用管理框架 -- Operator Kubernetes 的包管理器 -- Helm 一起来学 Go --(3)Go Modules 如何一步一步地优化博客方案 kubectl 实用指南 Kubernetes 中的基本概念 搭建远程 Kubernetes 开发环境 大公司和小公司的 ToB 思路 开发 Tips(9) Go 入门指南 一起来学 Go --(2)数据与逻辑结构 如何预防 Web 富文本中的 XSS 攻击 django-xss-cleaner 云工作时代 一起来学 Go --(1)背景与特点 SaaS 开发团队的不同阶段 你不知道的 Git 使用技巧 输出既服务 微服务设计 继续奔跑 开发 Tips(8) 从账户安全到二次验证 Django 性能之数据库查询优化 Django 性能之分库分表 敏捷开发之研发流程 打造一致性的团队 开发 Tips(7) Pytest 进阶学习之 Mock PaaS 部署之 buildpack Go 开发配置 领域输出才是 PaaS 的核心竞争力 Pytest 入门学习 开发 Tips(6) 如何使用 Jenkins、Docker、GitLab 搭建 Django 自动化部署流程
使用 Calico 限制 Pod 的带宽
微信公众号 · 2025-02-12 · via 陈少文的网站

Please enable Javascript to view the contents

1. 测试全部带宽

  • 在目标主机上启动 iperf3 服务端
1
2
3
4
5
iperf3 -s

-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
  • 在客户端主机上测试
1
iperf3 -c x.x.x.x -p 5201 -t 10
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
Connecting to host x.x.x.x, port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec   151 MBytes  1.27 Gbits/sec  3562    164 KBytes
[  5]   1.00-2.00   sec   134 MBytes  1.12 Gbits/sec  230    164 KBytes
[  5]   2.00-3.00   sec   124 MBytes  1.04 Gbits/sec  250    213 KBytes
[  5]   3.00-4.00   sec   122 MBytes  1.03 Gbits/sec  229    195 KBytes
[  5]   4.00-5.00   sec   122 MBytes  1.03 Gbits/sec  342    198 KBytes
[  5]   5.00-6.00   sec   125 MBytes  1.05 Gbits/sec  351    212 KBytes
[  5]   6.00-7.00   sec   124 MBytes  1.04 Gbits/sec  319    220 KBytes
[  5]   7.00-8.00   sec   121 MBytes  1.02 Gbits/sec  286    220 KBytes
[  5]   8.00-9.00   sec   125 MBytes  1.05 Gbits/sec  233    191 KBytes
[  5]   9.00-10.00  sec   122 MBytes  1.03 Gbits/sec  377    192 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec  1.24 GBytes  1.07 Gbits/sec  6179             sender
[  5]   0.00-10.00  sec  1.24 GBytes  1.06 Gbits/sec                  receiver

这说明两台主机之间的带宽是 1 Gbps 。

2. 确认 Calico 已经开启 Bandwidth 插件

  1. 在 Calico 的 ConfigMap 配置文件中应该可以看到 Bandwidth 插件
1
kubectl -n calico-system get cm cni-config  -o yaml
1
2
3
4
        {
          "type": "bandwidth",
          "capabilities": {"bandwidth": true}
        },
  1. 在主机上可以看到 calico-bandwidth 的插件
1
cat /etc/cni/net.d/10-calico.conflist
1
2
3
4
    {
      "type": "bandwidth",
      "capabilities": {"bandwidth": true}
    },

3. 创建带宽受限的 Pod

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-rate-limit
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-rate-limit
  template:
    metadata:
      labels:
        app: test-rate-limit
      annotations:
        kubernetes.io/egress-bandwidth: "1M"
        kubernetes.io/ingress-bandwidth: "1M"
    spec:
      containers:
      - name: main
        image: shaowenchen/demo:iperf3
        ports:
        - containerPort: 80
EOF

这里的 M 单位是 Mbps,所以这里设置的是 1 Mbps 的带宽。

kubernetes.io/egress-bandwidth 表示的是 Pod 的出口带宽,也就是其他应用访问这个 Pod 的带宽。

kubernetes.io/ingress-bandwidth 表示的是 Pod 的入口带宽,也就是这个 Pod 访问其他应用的带宽。

4. 在 Pod 中测试带宽

  • 在容器中启动客户端
1
kubectl exec deployment/test-rate-limit  -- bash -c "iperf3 -c x.x.x.x -p 5201 -t 10"
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
Connecting to host x.x.x.x, port 5201
[  5] local 10.244.101.19 port 60566 connected to x.x.x.x port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  8.81 MBytes  73.9 Mbits/sec    0    382 KBytes
[  5]   1.00-2.00   sec  0.00 Bytes  0.00 bits/sec    0    388 KBytes
[  5]   2.00-3.00   sec  0.00 Bytes  0.00 bits/sec    0    395 KBytes
[  5]   3.00-4.00   sec   816 KBytes  6.68 Mbits/sec    0    395 KBytes
[  5]   4.00-5.00   sec  0.00 Bytes  0.00 bits/sec    0    395 KBytes
[  5]   5.00-6.00   sec  0.00 Bytes  0.00 bits/sec    0    395 KBytes
[  5]   6.00-7.00   sec  0.00 Bytes  0.00 bits/sec    0    395 KBytes
[  5]   7.00-8.00   sec  0.00 Bytes  0.00 bits/sec    0    395 KBytes
[  5]   8.00-9.00   sec  0.00 Bytes  0.00 bits/sec    0    395 KBytes
[  5]   9.00-10.00  sec  0.00 Bytes  0.00 bits/sec    0    395 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec  9.61 MBytes  8.06 Mbits/sec    0             sender
[  5]   0.00-10.11  sec  8.03 MBytes  6.67 Mbits/sec                  receiver
  • 将 kubernetes.io/egress-bandwidth 设置为 100M
1
kubectl exec deployment/test-rate-limit  -- bash -c "iperf3 -c x.x.x.x -p 5201 -t 10"
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
Connecting to host x.x.x.x, port 5201
[  5] local 10.244.101.50 port 34504 connected to x.x.x.x port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec   127 MBytes  1.06 Gbits/sec  2262   1.37 KBytes
[  5]   1.00-2.00   sec   124 MBytes  1.04 Gbits/sec  2423    198 KBytes
[  5]   2.00-3.00   sec  25.0 MBytes   210 Mbits/sec   26    177 KBytes
[  5]   3.00-4.00   sec  11.2 MBytes  94.4 Mbits/sec    0    177 KBytes
[  5]   4.00-5.00   sec  11.2 MBytes  94.4 Mbits/sec    0    177 KBytes
[  5]   5.00-6.00   sec  11.2 MBytes  94.4 Mbits/sec    0    177 KBytes
[  5]   6.00-7.00   sec  12.5 MBytes   105 Mbits/sec    0    177 KBytes
[  5]   7.00-8.00   sec  11.2 MBytes  94.4 Mbits/sec    0    177 KBytes
[  5]   8.00-9.00   sec  11.2 MBytes  94.4 Mbits/sec    0    177 KBytes
[  5]   9.00-10.00  sec  11.2 MBytes  94.4 Mbits/sec    0    177 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec   355 MBytes   298 Mbits/sec  4711             sender
[  5]   0.00-10.01  sec   352 MBytes   295 Mbits/sec                  receiver

iperf3 测试持续的时间越长,带宽值越稳定,越接近设置的限制值。

5. 总结

在集群除了 CPU、Memory 之外,IO 中的带宽也是受限资源,特别是在高密度部署的集群中,时常会因为带宽抢占,导致服务的延时增加。

本篇主要是介绍了如何使用 Calico 的 Bandwidth 插件来限制 Pod 的带宽,通过设置 kubernetes.io/egress-bandwidth 和 kubernetes.io/ingress-bandwidth 来限制 Pod 的出口和入口带宽。

值得注意的是,虽然对 Pod 的带宽进行了限制,在并不是实时有效,在流量发起时,可能会出现瞬时的带宽超限情况,但是随着时间的推移,带宽会逐渐稳定在限制值附近。

另外在测试过程还发现,如果 Pod 使用了 HostNetwork,那么设置的带宽限制是无效的,这是因为 HostNetwork 的 Pod 是直接使用主机的网络资源,所以无法通过 Calico 的 Bandwidth 插件来限制。


微信公众号