JMeter + K8s: How to Run Tests Efficiently With Testkube

Jan 20, 2023
5 min
read
With Testkube and JMeter, we can unleash new ways to efficiently run performance tests for our apps in Kubernetes.
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!

Get Started with Testkube Pro

Non-functional aspects can differentiate between a successful product and a total failure - performance being one of them. Performance tests aim to understand the product's performance under specific loads, and its limits. Load tests can identify areas worth optimizing, possible bottlenecks. Stress tests will tell you at which point the application will break - they can help you build confidence in the product's reliability and performance.

Different tools help developers and testers across the globe execute these types of tests, including JMeter - a tool created by Apache to load test functional behavior and gauge software performance. However, designing our actual performance tests with JMeter to answer specific questions and analyzing test results can be challenging, especially when Kubernetes is involved. Fortunately, this whole process can be simplified using Testkube.

Testkube is Kubernetes-native testing framework for testers and developers. It acts as an executor so you can orchestrate, run, and display tests and test results for your code in a Kubernetes environment.
Whether you're new to the K8s ecosystem or a seasoned pro, Testkube lets you focus on testing without having to complicate yourself, your processes, or your pipelines.

After Testkube's v1.7 release, you can now run JMeter tests with Testkube (additionally to already available K6 and Artillery executors), and the process is pretty straightforward. Let's go over the process in this short tutorial.

Prerequisites

If you don’t have Testkube installed yet, you can get started right away at http://cloud.testkube.io.

If you have Testkube installed already, all you need to do is save your JMeter tests into a `.jmx` file. You can then create your Testkube Test using any of the available methods - using Testkube's Dashboard, CLI, or Test CRD.

Now that you've got Testkube ready, let's run some JMeter tests. Let's use this jmx file as an example.

This file is already in a git repository so you can use `Git file` as your Test Source.

You have the following options:

Option 1: Creating a JMeter Test with Dashboard

All you need to do is to set the test's Name, Type (`jmeter/test`), Test Source (Git file), and fill in repository-related details (repository URL, branch, and file path):

You can then create the test, and run it:

Option 2: Creating a JMeter Test with CLI

You can also use Testkube CLI to do exactly the same thing by using `testkube create test`.

CLI provides corresponding arguments to the ones visible in Dashboard.

You will need to set the following parameters:

  • Test name: `--name jmeter-test-example`
  • Test type: `--type jmeter/test`
  • Test content type (also named Test Source in Dashboard): `--test-content-type git-file`
  • Repository URL: `--git-uri https://github.com/kubeshop/testkube.git`
  • Git branch: `--git-branch main`
  • Test (.jmx file) path in the repository: `--git-path test/jmeter/executor-tests/jmeter-executor-smoke.jmx`

After filling in all the parameters, your final command should look something like this:

```bash

testkube create test --name jmeter-test-example --type jmeter/test --test-content-type git-file --git-uri https://github.com/kubeshop/testkube.git --git-branch main --git-path test/jmeter/executor-tests/jmeter-executor-smoke.jmx

```

You can then run the test with `testkube run test` using your test name - in our example it will be: `testkube run test jmeter-test-example`.

Optionally, you can add the `-f` (`follow`) to get the execution result directly.

Option 3: Creating a JMeter Test with test CRD

So what if you want to use the Test Custom Resource Definition? The easiest option is to use Testkube's CLI, and add `--crd-only` to the previous `testkube create test command`. This should look like this:

```bash

testkube create test --name jmeter-test-example --type jmeter/test --test-content-type git-file --git-uri https://github.com/kubeshop/testkube.git --git-branch main --git-path test/jmeter/executor-tests/jmeter-executor-smoke.jmx --crd-only

```

You can then save it to a YAML file and apply it using the usual `kubectl apply`.

It’s also possible to get a Test CRD from Dashboard - just go to Test Settings, and then Definition:

Option 4: Creating a JMeter Test from local .jmx file

What if you have the .jmx file saved locally? The `File` Test Source can be used. It allows you to select your local file, and then upload it while creating the test:

Adjusting Your JMeter Executor With Job Templates

The example test we showed before is pretty basic, but actual, day-to-day performance tests can quickly become resource-heavy. You may want greater control over hardware resources used during the test execution. For these cases, Testkube now allows you to customize the default job template.

If you want to, for example, set the minimum CPU/RAM resources with K8s requests, you can do it with the custom template:

```YAML

apiVersion: batch/v1

kind: Job

spec:

  template:

    spec:

      containers:

      - name: {{ .Name }}

        image: {{ .Image }}

        resources:

          requests:

            cpu: 500m

            memory: 256Mi

```

...and just save it to a YAML file. Then, you need to set `--job-template` when creating your test in Testkube to use this. So if you have a job template named `custom_job_template.yaml` you can create a test with the following command:

```bash

testkube create test --name jmeter-test-example --type jmeter/test --test-content-type git-file --git-uri https://github.com/kubeshop/testkube.git --git-branch main --git-path test/jmeter/executor-tests/jmeter-executor-smoke.jmx --job-template custom_job_template.yaml

```

You can then run the test as usual, but the execution pod will now be customized to exactly match your needs:

---

Give it a go!

Why not check it out yourself? Get started with Testkube and JMeter to run tests efficiently in Kubernetes.

If you get stuck or have questions, we’re here to help! Find an answer to your questions in the Testkube Knowledge Base or reach out to us on Slack.