Setup vCluster with Taikun Cloudworks using Terraform

Taikun Cloudworks is a powerful cloud management platform that simplifies the deployment and management of Kubernetes clusters. One of the features offered by CloudWorks is the ability to create virtual clusters (vCluster) within a parent cluster. This allows for better resource isolation and management.

In this tutorial, we’ll walk through the process of setting up a vCluster with Taikun Cloudworks using the Taikun Terraform provider. We’ll use OpenStack as the underlying cloud provider.

Prerequisites

Before we get started, make sure you have the following:

  1. Taikun Cloudworks account
  2. Terraform installed on your local machine
  3. Access to an OpenStack cloud environment

Step 1: Configure Terraform Provider

First, let’s define the Terraform provider for Taikun CloudWorks. Create a new file named main.tf and add the following code:

HCL
terraform {
  required_providers {
    taikun = {
      source  = "itera-io/taikun"
      version = "1.9.1"
    }
  }
}

provider "taikun" {
  email    = "test@example.com"
  password = "asdfghjkl"
}

Replace test@example.com and asdfghjkl with your CloudWorks account email and password.

Step 2: Define Cloud Credential

Next, we need to define a cloud credential resource that connects to your OpenStack environment:

HCL
resource "taikun_cloud_credential_openstack" "foo" {
  name                = "terraform-openstack-cc"
  user                = "zaphod"
  password            = "bEEblebrox4prez"
  url                 = "example.com"
  domain              = "domain"
  project_name        = "project_name"
  public_network_name = "public_network_name"
  region              = "region"
  lock                = false
}

Replace the values with your OpenStack credentials and configuration.

Step 3: Create a Parent Cluster

Before creating a vCluster, we need to have a parent cluster. Let’s create one using the taikun_project resource:

HCL
resource "taikun_project" "proj" {
  name              = "tf-openstack-vc"
  cloud_credential_id = taikun_cloud_credential_openstack.foo.id
  flavors           = concat(local.flavors_small, local.flavors_big)

  server_bastion {
    name      = "tf-bastion"
    disk_size = 30
    flavor    = local.flavors_small[0]
  }

  server_kubemaster {
    name      = "tf-master"
    disk_size = 30
    flavor    = local.flavors_small[0]
  }

  server_kubeworker {
    name      = "tf-worker"
    disk_size = 100
    flavor    = local.flavors_big[0]
  }
}

This creates a parent cluster with a bastion host, a master node, and a worker node. The flavors argument uses data sources to filter and select appropriate flavors for the nodes.

Step 4: Create a vCluster

Now that we have a parent cluster, we can create a vCluster within it using the taikun_virtual_cluster resource:

HCL
resource "taikun_virtual_cluster" "foo" {
  name      = "terraform-vc01"
  parent_id = taikun_project.proj.id
}

This creates a vCluster named “terraform-vc01” within the parent cluster created in Step 3.

Terraform Script should look like this:

HCL
terraform {
  required_providers {
    taikun = {
      source  = "itera-io/taikun"
      version = "1.9.1" // Use the latest version
    }
  }
}

// Define connection to Taikun
provider "taikun" {
  email    = "test@example.com"
  password = "asdfghjkl"
}

// Define a Cloud credential (Connection to Openstack)
resource "taikun_cloud_credential_openstack" "foo" {
  name = "terraform-openstack-cc"

  user                = "zaphod"
  password            = "bEEblebrox4prez"
  url                 = "example.com"
  domain              = "domain"
  project_name        = "project_name"
  public_network_name = "public_network_name"
  region              = "region"
  lock                = false
}

// Create a BMW ccluster
resource "taikun_project" "proj" {
  name                = "tf-openstack-vc"
  cloud_credential_id = taikun_cloud_credential_openstack.foo.id
  flavors             = concat(local.flavors_small, local.flavors_big)

  server_bastion {
    name      = "tf-bastion"
    disk_size = 30
    flavor    = local.flavors_small[0]
  }
  server_kubemaster {
    name      = "tf-master"
    disk_size = 30
    flavor    = local.flavors_small[0]
  }
  server_kubeworker {
    name      = "tf-worker"
    disk_size = 100
    flavor    = local.flavors_big[0]
  }
}

resource "taikun_virtual_cluster" "foo" {
  name      = "terraform-vc01"
  parent_id = taikun_project.proj.id
}

// Flavors configuration. Filtering data sources
data "taikun_flavors" "small" {
  cloud_credential_id = taikun_cloud_credential_openstack.foo.id
  min_cpu             = 2
  max_cpu             = 2
  min_ram             = 4
  max_ram             = 4
}
data "taikun_flavors" "big" {
  cloud_credential_id = taikun_cloud_credential_openstack.foo.id
  min_cpu             = 4
  max_cpu             = 4
  min_ram             = 8
  max_ram             = 8
}
locals {
  flavors_small = [for flavor in data.taikun_flavors.small.flavors : flavor.name]
  flavors_big   = [for flavor in data.taikun_flavors.big.flavors : flavor.name]
}

Conclusion

In this tutorial, we learned how to set up a vCluster on Taikun Cloudworks using the Taikun Terraform provider. We defined a cloud credential, created a parent cluster, and then provisioned a vCluster within it.

VClusters provide a convenient way to isolate and manage resources within a parent cluster. With Taikun Cloudworks and Terraform, you can automate the deployment and management of vCluster, making it easier to scale and optimize your Kubernetes infrastructure.

For more information and advanced configuration options, refer to the Taikun Terraform Provider documentation.

Taikun CloudWorks is a one-stop solution for your Kubernetes workloads. Try our vCluster with Taikun CloudWorks Interactive demo below. Book your free demo today, and let our team simplify, enhance, and streamline your infrastructure management.

Virtual Clusters Demo
Explore our platform