Load Testing in Kubernetes with k6 and Testkube

May 30, 2022
4 min
Bruno Lopes
Product Leader
Learn how to harness the power of k6 load testing in Kubernetes with Testkube's CLI and API.
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

Want to learn more about this topic? Check out our Office Hours sessions!

Start Using Testkube for Free Today

## Introduction: k6 Load Testing

Kubernetes clusters are designed for reliability and a degree of “self-healing,” including scaling horizontally with more pods running in parallel, to handle sudden bursts of demand. But like all other parts of your application, from the UI to the APIs that power each service, you can enhance your baseline availability by load testing your infrastructure and understanding what happens.

One tool that helps you with that — and undoubtedly one of the most popular load testing tools today — is [k6]( The open-source project is cloud native-friendly and supported by a large community of developers and testers — not to mention the 2021 [acquisition]( by [Grafana Labs](, the leader in infrastructure observability tools. The open-source project has 16,000+ stars on GitHub and more than 100 active contributors.

## The state of testing Kubernetes clusters with k6

The k6 team has previously announced their intention to make k6 more friendly toward cloud-native technology like Kubernetes, but support is still in experimental stages and its integration is fairly complex if you don’t have a strong DevOps background.

In the current best practices guide ([Running distributed k6 tests on Kubernetes](, you need to clone a GitHub repository to use an operator which then you can deploy manually to your cluster using Make and Kustomize.

To view the results of a particular load test, you can run `kubectl logs [POD]` to see k6’s output but there are no instructions for seeing detailed performance testing metrics and dashboards for your tests, although it’s certainly possible with enough customization.

Working with an operator like this one will add complexity to your testing process and your CI/CD pipelines. Also it still won’t allow you to store or aggregate your results over time. Good news is that Testkube does a great job of adapting K6 into Kubernetes, solving all of those problems mentioned above.

## How Testkube does Kubernetes load testing differently

[Testkube]( tries to solve both of those problems by tackling the process of executing a k6 load test through the Testkube CLI and API.

With Testkube, users create and run commands with `kubectl testkube create test…` and `kubectl testkube run test…`, respectively. When running the Testkube CLI — or when the CI/CD pipeline does it for you — it sends these tests to the Testkube API running on the cluster, which in turn manages the resources required to run them. Once your tests finish, users can use Testkube’s UI to see the results if they would like.

K6 load testing web dashboard

With this process, you can aggregate any number of k6 test results in one place, and they’re stored alongside any other application tests you might be running, like Postman, Cypress, or SoapUI. You simplify the chain of load testing -> trying improvements -> testing your improvements, or even automate it entirely using CI/CD, to dramatically improve your performance testing lifecycle.

And you’ll get a much better sense of how your application will perform if you get the “[hug of death](” from Hacker News or Reddit.

Let’s walk through all the steps together.

## Get Testkube

The fastest way to install Testkube is by signing up for our free [Testkube Cloud]( account.

With only a few commands, you’re now ready to start testing against your cluster!

Our [k6 executor](, which takes your k6 load testing scripts and launches them directly inside of your cluster, comes enabled by default, so there’s nothing else for you to manage or administer.

## Create your k6 load test and run it

I won’t cover the nuances of writing a k6 load testing script here - the [k6 documentation]( is a fantastic resource for that—but instead, let’s use an [example script]( to showcase how Kubernetes load testing works with Testkube and k6.

-- CODE language-bash --
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
 stages: [
   { duration: '5s', target: 20 },
   { duration: '5s', target: 10 },
export default function () {
 const res = http.get('');
 check(res, { 'status was 200': (r) => r.status == 200 });

Save this file on your local machine as `k6-test.js`.

Now that you have the k6 load test script, you can execute it in just two steps:

First you need to define the test as the “k6/script” type and then you can run it:

-- CODE language-bash --
$ kubectl testkube create test --file path/to/your/k6-test.js --type "k6/script" --name k6-test
$ kubectl testkube run test k6-test -f

## View logs and results in the Testkube dashboard

Testkube handles every part of running, managing, storing, and visualizing your k6 load testing scripts. Once a single execution finishes, it’s available for viewing on your Testkube dashboard.

Setup K6 test to run cloud native

## What’s next?

Now that you’ve run a k6 load test against your Kubernetes application for the first time, you’re ready to add it as a step in your CI/CD pipeline alongside any other UI/API tests you might have already run.

With load testing built into your development lifecycle and all your results condensed into a single UI, you can start to understand how your cloud-native application performs over time and through significant change. Discover regressions, dig into root causes, and make optimizations.

I would love to hear all about your [k6 load testing]( results and wins—the entire [Testkube]( team, plus a vibrant community of fellow Kubernetes testers, are on [Slack]( Let me know what’s working for you and where you see more opportunities in the future. We’re just getting started in building the most comprehensive (and friendliest!) cloud-native testing framework for Kubernetes so feel free to follow us on [Twitter @testkube_io](

Bruno Lopes
Product Leader
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL