基准测试
概述
K9s 集成了由才华横溢的 Jaana Dogan 开发的 Hey 工具。Hey
是一个命令行工具,用于对 HTTP 端点进行基准测试,类似于 AB bench。这个初步功能目前支持对端口转发和服务进行基准测试(注意:该功能尚处于早期开发阶段!)。
要设置端口转发,您需要导航到 Pod 视图,选择一个 Pod 和一个暴露了特定端口的容器。使用 SHIFT-F
会弹出一个对话框,允许您指定一个本地端口进行转发。确认后,您可以导航到 PortForward 视图(别名 pf
),其中列出了您活动的端口转发。选择一个端口转发并按 b
键,将对该 HTTP 端点运行基准测试。要查看基准测试的运行结果,请转到 Benchmarks 视图(别名 be
)。现在您应该能够选择一个基准测试,并通过按 <ENTER>
键查看运行的统计详情。注意:端口转发仅在 K9s 会话期间有效,退出后将终止。
最初,基准测试将使用以下默认值运行:
- 并发级别:1
- 请求数量:200
- HTTP 方法:GET
- 路径:/
PortForward 视图由一个名为 $XDG_DATA_HOME/k9s/clusters/clusterX/contextY/benchmarks.yaml
的基准测试配置文件支持。您连接的每个上下文(context)都有其自己的基准测试配置文件。对此文件的更改应会自动更新 PortForward 视图,以反映您希望如何运行基准测试。生成的基准测试报告存储在 $XDG_STATE_HOME/k9s/clusters/clusterX/contextY/xxx.txt
中。
请注意,此文件在后续版本中很可能会发生变化!
示例
# $XDG_DATA_HOME/k9s/clusters/clusterX/contextY/benchmarks.yaml
benchmarks:
# Indicates the default concurrency and number of requests setting if a container or service rule does not match.
defaults:
# One concurrent connection
concurrency: 1
# Number of requests that will be sent to an endpoint
requests: 1000
containers:
# Containers section allows you to configure your http container's endpoints and benchmarking settings.
# NOTE: the container ID syntax uses namespace/pod-name:container-name
default/nginx:nginx:
# Benchmark a container named nginx using POST HTTP verb using https://:port/bozo URL and headers.
concurrency: 1
requests: 10000
http:
path: /bozo
method: POST
body:
{"fred":"blee"}
header:
Accept:
- text/html
Content-Type:
- application/json
services:
# Similarly you can Benchmark an HTTP service exposed either via NodePort, LoadBalancer types.
# Service ID is ns/svc-name
default/nginx:
# Set the concurrency level
concurrency: 5
# Number of requests to be sent
requests: 500
http:
method: GET
# This setting will depend on whether service is NodePort or LoadBalancer. NodePort may require vendor port tunneling setting.
# Set this to a node if NodePort or LB if applicable. IP or dns name.
host: 1.2.3.4
path: /bumblebeetuna
auth:
user: jean-baptiste-emmanuel
password: Zorg!
