- Published on
 
Terraform Module usage on Running Kubernetes KinD Clusters
- Authors
 
- Name
 - Ruan Bekker
 - @ruanbekker
 
In this tutorial we will discover how to use the terraform-kubernetes-kind-module which enables you to deploy a KinD (Kubernetes in Docker) Cluster on your local workstation using Terraform.
Why another method to run KinD
We already have the kind cli that makes it easy to run a KinD Kubernetes clusters, but recently I've been working on a couple of workshop projects where the infrastructure is already using Terraform, so having Terraform to deploy a local environment was something I was keen to do.
What does this module offer?
This Kubernetes Kind Module enables you to do the following:
- Spins up a KinD Kubernetes Cluster in Docker
 - It dumps the kubeconfig by default to the 
/tmp/directory. - You can define the Kubernetes Cluster Version.
 - You have the option to define how many worker nodes you want.
 
Spinning up a 3 node KinD Kubernetes Cluster is as easy as:
module "kind-module" {
  source  = "ruanbekker/kind-module/kubernetes"
  version = "1.0.0"
  cluster_name = "test"
  workers      = 3
}
Lets Deploy a KinD Kubernetes Cluster
The pre-requisite to run this is to have docker, kubectl and terraform installed.
I will create a directory called ~/workspace/kind-kubernetes-terraform:
mkdir -p ~/workspace/kind-kubernetes-terraform
Then inside the directory:
cd ~/workspace/kind-kubernetes-terraform
Create a main.tf with the following content:
module "kind-module" {
  source  = "ruanbekker/kind-module/kubernetes"
  version = "1.0.0"
  cluster_name    = "demo"
  cluster_version = "v1.28.15"
  workers         = 3
  kubeconfig_file = "/tmp/kube.config"
}
Once the content has been written to the file, we can initialize terraform where it will download the module dependencies:
terraform init
Once done we can run apply to deploy the cluster to our local workstation:
terraform apply
Configure kubeconfig:
export KUBECONFIG=/tmp/kube.config
Access the cluster:
kubectl get nodes
Cleanup
To tear down the cluster you can run:
terraform destroy
Resources
To see the Terraform Module on Terraform Registry:
The source code:
Thank You
Thanks for reading, if you like my content, feel free to check out my website, and subscribe to my newsletter or follow me at @ruanbekker on Twitter.
- Linktree: https://go.ruan.dev/links
 - Patreon: https://go.ruan.dev/patreon
 
