Creating a Self-Hosted Kubernetes Cluster on Proxmox with Taikun CloudWorks using Terraform

By Rohit Ghumare 6 min read
Creating a Self-Hosted Kubernetes Cluster on Proxmox with Taikun CloudWorks using Terraform
Creating a Self-Hosted Proxmox Kubernetes Cluster with Taikun CloudWorks and Terraform

Introduction

In this blog post, we'll walk through the process of creating a Kubernetes cluster on Proxmox using Taikun CloudWorks and Terraform. We'll leverage the Taikun Terraform provider to automate the deployment of a Kubernetes cluster on your Proxmox infrastructure.

Let's consider a scenario:

Meet Sarah, a DevOps engineer at a rapidly growing tech startup. Her company has been using on-premises Proxmox infrastructure for its development and testing environments, but as the business expands, they need to scale their operations and adopt Kubernetes for better container orchestration.

Sarah faces several challenges:

  • Manual provisioning: Setting up Kubernetes clusters on Proxmox manually is time-consuming and error-prone.
  • Lack of standardization: Different team members create clusters with varying configurations, leading to inconsistencies.
  • Scaling difficulties: As the company grows, manually managing multiple clusters becomes increasingly complex.
  • Limited visibility: There's no centralized way to monitor and manage all the Kubernetes clusters across their Proxmox infrastructure.
  • Compliance concerns: Ensuring all clusters meet security and compliance standards is a constant struggle.

Sarah knows automating this process would solve many of these issues, but creating a custom solution seems daunting and time-consuming. We present Taikun's terraform provider that can help you spin up Proxmox Kubernetes clusters with a click. This integration offers Sarah a powerful solution:

  • Infrastructure as Code: Sarah can now define her Proxmox Kubernetes clusters using Terraform, ensuring consistency and repeatability.
  • Simplified management: Taikun provides a centralized platform for managing multiple Kubernetes clusters across Proxmox nodes.
  • Scalability: As the company grows, Sarah can easily manage and scale multiple clusters using the same Terraform configurations.
  • Enhanced visibility: Taikun offers monitoring and management features, giving Sarah's team better insight into their Kubernetes environments.
  • Automated provisioning and Standardization: With a few lines of Terraform code, Sarah can spin up fully configured Kubernetes clusters on Proxmox in minutes and maintain the same standard modules across the entire company.
  • Compliance automation: Sarah can bake security and compliance requirements into her Terraform templates, ensuring all new clusters meet company standards.

Sarah transforms her company's Kubernetes on Proxmox on-premise solution. She reduces cluster provisioning time from days to minutes, eliminates configuration inconsistencies, and gains the ability to manage their growing infrastructure efficiently.

This integration bridges the gap between Proxmox's powerful virtualization capabilities and the need for automated, scalable Kubernetes deployments, empowering companies like Sarah's to leverage their on-premises infrastructure for modern, container-based applications.

Prerequisites

Before we begin, ensure you have:

  • A Taikun CloudWorks account with access to Proxmox integration
  • Proxmox environment set up and accessible
  • Terraform installed on your local machine

Our Proxmox Kubernetes Cluster, built using Terraform, will have the following architecture:

Step 1: Set Up the Terraform Configuration

First, create a new directory for your Terraform project and initialize it:

$ mkdir proxmox-k8s-taikun

$ cd proxmox-k8s-taikun

$ terraform init

Note: To use the taikun_cloud_credential_proxmox resource, you need a Manager or Partner account role.

Create a main.tf file with the following content: Use Taikun terraform provider from terraform website:

terraform {

  required_providers {

    taikun = {

      source  = "itera-io/taikun"

      version = "~> 1.8.0"

    }

  }

}

provider "taikun" {

  email    = "user@itera.io" #your email id

  password = "userpassword" #your password

  api_host = "api.taikun.cloud"

}

Step 2: Define Proxmox Cloud Credentials

Add the following to your main.tf to set up Proxmox credentials in Taikun:

