Kubernetes local testing with Kind

Gabriele Bartolini
Gabriele Bartolini

Did you know that you can create a Kubernetes cluster inside a Docker container? Read how kind allows you and your team to practice with Kubernetes on your machine and to enhance automated testing capabilities for your software.

Kubernetes (often shortened in "k8s") is a very popular open source software that helps orchestrate containerised applications, in terms of deployment, scaling, and high availability - just to name a few.

When using it in production, you need to rely on a "Kubernetes as a service" platform available in the Public cloud or your organisation's infrastructure team with Kubernetes Administration expertise (like EnterpriseDB, the first Kubernetes Certified Service Provider in the PostgreSQL eco-system).

The good thing with containers is that they are designed to be immutable and therefore bring an important property along with them: infrastructure abstraction. This means that the same container image can run the same way in every Kubernetes cluster you want to use, including local installations.

In this article we describe how to use a very popular tool called Kind, "Kubernetes in Docker". Kind can be used primarily for two purposes:

  1. evaluation and local testing of Kubernetes workloads (how applications are called in that context)
  2. automated testing in your CI/CD pipelines (for example, EnterpriseDB systematically tests Cloud Native applications this way)

This article is limited to Kind and will not explain how to use interact with the Kubernetes cluster through kubectl.

Install Kind

You can Install kind on your environment by following the specific instructions for your system that you find in the Quickstart. You will also need to install the Kubernetes CLI application, called kubectl. For example, on a Mac OS X where brew is used to manage packages, you can install Kind and kubectl with:

brew install kind kubectl

You can then familiarise with the kind help page:

kind --help

Create a cluster

As you can see, creating your default test cluster is very easy:

kind create cluster

You can also specify a name for a cluster (allowing you to create multiple ones at the same time):

kind create cluster --name mycluster

List available clusters

You can list the available Kubernetes clusters in Kind with:

kind get clusters

Destroy a cluster

When you are done with testing a cluster, you can destroy it (with all the resources contained in it) with the delete cluster command.

In order to remove the default cluster, you can type:

kind delete cluster

If you created the cluster with a name, you can delete it with:

kind delete cluster --name mycluster

Simulate multiple Kubernetes nodes

By default, Kind creates a cluster with a single Kubernetes worker node. In case your tests require you to simulate multiple nodes, you can easily do it by creating a YAML file with the following content:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
- role: control-plane
- role: worker
- role: worker
- role: worker

Then, create the cluster as follows:

kind create cluster --config config.yaml --name mycluster

This will create a Kubernetes cluster with 3 workers.

Was this article helpful?

0 out of 0 found this helpful