Skip to content

Commit 168863c

Browse files
authored
kubectl ko perf on release-1.11 (#2945)
1 parent ea5f81a commit 168863c

File tree

1 file changed

+290
-0
lines changed

1 file changed

+290
-0
lines changed

dist/images/kubectl-ko

+290
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ OVN_NB_POD=
77
OVN_SB_POD=
88
KUBE_OVN_VERSION=
99
REGISTRY="kubeovn"
10+
OVN_NORTHD_POD=
11+
PERF_TIMES=5
12+
PERF_LABEL="PerfTest"
1013

1114
showHelp(){
1215
echo "kubectl ko {subcommand} [option...]"
@@ -26,6 +29,7 @@ showHelp(){
2629
echo " env-check check the environment configuration"
2730
echo " tuning {install-fastpath|local-install-fastpath|remove-fastpath|install-stt|local-install-stt|remove-stt} {centos7|centos8}} [kernel-devel-version] deploy kernel optimisation components to the system"
2831
echo " reload restart all kube-ovn components"
32+
echo " perf [image] performance test default image is kubeovn/test:v1.12.0"
2933
}
3034

3135
# usage: ipv4_to_hex 192.168.0.1
@@ -578,6 +582,14 @@ getOvnCentralPod(){
578582
exit 1
579583
fi
580584
OVN_SB_POD=$SB_POD
585+
586+
NORTHD_POD=$(kubectl get pod -n kube-system -l ovn-northd-leader=true | grep ovn-central | head -n 1 | awk '{print $1}')
587+
if [ -z "$NORTHD_POD" ]; then
588+
echo "ovn northd not exists"
589+
exit 1
590+
fi
591+
OVN_NORTHD_POD=$NORTHD_POD
592+
581593
image=$(kubectl -n kube-system get pods -l app=kube-ovn-cni -o jsonpath='{.items[0].spec.containers[0].image}')
582594
if [ -z "$image" ]; then
583595
echo "cannot get kube-ovn image"
@@ -941,6 +953,281 @@ env-check(){
941953
done
942954
}
943955

956+
957+
applyTestServer() {
958+
tmpFileName="test-server.yaml"
959+
podName="test-server"
960+
nodeID=$1
961+
imageID=$2
962+
963+
cat <<EOF > $tmpFileName
964+
apiVersion: v1
965+
kind: Pod
966+
metadata:
967+
name: $podName
968+
namespace: $KUBE_OVN_NS
969+
labels:
970+
app: $PERF_LABEL
971+
spec:
972+
containers:
973+
- name: $podName
974+
image: $imageID
975+
imagePullPolicy: IfNotPresent
976+
command: ["sh", "-c"]
977+
args:
978+
- |
979+
qperf &
980+
./test-server.sh
981+
nodeSelector:
982+
kubernetes.io/hostname: $nodeID
983+
EOF
984+
985+
kubectl apply -f $tmpFileName
986+
rm $tmpFileName
987+
}
988+
989+
applyTestHostServer() {
990+
tmpFileName="test-host-server.yaml"
991+
podName="test-host-server"
992+
nodeID=$1
993+
imageID=$2
994+
995+
cat <<EOF > $tmpFileName
996+
apiVersion: v1
997+
kind: Pod
998+
metadata:
999+
name: $podName
1000+
namespace: $KUBE_OVN_NS
1001+
labels:
1002+
app: $PERF_LABEL
1003+
spec:
1004+
hostNetwork: true
1005+
containers:
1006+
- name: $podName
1007+
image: $imageID
1008+
imagePullPolicy: IfNotPresent
1009+
command: ["sh", "-c"]
1010+
args:
1011+
- |
1012+
qperf &
1013+
./test-server.sh
1014+
nodeSelector:
1015+
kubernetes.io/hostname: $nodeID
1016+
EOF
1017+
1018+
kubectl apply -f $tmpFileName
1019+
rm $tmpFileName
1020+
}
1021+
1022+
1023+
applyTestClient() {
1024+
tmpFileName="test-client.yaml"
1025+
local podName="test-client"
1026+
local nodeID=$1
1027+
local imageID=$2
1028+
touch $tmpFileName
1029+
cat <<EOF > $tmpFileName
1030+
apiVersion: v1
1031+
kind: Pod
1032+
metadata:
1033+
name: $podName
1034+
namespace: $KUBE_OVN_NS
1035+
labels:
1036+
app: $PERF_LABEL
1037+
spec:
1038+
containers:
1039+
- name: $podName
1040+
image: $imageID
1041+
imagePullPolicy: IfNotPresent
1042+
command: ["sh", "-c", "sleep infinity"]
1043+
nodeSelector:
1044+
kubernetes.io/hostname: $nodeID
1045+
EOF
1046+
kubectl apply -f $tmpFileName
1047+
rm $tmpFileName
1048+
}
1049+
1050+
applyTestHostClient() {
1051+
tmpFileName="test-host-client.yaml"
1052+
local podName="test-host-client"
1053+
local nodeID=$1
1054+
local imageID=$2
1055+
touch $tmpFileName
1056+
cat <<EOF > $tmpFileName
1057+
apiVersion: v1
1058+
kind: Pod
1059+
metadata:
1060+
name: $podName
1061+
namespace: $KUBE_OVN_NS
1062+
labels:
1063+
app: $PERF_LABEL
1064+
spec:
1065+
hostNetwork: true
1066+
containers:
1067+
- name: $podName
1068+
image: $imageID
1069+
imagePullPolicy: IfNotPresent
1070+
command: ["sh", "-c", "sleep infinity"]
1071+
nodeSelector:
1072+
kubernetes.io/hostname: $nodeID
1073+
EOF
1074+
kubectl apply -f $tmpFileName
1075+
rm $tmpFileName
1076+
}
1077+
1078+
perf(){
1079+
imageID=${1:-"kubeovn/test:v1.12.0"}
1080+
1081+
nodes=($(kubectl get node --no-headers -o custom-columns=NAME:.metadata.name))
1082+
if [[ ${#nodes} -eq 1 ]]; then
1083+
applyTestClient ${nodes[0]} $imageID
1084+
applyTestHostClient ${nodes[0]} $imageID
1085+
applyTestServer ${nodes[0]} $imageID
1086+
applyTestHostServer ${nodes[0]} $imageID
1087+
elif [[ ${#nodes} -le 0 ]]; then
1088+
echo "can't find node in the cluster"
1089+
return
1090+
elif [[ ${#nodes} -ge 2 ]]; then
1091+
applyTestClient ${nodes[1]} $imageID
1092+
applyTestHostClient ${nodes[1]} $imageID
1093+
applyTestServer ${nodes[0]} $imageID
1094+
applyTestHostServer ${nodes[0]} $imageID
1095+
fi
1096+
1097+
isfailed=true
1098+
for i in {0..300}
1099+
do
1100+
if kubectl wait pod --for=condition=Ready -l app=$PERF_LABEL -n kube-system ; then
1101+
isfailed=false
1102+
break
1103+
fi
1104+
sleep 1; \
1105+
done
1106+
1107+
if $isfailed; then
1108+
echo "Error test pod not ready"
1109+
return
1110+
fi
1111+
1112+
local serverIP=$(kubectl get pod test-server -n $KUBE_OVN_NS -o jsonpath={.status.podIP})
1113+
local hostserverIP=$(kubectl get pod test-host-server -n $KUBE_OVN_NS -o jsonpath={.status.podIP})
1114+
1115+
echo "Start doing pod network performance"
1116+
unicastPerfTest test-client $serverIP
1117+
1118+
echo "Start doing host network performance"
1119+
unicastPerfTest test-host-client $hostserverIP
1120+
1121+
echo "Start doing pod multicast network performance"
1122+
multicastPerfTest
1123+
1124+
echo "Start doing leader recover time test"
1125+
checkLeaderRecover
1126+
1127+
kubectl delete pods -l app=$PERF_LABEL -n $KUBE_OVN_NS
1128+
}
1129+
1130+
unicastPerfTest() {
1131+
clientPodName=$1
1132+
serverIP=$2
1133+
echo "=================================== unicast perfromance test ============================================================="
1134+
printf "%-15s %-15s %-15s %-15s %-15s %-15s\n" "Size" "TCP Latency" "TCP Bandwidth" "UDP Latency" "UDP Lost Rate" "UDP Bandwidth"
1135+
for size in "64" "128" "512" "1k" "4k"
1136+
do
1137+
output=$(kubectl exec $clientPodName -n $KUBE_OVN_NS -- qperf -t $PERF_TIMES $serverIP -ub -oo msg_size:$size -vu tcp_lat udp_lat 2>&1)
1138+
tcpLat="$(echo $output | grep -oP 'tcp_lat: latency = \K[\d.]+ (us|ms|sec)')"
1139+
udpLat="$(echo $output | grep -oP 'udp_lat: latency = \K[\d.]+ (us|ms|sec)')"
1140+
kubectl exec $clientPodName -n $KUBE_OVN_NS -- iperf3 -c $serverIP -u -t $PERF_TIMES -i 1 -P 10 -b 1000G -l $size > temp_perf_result.log 2> /dev/null
1141+
udpBw=$(cat temp_perf_result.log | grep -oP '\d+\.?\d* [KMG]bits/sec' | tail -n 1)
1142+
udpLostRate=$(cat temp_perf_result.log | grep -oP '\(\d+(\.\d+)?%\)' | tail -n 1)
1143+
1144+
kubectl exec $clientPodName -n $KUBE_OVN_NS -- iperf3 -c $serverIP -t $PERF_TIMES -i 1 -P 10 -l $size > temp_perf_result.log 2> /dev/null
1145+
tcpBw=$(cat temp_perf_result.log | grep -oP '\d+\.?\d* [KMG]bits/sec' | tail -n 1)
1146+
printf "%-15s %-15s %-15s %-15s %-15s %-15s\n" "$size" "$tcpLat" "$tcpBw" "$udpLat" "$udpLostRate" "$udpBw"
1147+
done
1148+
echo "========================================================================================================================="
1149+
rm temp_perf_result.log
1150+
}
1151+
1152+
multicastPerfTest() {
1153+
clientNode=$(kubectl get pod test-client -n $KUBE_OVN_NS -o jsonpath={.spec.nodeName})
1154+
serverNode=$(kubectl get pod test-server -n $KUBE_OVN_NS -o jsonpath={.spec.nodeName})
1155+
clientNs=$(kubectl ko vsctl $clientNode --column=external_ids find interface external_ids:iface-id=test-client.$KUBE_OVN_NS | awk -F 'pod_netns=' '{print $2}' | grep -o 'cni-[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}')
1156+
serverNs=$(kubectl ko vsctl $serverNode --column=external_ids find interface external_ids:iface-id=test-server.$KUBE_OVN_NS | awk -F 'pod_netns=' '{print $2}' | grep -o 'cni-[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}')
1157+
clientovsPod=$(kubectl get pod -owide -A |grep ovs-ovn | grep $clientNode | awk '{print $2}')
1158+
kubectl exec $clientovsPod -n kube-system -- ip netns exec $clientNs ip maddr add 01:00:5e:00:00:64 dev eth0
1159+
serverovsPod=$(kubectl get pod -owide -A |grep ovs-ovn | grep $serverNode | awk '{print $2}')
1160+
kubectl exec $serverovsPod -n kube-system -- ip netns exec $serverNs ip maddr add 01:00:5e:00:00:64 dev eth0
1161+
genMulticastPerfResult test-server
1162+
kubectl exec $clientovsPod -n kube-system -- ip netns exec $clientNs ip maddr del 01:00:5e:00:00:64 dev eth0
1163+
kubectl exec $serverovsPod -n kube-system -- ip netns exec $serverNs ip maddr del 01:00:5e:00:00:64 dev eth0
1164+
}
1165+
1166+
genMulticastPerfResult() {
1167+
serverName=$1
1168+
1169+
start_server_cmd="iperf -s -B 224.0.0.100 -i 1 -u"
1170+
kubectl exec $serverName -n $KUBE_OVN_NS -- $start_server_cmd > $serverName.log &
1171+
1172+
echo "=================================== multicast perfromance test ========================================================="
1173+
printf "%-15s %-15s %-15s %-15s\n" "Size" "UDP Latency" "UDP Lost Rate" "UDP Bandwidth"
1174+
for size in "64" "128" "512" "1k" "4k"
1175+
do
1176+
kubectl exec test-client -n $KUBE_OVN_NS -- iperf -c 224.0.0.100 -u -T 32 -t $PERF_TIMES -i 1 -b 1000G -l $size > /dev/null
1177+
udpBw=$(cat $serverName.log | grep -oP '\d+\.?\d* [KMG]bits/sec' | tail -n 1)
1178+
udpLostRate=$(cat $serverName.log |grep -oP '\(\d+(\.\d+)?%\)' | tail -n 1)
1179+
kubectl exec test-client -n $KUBE_OVN_NS -- iperf -c 224.0.0.100 -u -T 32 -t $PERF_TIMES -i 1 -l $size > /dev/null
1180+
udpLat=$(cat $serverName.log | grep -oP '\d+\.?\d* ms' | tail -n 1)
1181+
printf "%-15s %-15s %-15s %-15s\n" "$size" "$udpLat" "$udpLostRate" "$udpBw"
1182+
done
1183+
1184+
echo "========================================================================================================================="
1185+
1186+
pids=($(ps -ef | grep "$start_server_cmd" | grep -v grep | awk '{print $2}'))
1187+
kill ${pids[1]}
1188+
1189+
rm $serverName.log
1190+
}
1191+
1192+
checkLeaderRecover() {
1193+
getOvnCentralPod
1194+
getPodRecoverTime "nb"
1195+
sleep 5
1196+
getOvnCentralPod
1197+
getPodRecoverTime "sb"
1198+
sleep 5
1199+
getOvnCentralPod
1200+
getPodRecoverTime "northd"
1201+
1202+
}
1203+
1204+
getPodRecoverTime(){
1205+
component_name=$1
1206+
start_time=$(date +%s.%N)
1207+
echo "Delete ovn central $component_name pod"
1208+
if [[ $component_name == "nb" ]]; then
1209+
kubectl delete pod $OVN_NB_POD -n kube-system
1210+
elif [[ $component_name == "sb" ]]; then
1211+
kubectl delete pod $OVN_SB_POD -n kube-system
1212+
elif [[ $component_name == "northd" ]]; then
1213+
kubectl delete pod $OVN_NORTHD_POD -n kube-system
1214+
fi
1215+
echo "Waiting for ovn central $component_name pod running"
1216+
replicas=$(kubectl get deployment -n kube-system ovn-central -o jsonpath={.spec.replicas})
1217+
availableNum=$(kubectl get deployment -n kube-system | grep ovn-central | awk {'print $4'})
1218+
while [ $availableNum != $replicas ]
1219+
do
1220+
availableNum=$(kubectl get deployment -n kube-system | grep ovn-central | awk {'print $4'})
1221+
usleep 0.001
1222+
done
1223+
1224+
end_time=$(date +%s.%N)
1225+
elapsed_time=$(echo "$end_time - $start_time" | bc)
1226+
echo "================================ OVN $component_name recover takes $elapsed_time s =================================="
1227+
}
1228+
1229+
1230+
9441231
if [ $# -lt 1 ]; then
9451232
showHelp
9461233
exit 0
@@ -981,6 +1268,9 @@ case $subcommand in
9811268
env-check)
9821269
env-check
9831270
;;
1271+
perf)
1272+
perf "$@"
1273+
;;
9841274
*)
9851275
showHelp
9861276
exit 1

0 commit comments

Comments
 (0)