Kube-OVN 可以通过 Pod 上的 annotation ovn.kubernetes.io/ingress_rateovn.kubernetes.io/egress_rate 来控制 Pod 的双向带宽,其单位为 Mbit/s。我们可以在创建时设定 QoS 也可以在 Pod 运行时通过更改 annotation 来动态调整 QoS。

创建 Pod 时设定 QoS

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: qos
  5. namespace: ls1
  6. annotations:
  7. ovn.kubernetes.io/ingress_rate: "3"
  8. ovn.kubernetes.io/egress_rate: "1"
  9. spec:
  10. containers:
  11. - name: qos
  12. image: nginx:alpine

动态调整 QoS

  1. kubectl annotate --overwrite pod nginx-74d5899f46-d7qkn ovn.kubernetes.io/ingress_rate=3

测试 QoS 调整

部署性能测试需要的容器

  1. kind: DaemonSet
  2. apiVersion: apps/v1
  3. metadata:
  4. name: perf
  5. namespace: ls1
  6. labels:
  7. app: perf
  8. spec:
  9. selector:
  10. matchLabels:
  11. app: perf
  12. template:
  13. metadata:
  14. labels:
  15. app: perf
  16. spec:
  17. containers:
  18. - name: nginx
  19. image: index.alauda.cn/alaudaorg/perf

进入其中一个 Pod 并开启 iperf3 server

  1. [root@node2 ~]# kubectl exec -it perf-4n4gt -n ls1 sh
  2. / # iperf3 -s
  3. -----------------------------------------------------------
  4. Server listening on 5201
  5. -----------------------------------------------------------

进入另一个 Pod 请求之前的 Pod

  1. [root@node2 ~]# kubectl exec -it perf-d4mqc -n ls1 sh
  2. / # iperf3 -c 10.66.0.12
  3. Connecting to host 10.66.0.12, port 5201
  4. [ 4] local 10.66.0.14 port 51544 connected to 10.66.0.12 port 5201
  5. [ ID] Interval Transfer Bandwidth Retr Cwnd
  6. [ 4] 0.00-1.00 sec 86.4 MBytes 725 Mbits/sec 3 350 KBytes
  7. [ 4] 1.00-2.00 sec 89.9 MBytes 754 Mbits/sec 118 473 KBytes
  8. [ 4] 2.00-3.00 sec 101 MBytes 848 Mbits/sec 184 586 KBytes
  9. [ 4] 3.00-4.00 sec 104 MBytes 875 Mbits/sec 217 671 KBytes
  10. [ 4] 4.00-5.00 sec 111 MBytes 935 Mbits/sec 175 772 KBytes
  11. [ 4] 5.00-6.00 sec 100 MBytes 840 Mbits/sec 658 598 KBytes
  12. [ 4] 6.00-7.00 sec 106 MBytes 890 Mbits/sec 742 668 KBytes
  13. [ 4] 7.00-8.00 sec 102 MBytes 857 Mbits/sec 764 724 KBytes
  14. [ 4] 8.00-9.00 sec 97.4 MBytes 817 Mbits/sec 1175 764 KBytes
  15. [ 4] 9.00-10.00 sec 111 MBytes 934 Mbits/sec 1083 838 KBytes
  16. - - - - - - - - - - - - - - - - - - - - - - - - -
  17. [ ID] Interval Transfer Bandwidth Retr
  18. [ 4] 0.00-10.00 sec 1010 MBytes 848 Mbits/sec 5119 sender
  19. [ 4] 0.00-10.00 sec 1008 MBytes 846 Mbits/sec receiver
  20.  
  21. iperf Done.
  22. / #

修改第一个 Pod 的出口带宽 QoS

  1. [root@node2 ~]# kubectl annotate --overwrite pod perf-4n4gt -n ls1 ovn.kubernetes.io/egress_rate=30

再次从第二个 Pod 测试第一个 Pod 带宽

  1. / # iperf3 -c 10.66.0.12
  2. Connecting to host 10.66.0.12, port 5201
  3. [ 4] local 10.66.0.14 port 52372 connected to 10.66.0.12 port 5201
  4. [ ID] Interval Transfer Bandwidth Retr Cwnd
  5. [ 4] 0.00-1.00 sec 3.66 MBytes 30.7 Mbits/sec 2 76.1 KBytes
  6. [ 4] 1.00-2.00 sec 3.43 MBytes 28.8 Mbits/sec 0 104 KBytes
  7. [ 4] 2.00-3.00 sec 3.50 MBytes 29.4 Mbits/sec 0 126 KBytes
  8. [ 4] 3.00-4.00 sec 3.50 MBytes 29.3 Mbits/sec 0 144 KBytes
  9. [ 4] 4.00-5.00 sec 3.43 MBytes 28.8 Mbits/sec 0 160 KBytes
  10. [ 4] 5.00-6.00 sec 3.43 MBytes 28.8 Mbits/sec 0 175 KBytes
  11. [ 4] 6.00-7.00 sec 3.50 MBytes 29.3 Mbits/sec 0 212 KBytes
  12. [ 4] 7.00-8.00 sec 3.68 MBytes 30.9 Mbits/sec 0 294 KBytes
  13. [ 4] 8.00-9.00 sec 3.74 MBytes 31.4 Mbits/sec 0 398 KBytes
  14. [ 4] 9.00-10.00 sec 3.80 MBytes 31.9 Mbits/sec 0 526 KBytes
  15. - - - - - - - - - - - - - - - - - - - - - - - - -
  16. [ ID] Interval Transfer Bandwidth Retr
  17. [ 4] 0.00-10.00 sec 35.7 MBytes 29.9 Mbits/sec 2 sender
  18. [ 4] 0.00-10.00 sec 34.5 MBytes 29.0 Mbits/sec receiver
  19.  
  20. iperf Done.
  21. / #