How to run Kubernetes clusters locally on Windows

Comments 0

Share to social media

Kubernetes production clusters are typically run on cloud platforms. However, running and deploying Kubernetes applications on cloud platforms such as Google Kubernetes Engine is costly. These high costs can restrict the Kubernetes learning process for beginners. However, running Kubernetes clusters locally helps you efficiently test applications without disrupting the production environment or paying for cloud services. 

To make things easier, the Kubernetes team developed two tools,  Minikube and Kind, that allow Kubernetes users to run clusters locally without spending a dollar. This article will cover how to do it with Kind. Kind is a command-line tool used to run Kubernetes clusters locally on your computer using Docker containers. Kind works with Docker by loading Docker containers into Kind clusters. A Kubernetes cluster is a group of nodes used to run containerized applications.

Kind uses a virtual machine on your pc to create nodes. Kind is also widely used to test and implement continuous integration tasks. Kind runs clusters locally from your computer making it easy to develop your Kubernetes applications without the need for a server.

Kind is good at creating clusters with multiple nodes. The more nodes you have, the more containerized applications you can run. These clusters created by Kind can be operated and interacted with using Kubectl. Kubectl is a command line that enables you to execute commands that communicate with your Kubernetes cluster and make changes.

In this article, you will learn how to install Kind on Windows. In addition, you will learn how to create a cluster using Kind and create a service.

Table of contents

  1. Prerequisites
  2. How to install Kind on Windows
  3. How to create and delete a cluster
  4. How to create a cluster with multiple nodes
  5. How to create a service
  6. How to export cluster logs
  7. Conclusion

Prerequisites

  • A Windows machine that has at least 8GB RAM. Using a machine that has less than 8GB of RAM will raise memory issues and complications when running a Kind cluster.
  • You need to have installed Kubectl before starting this tutorial; if you haven’t installed Kubectl, you install it from here.
  • Kind cannot function without Docker, install Docker from here.
  • In this tutorial, you will install Kind using Chocolatey. Download Chocolatey here.
  • Run Windows PowerShell as an Administrator whenever executing any Kind or Kubectl commands.

How to install Kind on Windows

In this article, you will learn how to download Kubernetes Kind using Chocolatey. Use the following command to download Kind using chocolatey:

Chocolatey will install 6 packages. After Kind has been successfully installed, you will get the list of the installed artifacts:

To check if Kind has been installed successfully, execute the following command on Powershell:

If Kind has been installed successfully you will get the version output and your computer’s processor:

kind v0.11.1 go1.16.4 windows/amd64

Now you’re done installing Kind on Windows. You can now start creating clusters locally using kind. If you ever get stuck using Kind, use the command shown below to get all available commands:

You will get the following list of commands as output:

Use the -h flag to get more information about any command. For example, executing this command:

gives you the following detailed information about the build command:

How to create and delete a cluster

Clusters are the holy grail of Kubernetes. Clusters comprise containers with all the runtime resources needed to run applications in different operating systems.

Use the following command to create a default Kind cluster:

The above command will create a default cluster called kind. If you want to use a specific name, add the --name flag to the kind create cluster command. Here is an example:

The Kind create command has the following arguments and options

  • --quiet: this flag silences all stderr output.
  • --verbosity int32: This flag will log verbosity information.

When your cluster has been created successfully, you will get the following output:

After you have created your cluster, use the following command to check if the cluster has been created successfully or get the list of all Kind clusters running:

If you want to interact with a specific cluster locally. Use the following command and specify the name of the cluster (kind-<cluster-name>):

You will get the following output which shows you where the Kubernetes control plane and CoreDNS are running at:

The cluster’s configuration access will be stored in the ${HOME}/.kube/config file. This file acts as your cluster’s manifest. Here is the configuration access of the default Kind cluster created earlier:

A corresponding Docker container will be created automatically when creating a Kind cluster. Use the following docker command to see the corresponding docker container:

You will get the following information:

To view nodes created by the cluster, use the following command to view them:

You will get the following information:

Use the following command to delete a cluster:

After the cluster has been successfully deleted, you will get the following information:

To delete a cluster without the default name, use the –name flag.

How to create a cluster with multiple nodes

A Kubernetes node is a virtual machine that runs a cluster. There are two types of nodes which are:

  • Worker node: A worker node executes and runs applications and containers assigned to it.
  • control-plane: A control-plane controls all the worker nodes.

You’ll need a YAML file that defines the nodes when creating a multi-node cluster.

A node can also be a physical machine. To add more nodes to your cluster, start by creating a cluster and adding different roles of nodes you want to add to your cluster. Save the following in kind-config.yaml.

After saving the YAML file that has the above contents. Use the following command to apply changes:

You will get the following output; this time the output will show that Kind is creating multiple nodes and show that it is joining worker nodes at the bottom of the output:

You can now use your cluster with:

To check if the nodes have been created successfully and are ready, execute the following command:

You will get the following output:

How to create a service

A Kubernetes service is used to expose your cluster and connect with authorized traffic outside your cluster. An ingress controller is a type of load balancer service that routes traffic to your service.

The following YAML file creates a pod, service, and the ingress controller objects. The service will receive traffic through the 5678 port. The ingress controller version is set to networking.k8s.io/v1.

Start by creating a YAML file that will define and configure the service. Add the following content to the YAML file:

After saving your YAML file, use the following command to deploy the service:

Execute the following command to check if the service is running:

You will get the following output:

The above output shows that your cluster is now ready to receive traffic from outside the cluster through the service you just created.

How to export cluster logs

Kubernetes logs give you visibility on how your cluster performs. Some vulnerabilities and defects will be identified when inspecting and auditing logs. Kind has the following command that is used to export cluster logs to your desired directory on your pc:

The above command will give you the following output, exporting logs of the default cluster. Use the –name flag if you have named the cluster something else:

Exporting logs for cluster “kind” to:
C:\Users\redgate

The structure of the logs will look like this in the folder you exported them to

Conclusion

In this article you have learned:

  1. How to install Kind on Windows.
  2. How to create a cluster using Kind.
  3. How to create a cluster with multiple nodes.
  4. How to create a service.

The above skills are enough to get you started with the journey of creating Kubernetes clusters using Kind. You can advance your Kubernetes skills on the Kubernetes official page here.

 

Load comments

About the author

Boemo Mmopelwa

See Profile

Boemo is a software developer who embraces innovative approaches when building applications. He likes diving deep into complex concepts in order to learn and write articles that can help the reader understand complex methodologies in a simple and fun way.