Kubernetes 网络性能测试-calico插件环境
本次主要针对calico网络插件k8s集群的网络性能进行摸底及测试方法探索实践。
1. 测试准备
1.1 测试环境
测试环境为VMware Workstation虚拟机搭建的一套K8S环境,版本为1.28.2,网络插件使用calico,版本为3.28.0。
hostname | ip | 配置 | 备注 |
---|---|---|---|
master | 192.168.0.61 | 2C4G | master |
node1 | 192.168.0.62 | 2C4G | worker |
node2 | 192.168.0.63 | 2C4G | worker |
已经部署测试应用sample-webapp,三个副本:
root@master1:~# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 15d
sample-webapp ClusterIP 10.106.172.112 <none> 8000/TCP 47s
root@master1:~# kubectl get pod
NAME READY STATUS RESTARTS AGE
sample-webapp-77745d4db-57rbx 1/1 Running 0 50s
sample-webapp-77745d4db-vprjc 1/1 Running 0 50s
sample-webapp-77745d4db-wltzl 1/1 Running 0 12s
备注:
- 本文测试环境,master节点取消了NoSchedule的Taints,使得master节点也可以调度业务pod。
- 测试用到的demo程序可以访问以下仓库获取:https://gitee.com/lldhsds/distributed-load-testing-using-k8s.git,仅部署sample-webapp即可。当然也可以使用其他应用进行测试,比如nginx等。
1.2 测试场景
- Kubernetes 集群 node 节点上通过 Cluster IP 方式访问
- Kubernetes 集群内部通过 service 访问
- Kubernetes 集群外部通过 metalLB暴露的地址访问
1.3 测试工具
- curl
- 测试程序:sample-webapp,源码见 Github kubernetes 的分布式负载测试。
1.4 测试说明
通过向 sample-webapp 发送 curl 请求获取响应时间,直接 curl 后的结果为:
root@master1:~# curl "http://10.106.172.112:8000"
Welcome to the "Distributed Load Testing Using Kubernetes" sample web app
2. 网络延迟测试
2.1 Kubernetes 集群 node 节点上通过 Cluster IP 访问
测试命令
curl -o /dev/null -s -w '%{time_connect} %{time_starttransfer} %{time_total}' "http://10.106.172.112:8000"
测试10组数据,取平均结果:
[root@k8s-node1 ~]# echo "time_connect time_starttransfer time_total"; for i in {1..10}; do curl -o /dev/null -s -w '%{time_connect} %{time_starttransfer} %{time_total}\n' "http://10.106.172.112:8000"; done
time_connect time_starttransfer time_total
0.000362 0.001538 0.001681
0.000456 0.002825 0.003137
0.000744 0.003152 0.003394
0.000388 0.001750 0.001847
0.000617 0.002405 0.003527
0.000656 0.002153 0.002390
0.000204 0.001597 0.001735
0.000568 0.002759 0.003117
0.000826 0.002278 0.002463
0.000582 0.002062 0.002120
平均响应时间:2.541 ms
指标说明:
-
time_connect:建立到服务器的 TCP 连接所用的时间
-
time_starttransfer:在发出请求之后,Web 服务器返回数据的第一个字节所用的时间
-
time_total:完成请求所用的时间
2.2 Kubernetes 集群内部通过 service 访问
# 进入测试的客户端
root@master1:~# kubectl exec -it test-78bcb7b45d-t9mvw -- /bin/bash
# 执行测试
test-78bcb7b45d-t9mvw:/# echo "time_connect time_starttransfer time_total"; for i in {1..10}; do curl -o /dev/null -s -w '%{time_connect} %{time_starttransfer} %{time_total}\n' "http://sample-webapp:8000/"; done
time_connect time_starttransfer time_total
0.001359 0.004808 0.005001
0.001470 0.003394 0.003508
0.001888 0.003702 0.004018
0.001630 0.003267 0.003622
0.001621 0.003235 0.003491
0.001008 0.002891 0.002951
0.001508 0.003137 0.003313
0.004427 0.006035 0.006293
0.001512 0.002924 0.002962
0.001649 0.003774 0.003981
平均响应时间:约3.914 ms
2.3 在外部通过ingress 访问
本文使用LB service类型,也可以将service改为NodePort类型进行测试。
root@master1:~# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 15d
sample-webapp LoadBalancer 10.98.247.190 192.168.0.242 80:31401/TCP 6m16s
在外部的客户端添加域名解析sample-webapp.test.com 192.168.0.242
,进行访问测试:
$ echo "time_connect time_starttransfer time_total"; for i in {
1..10}; do curl -o /dev/null -s -w '%{time_connect} %{time_starttransfer} %{time_total}\n' "http://sample-webapp.test.com/"; done
time_connect time_starttransfer time_total
0.015586 0.017507 0.028004
0.039582 0.042034 0.052532
0.006702 0.008856 0.019461