最近更新时间:2021-03-26 11:37:55
金山云容器服务原生支持对Pod进行带宽限速。本文档讲介绍如何在KCE集群设置Pod带宽限速。
新建Pod,通过annotations
的方式设置Pod出入带宽
kubernetes.io/egress-bandwidth
:定义Pod的出向带宽,如240M,这里单位是Mbit,kubernetes.io/ingress-bandwidth
:定义Pod的入向带宽,如400M,这里单位是MbitYaml示例如下:
apiVersion: v1
kind: Pod
metadata:
annotations:
kubernetes.io/egress-bandwidth: 240M
kubernetes.io/ingress-bandwidth: 400M
name: iperf3-4
namespace: default
spec:
containers:
- args:
- iperf3
- -s
image: networkstatic/iperf3
imagePullPolicy: Always
name: iperf3-4
resources: {}
dnsPolicy: ClusterFirst
你可以通过以下两种方式验证:
tc qdisc show
返回如下示例代表设置成功
qdisc tbf 1: dev vethbab31be6 root refcnt 2 rate 400Mbit burst 256Mb lat 25.0ms
qdisc ingress ffff: dev vethbab31be6 parent ffff:fff1 ----------------
qdisc tbf 1: dev bwp91fff0f8f685 root refcnt 2 rate 240Mbit burst 256Mb lat 25.0ms
iperf3 -c <服务 IP> -i 1
结果如下:
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 10.0.11.85, port 45690
[ 5] local 10.0.11.207 port 5201 connected to 10.0.11.85 port 45692
[ ID] Interval Transfer Bandwidth
[ 5] 0.00-1.00 sec 243 MBytes 2.03 Gbits/sec
[ 5] 1.00-2.00 sec 49.2 MBytes 413 Mbits/sec
[ 5] 2.00-3.00 sec 27.3 MBytes 229 Mbits/sec
[ 5] 3.00-4.00 sec 27.3 MBytes 229 Mbits/sec
[ 5] 4.00-5.00 sec 27.4 MBytes 230 Mbits/sec
[ 5] 5.00-6.00 sec 27.3 MBytes 229 Mbits/sec
[ 5] 6.00-7.00 sec 27.3 MBytes 229 Mbits/sec
[ 5] 7.00-8.00 sec 27.3 MBytes 229 Mbits/sec
[ 5] 8.00-9.00 sec 27.3 MBytes 229 Mbits/sec
[ 5] 9.00-10.00 sec 27.3 MBytes 229 Mbits/sec
[ 5] 10.00-10.06 sec 1.49 MBytes 225 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth
[ 5] 0.00-10.06 sec 0.00 Bytes 0.00 bits/sec sender
[ 5] 0.00-10.06 sec 512 MBytes 427 Mbits/sec receiver
纯净模式