当前位置: 首页 > news >正文

k8s 查看pod流量_K8s中对pod进行流量限制

最近接到一个需求,对日志上传的pod进行流量限制。

# 前期准备k8s一份

calico装好

# k8s配置

由于默认情况下calico并没有启用流量限制的功能,所以需要在calico的配置文件里面启用一下。在每个节点的/etc/cni/net.d/10-calico.conflist 文件中加入bandwidth的支持。这一步最好在安装calico的时候做了,就不用每个节点都配置一遍。期待calico把这个选项也默认打开的一天(https://github.com/projectcalico/calico/issues/2815)。因为是实验环境,我只有一个节点,就手动配置了。

vagrant@ubuntu:~$ cat /etc/cni/net.d/10-calico.conflist

{

"name": "k8s-pod-network",

"cniVersion": "0.3.1",

"plugins": [

{

"type": "calico",

"datastore_type": "kubernetes",

"mtu": 1410,

"nodename_file_optional": false,

"log_file_path": "/var/log/calico/cni/cni.log",

"ipam": {

"type": "calico-ipam",

"assign_ipv4" : "true",

"assign_ipv6" : "false"

},

"container_settings": {

"allow_ip_forwarding": false

},

"policy": {

"type": "k8s"

},

"kubernetes": {

"kubeconfig": "/etc/cni/net.d/calico-kubeconfig"

}

},

{"type": "portmap", "snat": true, "capabilities": {"portMappings": true}},

{

"type": "bandwidth",

"capabilities": {"bandwidth": true}

}

]

}

#流量限制的原理

其实原理很简单,就是在pod启动的时候,在对应的虚拟网络设备加上相应的tc规则,通过tc实现的流量限制。不懂TC的可以参阅https://cloud.tencent.com/developer/article/1409664 等资料。

#实验一

没有流量限制的情况下两个pod之间。

通过下面的yaml启动两个pod。

---apiVersion:v1kind:Podmetadata:name:perf1labels:app:perf1# annotations:# kubernetes.io/ingress-bandwidth: 10M# kubernetes.io/egress-bandwidth: 10Mspec:containers:- name:perf-serverimage:elynn/pperf:latestimagePullPolicy:Alwayscommand:- "/opt/runserver.sh"ports:- containerPort:5201- containerPort:5203---apiVersion:v1kind:Podmetadata:name:perf2labels:app:perf2# annotations:# kubernetes.io/ingress-bandwidth: 1M# kubernetes.io/egress-bandwidth: 1Mspec:containers:- name:perf-serverimage:elynn/pperf:latestimagePullPolicy:Alwayscommand:- "/opt/runserver.sh"ports:- containerPort:5201- containerPort:5203

pod启动完之后,我们先看看对应节点的tc规则,并没有找到任何的流量限制。

$ tc qdisc show

qdisc noqueue 0: dev lo root refcnt 2

qdisc pfifo_fast 0: dev ens33 root refcnt 2 bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1

qdisc noqueue 0: dev docker0 root refcnt 2

qdisc noqueue 0: dev cali51d8b092aa9 root refcnt 2

qdisc noqueue 0: dev cali40347405ff0 root refcnt 2

qdisc noqueue 0: dev vxlan.calico root refcnt 2

qdisc noqueue 0: dev cali3fe07939e27 root refcnt 2

qdisc noqueue 0: dev califde8991e611 root refcnt 2

qdisc noqueue 0: dev calieec63a8d445 root refcnt 2

到pod里面跑个iperf试试,单机转发30Gbits的流量。

$ kubectl exec -it perf1 bash

kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.

root@perf1:/opt# iperf3 -c 192.168.243.203

Connecting to host 192.168.243.203, port 5201

[ 4] local 192.168.243.202 port 57728 connected to 192.168.243.203 port 5201

[ ID] Interval Transfer Bandwidth Retr Cwnd

[ 4] 0.00-1.00 sec 3.62 GBytes 31.1 Gbits/sec 283 893 KBytes

[ 4] 1.00-2.00 sec 3.64 GBytes 31.2 Gbits/sec 0 896 KBytes

[ 4] 2.00-3.00 sec 3.57 GBytes 30.7 Gbits/sec 0 1.38 MBytes

[ 4] 3.00-4.00 sec 3.61 GBytes 31.0 Gbits/sec 0 1.38 MBytes

[ 4] 4.00-5.00 sec 3.55 GBytes 30.5 Gbits/sec 0 1.38 MBytes

[ 4] 5.00-6.00 sec 3.64 GBytes 31.2 Gbits/sec 0 1.39 MBytes

[ 4] 6.00-7.00 sec 3.55 GBytes 30.5 Gbits/sec 0 1.39 MBytes

[ 4] 7.00-8.00 sec 3.59 GBytes 30.8 Gbits/sec 0 1.39 MBytes

[ 4] 8.00-9.00 sec 3.50 GBytes 30.1 Gbits/sec 0 1.49 MBytes

^C[ 4] 9.00-9.46 sec 1.67 GBytes 31.4 Gbits/sec 0 1.52 MBytes

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval Transfer Bandwidth Retr

[ 4] 0.00-9.46 sec 33.9 GBytes 30.8 Gbits/sec 283 sender

[ 4] 0.00-9.46 sec 0.00 Bytes 0.00 bits/sec receiver

#实验二

试试把流量控制加上。把实验一中的yaml文件的下列内容加上,就表示限制这个pod的进出流量都是10M。

annotations:kubernetes.io/ingress-bandwidth:10Mkubernetes.io/egress-bandwidth:10M

把之前的pod删了,再创建一下。创建成功之后就能看到tc规则加上了。

```

vagrant@ubuntu:~$ tc qdisc show

qdisc noqueue 0: dev lo root refcnt 2

qdisc pfifo_fast 0: dev ens33 root refcnt 2 bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1

qdisc noqueue 0: dev docker0 root refcnt 2

qdisc noqueue 0: dev cali51d8b092aa9 root refcnt 2

qdisc noqueue 0: dev cali40347405ff0 root refcnt 2

qdisc noqueue 0: dev vxlan.calico root refcnt 2

qdisc noqueue 0: dev cali3fe07939e27 root refcnt 2

qdisc noqueue 0: dev calieec63a8d445 root refcnt 2

qdisc tbf 1: dev califde8991e611 root refcnt 2 rate 10Mbit burst 256Mb lat 25.0ms

qdisc ingress ffff: dev califde8991e611 parent ffff:fff1 ----------------

qdisc tbf 1: dev bwp9524c730aa56 root refcnt 2 rate 10Mbit burst 256Mb lat 25.0ms

```

跑一把流量测试看看,就能看到流量被限制到了10Mbits/s。

vagrant@ubuntu:~$ kubectl exec -it perf1 bash

kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.

root@perf1:/opt# iperf3 -c 192.168.243.204

Connecting to host 192.168.243.204, port 5201

[ 4] local 192.168.243.205 port 35668 connected to 192.168.243.204 port 5201

[ ID] Interval Transfer Bandwidth Retr Cwnd

[ 4] 0.00-1.00 sec 246 MBytes 2.06 Gbits/sec 4 263 KBytes

[ 4] 1.00-2.00 sec 1.12 MBytes 9.39 Mbits/sec 0 263 KBytes

[ 4] 2.00-3.00 sec 1.12 MBytes 9.39 Mbits/sec 0 263 KBytes

[ 4] 3.00-4.00 sec 1.18 MBytes 9.91 Mbits/sec 0 263 KBytes

[ 4] 4.00-5.00 sec 1.12 MBytes 9.39 Mbits/sec 0 263 KBytes

[ 4] 5.00-6.00 sec 1.12 MBytes 9.39 Mbits/sec 0 263 KBytes

[ 4] 6.00-7.00 sec 1.18 MBytes 9.91 Mbits/sec 0 263 KBytes

[ 4] 7.00-8.00 sec 1.12 MBytes 9.39 Mbits/sec 0 263 KBytes

[ 4] 8.00-9.00 sec 1.12 MBytes 9.39 Mbits/sec 0 263 KBytes

^C[ 4] 9.00-10.00 sec 955 KBytes 7.86 Mbits/sec 0 264 KBytes

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval Transfer Bandwidth Retr

[ 4] 0.00-10.00 sec 256 MBytes 215 Mbits/sec 4 sender

[ 4] 0.00-10.00 sec 0.00 Bytes 0.00 bits/sec receiver

iperf3: interrupt - the client has terminated

#使用限制

目前发现有一下的一些限制:如果不是docker而是使用containerd作为runtime,需要containerd 1.4版本才能支持。

不能动态更新annotation里面的流量限制大小,更新之后必须删除pod重建。

相关文章:

  • hdr与sdr_sdr和hdr区别
  • gridlayoutmanager实现多样式布局_RecyclerView实现可拖拽的gridview
  • python 分钟数 获取当天_我背着女朋友,用 Python 偷偷抓取了她的行踪
  • -m commit git_「软帝学院」:十年总结常用 Git 命令清单
  • web无序列表去掉点_Python高级基础教程:Day21-30:Web前端概述
  • php缩小png质量变差_php缩小png图片不损失透明色的解决方法
  • 饱和气压与温度的关系_【动手做】制作简易气压计
  • rocketmq怎么保证消息一致性_SpringCloud集成RocketMQ实现可靠消息最终一致性分布式事务方案...
  • 朵朵糖故事机器人怎么更新_我家红薯从不熬粥,加点面,拌点糖,秒变抢手小零食,酥香软糯...
  • 感情沟通出了问题要怎么解决_感情问题咨询:男朋友想分手要怎么调整?
  • java位运算符取反_Java的和,||和|,位运算详解
  • 处理血压信号_打破智能可穿戴设备 “功能鸡肋”,ADI体征信号监测技术助力实现 “健康监测”...
  • e300氛围灯哪里调节_价位差不多,宝马530和奔驰E300,你选谁?
  • 代码批量加引号_字符串包含单引号和双引号写进数据库出错
  • python简单温度转换_python实现简单温度转换的方法
  • classpath对获取配置文件的影响
  • gops —— Go 程序诊断分析工具
  • IDEA常用插件整理
  • iOS小技巧之UIImagePickerController实现头像选择
  • js算法-归并排序(merge_sort)
  • Netty 4.1 源代码学习:线程模型
  • Protobuf3语言指南
  • rc-form之最单纯情况
  • session共享问题解决方案
  • Solarized Scheme
  • vue-router 实现分析
  • Vue小说阅读器(仿追书神器)
  • yii2权限控制rbac之rule详细讲解
  • 案例分享〡三拾众筹持续交付开发流程支撑创新业务
  • 不发不行!Netty集成文字图片聊天室外加TCP/IP软硬件通信
  • 从 Android Sample ApiDemos 中学习 android.animation API 的用法
  • 基于Vue2全家桶的移动端AppDEMO实现
  • 技术:超级实用的电脑小技巧
  • 前端技术周刊 2018-12-10:前端自动化测试
  • 嵌入式文件系统
  • 使用 Xcode 的 Target 区分开发和生产环境
  • 小程序、APP Store 需要的 SSL 证书是个什么东西?
  • 原生js练习题---第五课
  • PostgreSQL 快速给指定表每个字段创建索引 - 1
  • #NOIP 2014# day.1 T2 联合权值
  • #Spring-boot高级
  • (4)logging(日志模块)
  • (附源码)python旅游推荐系统 毕业设计 250623
  • (附源码)ssm高校社团管理系统 毕业设计 234162
  • (数据结构)顺序表的定义
  • (一)pytest自动化测试框架之生成测试报告(mac系统)
  • (中等) HDU 4370 0 or 1,建模+Dijkstra。
  • (轉貼) 2008 Altera 亞洲創新大賽 台灣學生成果傲視全球 [照片花絮] (SOC) (News)
  • **python多态
  • .NET 4.0中的泛型协变和反变
  • .Net 8.0 新的变化
  • .net core MVC 通过 Filters 过滤器拦截请求及响应内容
  • .NET Core 中的路径问题
  • .NET 使用 ILMerge 合并多个程序集,避免引入额外的依赖
  • .one4-V-XXXXXXXX勒索病毒数据怎么处理|数据解密恢复