A provider which is an alternative to k3d cli, this helps in creating a throw away kubernetes cluster using k3d.
The provider terraform-provider-k3d
covers almost every task that one can accomplish with k3d cli
with no k3d
installed.
terraform {
required_providers {
k3d = {
source = "hashicorp/k3d"
version = "0.1.3"
}
}
}
// Configure GoCD Provider
provider "k3d" {
// if no image is passed while creating cluster attribute `kubernetes_version` and `registry` would be used to construct an image name.
kubernetes_version = "1.24.4-k3s1"
k3d_api_version = "k3d.io/v1alpha4"
registry = "rancher/k3s"
kind = "Simple"
runtime = "docker"
}
// Create node under already created cluster
resource "k3d_node_create" "node-1" {
name = "sample-node-2"
cluster = "sample-cluster"
role = "agent"
replicas = 1
memory = "8g"
// wait = false
// timeout = 1
}
All parameters which is used by the providers has the environment variable support. Environment Variables:
KUBERNETES_VERSION
K3D_REGISTRY
K3D_API_VERSION
K3D_KIND
K3D_RUNTIME
k3d_api_version
(String) api version of k3d to be used while creation of clusterkind
(String) kind of config file that you want to usekubernetes_version
(String) version of kubernetes cluster that has to be created (tag of k3s to be passed)registry
(String) registry to be used for pulling images while creating cluster/nodesruntime
(String) runtime in which cluster has to be created, defaults to docker