菜单
文档breadcrumb arrow Grafana k6breadcrumb arrow 设置breadcrumb arrow 设置分布式 k6breadcrumb arrow 用法breadcrumb arrow 将 k6 Operator 与 Grafana Cloud k6 结合使用
开源

将 k6 Operator 与 Grafana Cloud k6 结合使用

Grafana Cloud k6 是 Grafana Cloud 提供的 k6 服务,可让您使用 k6 的所有功能,同时 Grafana 负责处理您的测试基础设施、存储以及指标聚合和洞察。

使用 k6 Operator 时,您仍然可以利用 Grafana Cloud k6 来访问该平台提供的指标存储和分析功能。

有两种方法可以将 k6 Operator 与 Grafana Cloud k6 结合使用:私有负载区域 (Private Load Zones) 和 Cloud 输出 (Cloud output)。

开始之前

要将 k6 Operator 与 Grafana Cloud k6 结合使用,您需要

私有负载区域 (Private Load Zones)

私有负载区域 (Private Load Zones, PLZ) 是您可以使用 k6 Operator 在您的网络内部托管的负载区域。您可以通过脚本中的名称引用 PLZ,从而在其中启动云测试,测试将在您的 Kubernetes 集群节点中运行。

请参阅 设置私有负载区域 以获取更多详情。

Cloud 输出 (Cloud output)

使用 k6,您可以通过 k6 run --out cloud script.js 命令将测试运行的输出发送到 Grafana Cloud k6。如果您有 Grafana Cloud 帐户,此功能在 k6 Operator 中也可用。

注意

Cloud 输出选项仅支持小于或等于 20 的 parallelism (并行度) 值。

要在 k6 Operator 中使用此选项,请在 YAML 中设置参数

yaml
# ...
script:
  configMap:
    name: '<configmap>'
arguments: --out cloud
# ...

然后,如果您使用 bundle 或 Helm 安装了 operator,请使用以下命令创建 secret

bash
kubectl -n k6-operator-system create secret generic my-cloud-token \
    --from-literal=token=<COPY YOUR TOKEN HERE> && kubectl -n k6-operator-system label secret my-cloud-token "k6cloud=token"

或者,如果您使用 Makefile 安装了 operator,您可以取消注释 config/default/kustomization.yaml 中的 cloud output 部分,并将您的 Grafana Cloud k6 token 复制到那里

yaml
# Uncomment this section if you need cloud output and copy-paste your token
secretGenerator:
  - name: cloud-token
    literals:
      - token=<copy-paste-token-string-here>
    options:
      annotations:
        kubernetes.io/service-account.name: k6-operator-controller
      labels:
        k6cloud: token

更新文件后,运行 make deploy

完成这些步骤后,您可以使用 cloud output 以及 projectIDname 的默认值来运行 k6。

请参阅 Cloud options,了解如何更改 projectIDname 选项的详细信息。