Responsive

Load Testing Kubernetes Applications using Gatling and Testkube

Load Testing Kubernetes Applications using Gatling and Testkube

Last updated
September 16, 2024
Bruno Lopes
Product Leader
Testkube
Share on X
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

Start Using Testkube with a Free Trial Today!

Load testing is an important step in verifying that an application can withstand the demands of real-world usage. Users today access applications to perform various tasks. Most of the time, the application behaves well. However, if the system is not designed to handle increased traffic, for example during peak hours, it may cause performance issues such as slow response times, server crashes, or unresponsiveness. 

Hence, it is important to simulate these scenarios and identify potential performance bottlenecks before adversely affecting the user experience.

In this blog post, we'll look at Gatling, a load testing tool, and see how we can use Gatling with Testkube for load testing in Kubernetes.

Need for Load Testing

Load testing ensures an application can withstand expected user traffic without affecting performance. In a situation where multiple users are using the application simultaneously, it helps identify potential issues such as slow response times, server crashes, or lack of responsiveness. 

Load testing simulates real-world traffic to identify performance bottlenecks and improve the application’s performance and user experience before deployment.

Some of the benefits include:

  • Performance Validation: Load testing determines whether an application can handle expected user traffic without performance degradation to ensure it meets performance requirements.
  • Scalability Assessment: It indicates how well an application scales with user load, allowing you to determine system capacity. 
  • Improved User Experience: Load testing improves user experience under various load conditions by identifying and fixing performance issues before they affect users.
  • Real-World Scenarios: Load testing replicates real-world usage scenarios to help you understand how the application behaves and ensure it can handle demands. 


In addition to its considerable advantages in terms of scalability and performance, it also introduces complexity in terms of configuration, execution, aggregation of results, etc.

Load Testing with Gatling

Gatling is a powerful load testing solution designed to analyze and measure the performance of web applications under varying levels of load. Load testing primarily determines how the application behaves when exposed to various traffic loads, ensuring it can manage the expected user load without experiencing performance degradation.

Load testing, particularly with Gatling, displays actual traffic and how the application performs in that traffic situation. This enables developers to identify performance bottlenecks and optimize application scalability and overall user experience before deploying the application in production.
Besides simulating real-world behavior, Gatling helps identify potential bottlenecks and performance issues, enabling you to resolve them before they adversely affect users. 

Gatling can run as a standalone tool and even supports integration with various build tools like Gradle and Maven and CI/CD tools like GitLab and Jenkins.

Refer to the Gatling documentation for more information.

Challenges of Load Testing with Gatling

While Gatling is powerful, load testing comes with several challenges that need to be managed to ensure accurate and efficient execution. The following are some challenges we generally encounter while performing Gatling load testing:

  • Resource Intensive: When performing load testing on a single system, resources like CPU, RAM, and other resources can quickly degrade, resulting in inconsistent results.
  • Results Accuracy: Load testing, particularly in high-demand situations, may not correctly reflect actual results due to resource limitations. This can lead to inaccurate information about application performance and stability. 
  • Aggregation of Results: Combining results from multiple machines can be complex and error-prone. To obtain reliable test results, combining data from all nodes correctly is important.

Load Testing with Testkube and Gatling

Testkube is a test orchestration platform that supports the execution of any testing tool in a containerized application infrastructure. It leverages Kubernetes to provide a scalable and consistent execution environment for all your tests and includes a unified dashboard for test definition, reporting, and troubleshooting.

Testkube makes load testing in Kubernetes environments easier, allowing you to ensure that your application can withstand loads and perform consistently. 

  • Simplified Test Workflow Creation: Without complex scripting, Testkube facilitates the creation of detailed Test workflows that allow for better control and customization of your Test Executions. 
  • Scales your Testing Tools by leveraging Kubernetes: Testkube integrates with any testing tool, including Cypress and Playwright, and allows you to leverage your own infrastructure to run tests at scale!
  • Single Pane of Glass: Testkube gives you a simple dashboard that allows you to observe and troubleshoot all of your tests.

Learn more about Test Workflows and how they help developers create complex tests quickly by centralizing and streamlining the testing process.

We’ll now look at creating a simple Gatling test workflow using Gradle in Testkube. The test code and related files are in our Gatling Test repository

For a visual walkthrough of this tutorial, you can watch the accompanying video below before diving into the written instructions and prerequisites.

Prerequisites

Once the prerequisites are met, you can launch a target Kubernetes cluster with a configured Testkube agent.

Creating a Test Workflow

Navigate to the test workflow section and click the “Add New Test Workflow” button.