resource "taikun_cloud_credential_proxmox" "rohit_proxmox" {

  name = "rohit-proxmox-demo"

  #Add authentication url for proxmox here
  api_host         = "https://foo.example.com/fooapi/json" 

  client_id        = "your-proxmox-clientid"

  client_secret    = "your-proxmox-clientsecret"

  hypervisors      = ["hyper-test1", "hyper-test2]

  storage          = "lvm-thin"

  vm_template_name = "itera-cloudinit-template"

  private_ip_address             = "192.168.101.0"

  private_net_mask               = "24"

  private_gateway                = "192.168.101.1"

  private_begin_allocation_range = "192.168.101.10"

  private_end_allocation_range   = "192.168.101.200"

  private_bridge                 = "vmbr1"

  public_ip_address             = "78.24.12.96"

  public_net_mask               = "28"

  public_gateway                = "78.24.12.97"

  public_begin_allocation_range = "78.24.12.102"

  public_end_allocation_range   = "78.24.12.110"

  public_bridge                 = "vmbr0"

  organization_id = "your-organization-id"

  lock            = false

  continent       = "Europe"

}

If you want to add monitoring, load balancing, and many more capabilities to your cluster, it is essential. You can find more details in our documentation for the Terraform provider.

Step 3: Create a Taikun Project

Define a Taikun project that will use the Proxmox credentials:

data "taikun_flavors" "small" {

  cloud_credential_id = taikun_cloud_credential_proxmox.rohit_proxmox.id

  min_cpu             = 2

  max_cpu             = 8

}

data "taikun_images_proxmox" "images" {

  cloud_credential_id = taikun_cloud_credential_proxmox.rohit_proxmox.id

}

locals {

  flavors = [for flavor in data.taikun_flavors.small.flavors : flavor.name]

  images  = [for image in data.taikun_images_proxmox.images.images : image.id]

}

Step 4: Define the Kubernetes Profile

Create a Kubernetes profile for your cluster:

resource "taikun_kubernetes_profile" "demo" {

  name = "rohit-proxmox-demo"

  organization_id         = "your-organization-id"

}

Step 5: Deploy the Kubernetes Cluster

Now, let's create the Kubernetes cluster on Proxmox:

resource "taikun_project" "rohit_proxmox_demo" {

  name                = "rohit-proxmox-demo"

  cloud_credential_id = taikun_cloud_credential_proxmox.rohit_proxmox.id

  organization_id     = "your-organization-id"

  kubernetes_profile_id = taikun_kubernetes_profile.demo.id

  flavors = local.flavors

  images  = local.images

  server_bastion {

    name   = "bastion"

    flavor = local.flavors[0]

    hypervisor = "hyper-test1"

  }

  server_kubemaster {

    name   = "master"

    flavor = local.flavors[0]

    hypervisor = "hyper-test1"

  }

  server_kubeworker {

    name      = "worker"

    flavor    = local.flavors[0]

    disk_size = 30

    hypervisor = "hyper-test2"

    proxmox_extra_disk_size = 50

  }

}

If you want to play more with the taikun terraform provider, You can find more details in our documentation for the Terraform provider.

Step 6: Apply the Configuration

Now, apply the Terraform configuration:

$ terraform init

$ terraform plan

$ terraform apply

Expected Output:

Step 8: Accessing Your Cluster

After the cluster is created, you can access it through the Taikun dashboard. To get the kubeconfig:

  • Log in to the Taikun dashboard
  • You can see your Proxmox Infrastructure in Cloud Credentials added successfully
  • Navigate to your Proxmox project
  • Find your cluster inside it:
  • You can choose to use the terminal to access your cluster directly
  • You can also download the kubeconfig file to use on your local machine. Then, you can use this kubeconfig with kubectl to interact with your Proxmox-based Kubernetes cluster.

Deleting the cluster

When you're done, don't forget to destroy the resources:

terraform destroy

Conclusion

In this blog post, we've documented how to use Terraform and Taikun CloudWorks to create a Kubernetes cluster on Proxmox infrastructure. This approach allows for version-controlled, reproducible infrastructure deployment, making it easier to manage and scale your Kubernetes environments on Proxmox.

Try Taikun CloudWorks today. Book your free demo today, and let our team simplify, enhance, and streamline your infrastructure management.