Skip to main content

Deploy to Kubernetes

Overview

This document will help you understand how to deploy NBomber load test to Kubernetes. In the image above, you can see a multi-resource deployment used to run NBomber load tests. Let’s now look at what is included in a single load test deployment:

  • NBomber K8sDemo - We created a minimal NBomber load test project, containerized it, and published it to Docker Hub.
  • ConfigMap containing the NBomber JSON Config file which will be consumed by NBomber load test. This configuration is used to set up the load test: override load simulation settings if needed, configure cluster parameters, and specify the connection string for the NATS message broker.
  • Job that spins up 2 containers running the NBomber load test scenario.
  • NATS message broker dedicated to NBomber cluster communication.

CI/CD pipiline execution

Now let’s review the execution flow of a potential CI/CD pipeline job that can run multiple load tests in parallel and then clean up the associated resources afterward:

  1. The CI/CD job applies the Kubernetes manifest to start the load test. Kubernetes will create: NATS, Job and ConfigMap.
kubectl apply -f my-test-1.yaml
  1. The k8s Job schedules 2 containers (Coordinator + Agent) and mounts the ConfigMap containing the JSON Config with NBomber Cluster and Scenario settings for these containers.
  2. After the load test scenario finishes, the containers will stop but are not automatically removed.
  3. (Optional) A CLI procedure may wait for the K8s Job to complete and then extract the HTML report.
# --timeout=600s - waits up to 600 seconds (10 minutes). Adjust as needed.

kubectl wait --for=condition=complete --timeout=600s -n <namespace> job/<job-name>

After this, the job should find the pod which was the Coordinator (it will log the message: "NBomber started as Coordinator") and then extract the HTML report from the ReportFolder. The NBomber logs will display the full path to the ReportFolder.

  1. A CLI job should destroy all allocated resources for this load test:
kubectl delete -f my-test-1.yaml
info

It’s important to note that the ConfigMap nb-config-my-test-1, Job k8sdemo-job-my-test-1 and NATS broker are postfixed with the load test name: my-test-1. This prevents naming collisions when multiple deployments (with multiple NATS instances) run in parallel and ensures all resources are grouped for a specific load test. Once the test is finished, cleanup can be performed safely.