k8s pod网络限速

在生产环境中有时候需要对pod进行网络限速,具体的步骤如下:
本次测试网络插件为calico

一、确认k8s版本

[root@node1 ~]# kubectl get node
NAME    STATUS   ROLES    AGE   VERSION
node1   Ready    master   42h   v1.18.6
node2   Ready    master   42h   v1.18.6
node3   Ready    master   42h   v1.18.6

二、修改calico参数,添加限速设置

可参考此处

编译配置文件vim /etc/cni/net.d/10-calico.conflist 
{
  "name": "k8s-pod-network",
  "cniVersion": "0.3.1",
  "plugins": [
    {
      "type": "calico",
      "log_level": "info",
      "datastore_type": "kubernetes",
      "nodename": "node1",
      "mtu": 1440,
      "ipam": {

          "type": "calico-ipam"

      },
      "policy": {
          "type": "k8s"
      },
      "kubernetes": {
          "kubeconfig": "/etc/cni/net.d/calico-kubeconfig"
      }
    },
    {
      "type": "portmap",
      "snat": true,
      "capabilities": {"portMappings": true}
    },
    {
      "type": "bandwidth",        #####添加带宽限速参数
      "capabilities": {"bandwidth": true}
    }
  ]
}

三、启动pod测试限速效果

---
apiVersion: v1
kind: Pod
metadata:
  name: qos-dd
  annotations:
    kubernetes.io/ingress-bandwidth: 1M     ###限制进带宽为1M
    kubernetes.io/egress-bandwidth: 1M     ###限制出带宽为1M
spec:
  containers:
    - name: nginx-resource
      image: centos-test:latest     ###自己编译的镜像可使用iperf3命令
      imagePullPolicy: IfNotPresent   ###镜像的拉取策略
      command: ["init"]
      securityContext:
        privileged: true
        capabilities:
          add: ["SYS_ADMIN"]
        runAsUser: 0

启动pod

kubectl apply -f pod-qos.yaml
[root@node1 ~]# kubectl get pod -o wide | grep qos-dd
qos-dd                          1/1     Running   0          28h   172.25.135.51   node3    <none>           <none>

四、进入pod,启动iperf3,在另一端node进行打流测试

如下可知,带宽被限制在1M
[root@node1 ~]# kubectl exec -it qos-dd bash 
[root@qos-dd /]# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 172.25.166.128, port 52622
[  5] local 172.25.135.51 port 5201 connected to 172.25.166.128 port 52624
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec  25.5 MBytes   213 Mbits/sec                  
[  5]   1.00-2.00   sec   172 KBytes  1.41 Mbits/sec                  
[  5]   2.00-3.00   sec   117 KBytes   955 Kbits/sec                  
[  5]   3.00-4.00   sec   117 KBytes   955 Kbits/sec                  
[  5]   4.00-5.00   sec   115 KBytes   944 Kbits/sec                  
[  5]   5.00-6.00   sec   117 KBytes   955 Kbits/sec                  
[  5]   6.00-7.00   sec   118 KBytes   966 Kbits/sec                  
[  5]   7.00-8.00   sec   117 KBytes   955 Kbits/sec                  
[  5]   8.00-9.00   sec   117 KBytes   955 Kbits/sec                  
[  5]   9.00-10.00  sec   117 KBytes   955 Kbits/sec                  
[  5]  10.00-11.00  sec   115 KBytes   944 Kbits/sec                  
[  5]  11.00-12.00  sec   117 KBytes   955 Kbits/sec                  
[  5]  12.00-13.00  sec   117 KBytes   955 Kbits/sec                  
[  5]  13.00-13.08  sec  10.8 KBytes  1.07 Mbits/sec                  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-13.08  sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-13.08  sec  26.9 MBytes  17.2 Mbits/sec                  receiver
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值