The Terraform Provider for kind enables Terraform to provision local Kubernetes clusters on base of Kubernetes IN Docker (kind).
Perform the following steps to build the providers:
-
Build the provider:
go build -o terraform-provider-kind
-
Move the provider binary into the terraform plugins folder.
NOTE: For details on Terraform plugins see this document.
Perform the following steps to use the provider:
- Go to the provider example folder:
cd examples
- Edit the
main.tf
file and provide the following kind configuration:
provider "kind" {}
# creating a cluster with kind of the name "test-cluster" with kubernetes version hardcoded in kind defaults https://github.com/kubernetes-sigs/kind/blob/master/pkg/apis/config/defaults/image.go#L21
resource "kind" "my-cluster" {
name = "test-cluster"
}
To override the node image used, you can specify the node_image
like so:
provider "kind" {}
# creating a cluster with kind of the name "test-cluster" with kubernetes version v1.16.1
resource "kind" "my-cluster" {
name = "test-cluster"
node_image = "kindest/node:v1.16.1"
}
To override the default kind config, you can specify the kind_config
with HEREDOC:
provider "kind" {}
# creating a cluster with kind of the name "test-cluster" with kubernetes version v1.15.7 and two nodes
resource "kind" "my-cluster" {
name = "test-cluster"
node_image = "kindest/node:v1.15.7"
kind_config =<<KIONF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
KIONF
}
- Initialize Terraform:
terraform init
- Plan the provisioning:
terraform plan
- Deploy the cluster:
terraform apply