A “Create a Test Workflow” dialog appears that provides you with four options to create a test workflow:

  • Create from Wizard: This option displays a dialog box that guides you through creating a new test workflow. 
  • Start from an Example: This option allows you to use a pre-configured example, such as k6, Playwright, Cypress, Playwright, or Postman.
  • Combine Existing Workflows: This option allows you to combine and run various existing test workflows sequentially or simultaneously.
  • Import a Workflow from YAML: This option allows you to import a test workflow using a YAML definition.

Choose the “Create from Wizard” option to create this workflow.

Enter the following information into the designated field of the “Name & Type” tab:

  1. Name: This name will be used to identify the workflow in the Testkube dashboard.
  2. Labels: Provide labels to tag test workflows. (Optional)
  3. Template: Select Gradle from the list of options, which includes Artillery, Cypress, JMeter, k6, and others.
  4. Gradle Version to Use: Enter the Gradle version you want for this workflow. We’ll use the default version suggested.

Click Next.

In the “Content” tab, choose “Git” as the content source from the drop-down menu and then provide the following information:

  1. Git Repository URL: The URL of the Git repository will be used to get the test files. We’ll use the Testkube example repository: https://github.com/kubeshop/testkube-examples.git 
  2. Git Token: This field allows for secure access to private repositories. As a result, the drop-down menu option for Secret is selected.
  3. Git Username: This field provides a username to enable secure access to private repositories. 
  4. Branch: This parameter is set to "main," indicating that the test files should be retrieved from the repository's main branch.
  5. Path: This parameter indicates the directory path in the repository where the test files are stored. We enter `Gradle/GatlingSimple`.

Click Next.

In the “Run” tab, provide the following information:

  1. Run Command: This column defines the command to run the test. We use `./gradlew gatlingRun`.
  2. Execution Working Directory: This field indicates the directory in which the command will be performed. We use `/data/repo/Gradle/Gatling/Simple` here.
  3. Artifacts: This field specifies the output files or directories that will be generated by the test. In this case, we use data/repo/Gradle/Gatling/Simple/build/reports/**`.
  4. Environment Variables: This field can be used to pass configuration or secrets required for test execution.

Click Next. The Summary tab will open, showing you the generated spec file.

The entire workflow specification is available in YAML format. To set up and execute the test workflow, click the "Create & Run" button.

Executing the Test Workflow

After you click on “Create & Run”, the test workflow will start being executed.

To check real-time progress and logs, click on each step in the test procedure. After the execution, Testkube collects all artifacts,  including a Gatling stats report with all of the results and outputs.

Click the "Artifacts" tab and then select the.html file to view the logs in a new tab.

This was a simple demonstration of how to use test workflows for Kubernetes testing. To maximize the benefits of test workflows, you can create complex test workflows or import custom workflows into Testkube.

Understanding Gatling Testing Workflow File

Let's analyze the Gatling Test Workflow that was used to set up and carry out this test:

kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
  name: gradle-testkube-simple
  namespace: testkube
  labels:
    test-workflow-templates: "yes"
spec:
  use:
  - name: official--gradle--v1
    config:
      run: ./gradlew gatlingRun
      version: 8.7.0-jdk21-alpine
  content:
    git:
      uri: https://github.com/kubeshop/testkube-examples/
      revision: main
      paths:
      - Gradle/Gatling/Simple
  container:
    workingDir: /data/repo/Gradle/Gatling/Simple
  steps:
  - name: Saving artifacts
    condition: always
    artifacts:
      paths:
      - /data/repo/Gradle/Gatling/Simple/build/reports/**
status: {}

The spec file includes the following components:

  • The metadata for the test workflow comprises its fields such as the name of the test workflow, namespace within which the test workflow is defined, labels that mark as a template or predefined workflow based on the details we provided in the wizard.
  • The spec specifies the desired state of the test workflow, including the configurations, content, and execution steps.
  • The steps define the test that will be run in the workflow, including name, conditions, artifacts, and paths.

Summary

This article describes the importance of load testing and how to use Gatling to create simple load tests that withstand real-world traffic scenarios. Using Gatling for load testing ensures that web applications are optimized for performance and can handle the expected loads from users. Gatling can also be used for distributed load testing. To learn more about this, read our next article “Distributed Load Testing with Gatling and Testkube on Kubernetes”. 

Running Gatling tests with Testkube provides lots of benefits from making it Kubernetes native to giving you more control and flexibility over your tests.  

Get started with Testkube today, or visit the Testkube documentation to learn more about running distributed tests in Testkube using other testing tools. If you find yourself struggling with anything, feel free to drop a note in our active Slack community, and someone will help you out. Need to generate heavy load to test your application? Follow 

About Testkube

Testkube is a test execution and orchestration framework for Kubernetes that works with any CI/CD system and testing tool you need, empowering teams to deliver on the promise of agile, efficient, and comprehensive testing programs by leveraging all the capabilities of K8s to eliminate CI/CD bottlenecks, perfecting your testing workflow. Get started with Testkube's free trial today!