在 CentOS 上进行 Kubernetes 性能测试
一、目标与范围
二、环境与工具准备
三、快速验证流程(功能与基线)
kubectl get nodes 均为 Ready。kubectl get pods -n kube-system 运行正常。kubectl create deployment nginx --image=nginx --replicas=3kubectl expose deployment nginx --type=NodePort --port=80curl http://<任一节点IP>:<NodePort> 返回 Nginx 欢迎页。kubectl scale deployment nginx --replicas=5kubectl top nodes、kubectl top podskubectl describe pod <pod>,kubectl logs <pod>四、控制面与调度性能测试(clusterloader2)
# 1) 编译
git clone https://github.com/kubernetes/perf-tests
cd perf-tests/clusterloader2 && go build -o clusterloader ./cmd/
# 2) 环境变量(示例)
export KUBE_CONFIG=$HOME/.kube/config
export PROVIDER=local
export TEST_CONFIG=configs/examples/density/config.yaml
export REPORT_DIR=./reports
export LOG_FILE=logs/run.log
# 3) 执行
./clusterloader \
--kubeconfig=$KUBE_CONFIG \
--provider=$PROVIDER \
--testconfig=$TEST_CONFIG \
--report-dir=$REPORT_DIR \
--alsologtostderr 2>&1 | tee $LOG_FILE
五、大规模模拟与弹性场景(kubemark + HPA)
kubectl taint nodes <node> role=real:NoSchedulekubectl label nodes <node> role=realapiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: nginx-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nginx
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
k6 run script.js 或 wrk -t12 -c400 -d60s http://<svc>/,观察 HPA 扩缩容、Pod 启动延迟与成功率。