Responsive

Getting Started with Test Workflows For Kubernetes Testing

Getting Started with Test Workflows For Kubernetes Testing

Last updated
September 4, 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

Subscribe to our monthly newsletter to stay up to date with all-things Testkube.

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

Table of Contents

Testing in Kubernetes environments can be complex and challenging. Developers frequently encounter difficulties configuring testing tools, accessing clusters, and managing multiple tools with different reporting formats, complicating the overall testing process.

CI/CDs, unfortunately, don't make these challenges much easier. Fortunately, platforms like Testkube provide a unified framework specifically designed to run natively in Kubernetes, streamlining the testing process. This blog post delves into the latest Test Workflow feature, highlighting their potential to revolutionize Kubernetes testing.

Test Workflows

Test Workflows provide a comprehensive, purpose-built solution for managing the full lifecycle of running tests against your applications and their components. This includes everything from provisioning necessary infrastructure components to running tests in parallel to maximize throughput, integrating seamlessly with other testing tools, and orchestrating complex tests.

Test Workflows use Kubernetes-native capabilities to run all types of testing, from integrations tests, load testing, security tests and end-to-end tests. It executes and orchestrates all tests in a very scalable way and then collects all test data for you. Including logs, artifacts and all results in real-time while showing them to you in a very convenient dashboard.

Test Workflows are single-YAML files that comprise everything required to define a test workflow. These are stored as custom resources in your cluster, making them easy to manage using existing Kubernetes tools and GitOps pipelines.

Test Workflows has a powerful templating engine that allows you to define common testing configurations, ensuring standardization and consistency across your testing efforts.

Test Workflows improve the testing experience by providing greater flexibility and usability and accommodating simple and complex configurations. Here is how Test Workflows enhance the testing experience:

  • Improved Test Management: Test workflows combine test results from various sources to provide a comprehensive view of testing outcomes. This centralization simplifies test result analysis, making identifying trends, areas for improvement, and potential issues easier.
  • Scalability and Flexibility: Test Workflows take advantage of Kubernetes’ scalability to enable parallel test execution, considerably minimizing the time required to run the entire test package. This scalability enables efficient management of large-scale tests, addressing the increasing complexity of current applications.
  • Enhanced Automation Capabilities: Built-in automation capabilities in test workflows facilitate the easy addition of new tests to the pipeline and their integration with existing CI/CD workflows.  With this automation, much manual work isn't required, making it easier to test things all at once and set up feedback loops.

Testkube integrates with most of the well-known CI/CD tools like GitHub Actions, Jenkins, Azure DevOps, and CircleCI, to name a few. Check out our Integrations documentation to learn more.

Benefits of Test Workflows

Test workflows provide multiple benefits for increasing the effectiveness of your testing efforts. Some of the benefits include:

  • Building Complex Test Workflows: Test Workflows allow you to create complex workflows by combining different tools and test workflows to test your application by simulating a more realistic production-like environment. These workflows enable the configuration of various user behaviors and conditions, resulting in a robust framework for stress-testing applications.
  • Multiple Methods To Trigger Tests: Testkube offers greater flexibility by enabling tests to be started manually or using API calls, CLI commands, Cronjobs, and CI/CD pipelines.
  • Parametrization: Testkube allows for dynamic modification of test parameters across several to quickly adapt to multiple scenarios. This allows you to configure parameters at run time to tailor your test workflows for different scenarios.
  • Services: When building complex Test Workflows, you might need additional services to execute your tests. For instance, databases, workers, and other similar services. Services in Testkube enable the dynamic provisioning of additional services within test workflows.

spec:
  services:
	db:
  	timeout: 5m
  	image: mongo:latest
  	env:
  	- name: MONGO_INITDB_ROOT_USERNAME
    	value: root
  	- name: MONGO_INITDB_ROOT_PASSWORD
    	value: p4ssw0rd
  	readinessProbe:
    	tcpSocket:
      		port: 27017
    	periodSeconds: 1
  • Analytics and Reporting: Testkube offers comprehensive analytics and reporting capabilities. It collects detailed test data and creates insightful dashboards highlighting performance trends, enabling in-depth insights.

Read more about Test Workflows to see how they empower developers to deliver high-quality software faster by centralizing and streamlining the testing process.

Test Workflows in Action

After learning about Test Workflows and their benefits, let's see how they work. This short demo will show how to create a test workflow to execute a test and streamline the testing lifecycle.

In this post, we will walk you through creating a basic k6 Test Workflow.

Pre-requisites

  • A Testkube Pro account.
  • Kubernetes cluster - we are using a local Minikube cluster.
  • Testkube Agent configured on the cluster.

Once the prerequisites are met, you should be able to launch a target Kubernetes cluster with a configured Testkube agent.

Creating a Test Workflow

  1. 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 presents a dialog that guides you through a step-by-step process for creating a new test workflow. 
  • Start from an Example: This option allows you to begin with a pre-configured example.
  • Combine Existing Workflows: You can combine multiple existing test workflows to run sequentially or simultaneously using this option.
  • Import a workflow from YAML: This option allows you to import a test workflow using a YAML definition.
  1. Choose Start from an Example to create a test workflow using a pre-defined specification.

 

A new dialog appears, offering a list of tests to select from. We will go with k6. 

The spec section provides detailed specifications for your test workflow. The default spec file for k6 is shown below:

kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
  name: k6-test
  namespace: testkube
  labels:
    docs: example
spec:
  content:
    files:
      - path: /data/example.js
        content: |-
          import http from 'k6/http';
          import { sleep } from 'k6';
          export default function () {
              http.get('https://test.k6.io');
              sleep(1);
          };
  steps:
    - name: Run Tests
      workingDir: /data
      run:
        image: grafana/k6:0.49.0
        env:
          - name: K6_WEB_DASHBOARD
            value: 'true'
          - name: K6_WEB_DASHBOARD_EXPORT
            value: k6-test-report.html
        args:
          - run
          - example.js
      artifacts:
        paths:
          - k6-test-report.html

The spec file includes the following components:

  • The metadata for the test workflow comprises its name, the Kubernetes namespace in which it is deployed, and the labels, which contain key-value pairs used to categorize and filter resources.
  • The content includes a list of the test files, their locations, and the k6 load test script.
  • The steps define the test that will be run in the workflow, including the name, working directory, environment, parameters, artifacts, and paths.‍

You can change the parameters here based on your requirements, but we will not do that now. Read our test workflow document to understand more about the test workflow specification.

  1. Click on the “Create & Run” button to create and run the test workflow.

You can click on a step in the test workflow to view real-time progress and logs.

After the execution, Testkube collects all artifacts, in this case a k6 log report containing all of the results and outputs.

  1. Click the “Artifacts” tab, then select the.html file to open it 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.

Summary

Test workflows represent a significant advancement in Kubernetes testing. They combine the entire testing lifecycle into a single, declarative format, allowing teams to improve scalability, streamline test workflows, and standardize testing operations. Improving consistency and making management easier with templating and single specification files are the obvious benefits, among others.

We invite you to try Test Workflows. Visit the Testkube website to get started. If you find yourself struggling with anything, feel free to drop a note in our active Slack community, and someone will help you out.

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!