Docker is one of the greatest advancements in application deployment. It revolutionized containerization, enabling developers to package their applications and dependencies into mobile units. As the number of containers grew, orchestrating and managing them became difficult.
Enter Kubernetes, which helps you manage containers at scale and comes with scaling, healing, and fault tolerance capabilities.
Many teams use docker-in-docker to extract most of the tool. However, as discussed in our previous post, that approach has limitations and complexities. Instead, using Kubernetes in Docker is a better alternative and changes how developers interact with Kubernetes.
In this post, we’ll examine KinD, its features, real-world use cases, and how you can use Testkube in KinD for efficient and effective testing.
As the name suggests, Kubernetes in Docker, KinD allows you to run Kubernetes clusters locally using Docker. Each Kubernetes node is represented by a Docker container, which uses Docker’s underlying networking and storage capabilities to simulate a realistic Kubernetes setup.
Source: https://kind.sigs.k8s.io/
Salient features of KinD:
Using Kubernetes in Docker brings many benefits while streamlining the development and deployment process. Some of the benefits are:
It's important to understand the specific use cases where KinD is helpful before you adopt it for your development and deployment needs. Below, we explore real-world use cases where KinD shines and helps improve your overall workflow efficiency.
Developers can use KinD to create local Kubernetes clusters that mimic the production setup. This helps them with easy testing and debugging. For instance, developers working on a microservices application can use KinD to create a local setup where each microservice can be tested in isolation, ensuring that changes in one service don’t affect the other.
When working with CI/CD pipelines, you can leverage KinD to provision ephemeral clusters for pipeline runs. Since these clusters can be created and destroyed dynamically, they are suitable for use with CI/CD pipelines. Further, these clusters can be configured to mirror your production setup, making them a good candidate for automated integration tests.
This ability of KinD allows your development workflow to be more reliable and efficient while ensuring that you’re testing in a production-like setup, which leads to a robust and stable application.
Testkube is designed to make Kubernetes testing efficient. It’s a framework that allows you to bring any testing tool and make it ‘Kubernetes-native’ to take full advantage of Kubernetes. It allows you to treat your tests as Kubernetes resources, making it more straightforward to manage them.
Running Testkube in KinD ensures consistency and reproducibility. Integration with CI/CD pipelines further streamlines the testing process, allowing for continuous testing and validation of code changes before deployment. It can easily integrate with CI/CD tools like GitHub Actions, Jenkins, and Azure DevOps, to name a few, allowing you to create automated workflows.
Using Testkube in KinD has a lot of benefits:
Further, Testkube can be used effectively in different scenarios:
Testkube can be deployed fully on-prem within a KinD cluster. You can install Testkube agents in your local environments to talk with your on-prem Tetskube control plane. This cost-effective solution allows developers to develop and manage their tests locally. This setup ensures that your testing environment is secured and within the local infrastructure.
When working with CI/CD pipelines, Testkube can be deployed as agents within a Kind cluster. To orchestrate and manage tests, these agents communicate with Testkube’s hosted control plane. Such a setup allows for automated integration and deployment testing as Testkube agents ensure seamless integration into the CI/CD workflow.
More details about Testkube offerings can be found here.
Test Workflows provide a comprehensive, purpose-built solution for managing the full lifecycle of running tests against your applications and their components. These are stored as custom resources in your cluster, making them easy to manage using existing Kubernetes tools and GitOps pipelines. Hence, when running Testkube in KinD, you’ll benefit from creating Test Workflows.
After setting up Testkube in your KinD cluster, you can configure a Testkube agent to talk to the dashboard. Once this is done, you can start creating Test Worfklows.
As mentioned earlier, there are two ways to use Testkube in KinD: one using the Testkube dashboard, which is suitable for self-hosted control planes, and the other using the Testkube CLI, which is suitable for your CI/CD pipeline.
Using an existing example is the easiest way to create a Test Workflow using the Testkube dashboard and understand how it works. Testkube provides some prebuilt Test Workflows for k6, PlayWright, and Cypress.
Choose any one of them from the wizard, provide a name, and you’re ready to execute your Test Workflow.
Testkube configures everything else for you, from resource allocation to artifacts and log collection. All you need to do is trigger your Test Workflow.
Once your Test Workflow is executed, you can examine the artifacts collected by Testkube that provide more details about the test. In this case, the playwright test report is generated and captured by Testkube.
If you want to run Test Workflows in KinD for your CI/CD pipeline, then using Testkube CLI is suitable. After configuring the environment on Testkube, you can install Testkube CLI to perform operations using CLI.
Once you have configured Testkube CLI, you create a Test Workflow. We will create a playwright Test Workflow using the following command:
```sh
testkube create testworkflow --name playwright --file playwright.yaml
```
We use a playwright.yaml file to create the Test Workflow.
Run the Test Workflow after it is created.
```sh
testkube run testworkflow playwright -f
```
After executing the Test Workflow, you can get the results using the execution execution id from the previous command's output.
```sh
kubectl testkube get twe 6683b881923ebd28cd944418
```
Similarly, you can create advanced Test Workflows from scratch for different testing tools and scenarios. We have detailed guides on creating Test Workflows for Cucumber, Rest Assured, and more in our Testing in Kubernetes Handbook.
Leveraging KinD for local Kubernetes development and testing offers multiple benefits, including cost-effectiveness, development consistency, and simplified CI/CD integration. These advantages streamline your testing and development efforts and enhance the overall workflow.
By using Testkube in KinD, you can further enhance your testing process with flexible test orchestration and leverage the full benefits of running Kubernetes in Docker. Try out Testkube today and join our Slack community to connect with fellow developers, share insights, and receive support.
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!
Related topics: