kubermatic / kubeone

Kubermatic KubeOne automate cluster operations on all your cloud, on-prem, edge, and IoT environments.
https://kubeone.io
Apache License 2.0
1.36k stars 231 forks source link

output.tf template for Civo provider #1621

Closed exocode closed 2 years ago

exocode commented 2 years ago

Civo https://www.civo.com/ is a relatively new and cheap Kubernetes cloud provider and has a fully working Terraform registry: https://registry.terraform.io/providers/civo/civo/latest/

What feature would you like to be added?

In order to deploy a KubeOne cluster at Civo, an output.tf file must be provided.

Civo offers a 250$ free start account, which can be used up within 2 months, which is definitely enough to achieve that task. I am not a Terraform expert, but it seems quite possible, when I look at the output.tf file for Hetzner.

I share here a most basic three instance cluster manifest to spin up a Kubernetes cluster at Civo:


# versions.tf
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    civo = {
      source  = "civo/civo"
      version = "1.0.5"
    }
  }
}

# provider.tf

provider "civo" {
  token  = var.civo_token
  region = var.datacenter
}

# main.tf

# Query xsmall instance size
data "civo_instances_size" "xsmall" {
  filter {
    key    = "type"
    values = ["kubernetes"]
  }

  sort {
    key       = "ram"
    direction = "asc"
  }
}

# Create a firewall
resource "civo_firewall" "kubeone-firewall" {
  name = "kubeone-firewall"
}

# Create a firewall rule
resource "civo_firewall_rule" "kubernetes" {
  firewall_id = civo_firewall.kubeone-firewall.id
  protocol    = "tcp"
  start_port  = "6443"
  end_port    = "6443"
  cidr        = ["0.0.0.0/0"]
  direction   = "ingress"
  label       = "kubernetes-api-server"
}

# Create a cluster
resource "civo_kubernetes_cluster" "kubeone-cluster" {
  region = var.datacenter
  name   = var.cluster_name
  # applications      = "Redis,Linkerd:Linkerd & Jaeger"
  num_target_nodes  = var.control_plane_replicas
  target_nodes_size = element(data.civo_instances_size.xsmall.sizes, 0).name
  firewall_id       = civo_firewall.kubeone-firewall.id
}

data "civo_kubernetes_cluster" "kubeone-cluster" {
  name = "kubeone-cluster"
}

# output.tf

output "kubeone_api" {
  description = "kube-apiserver LB endpoint"

  value = {
    endpoint = data.civo_kubernetes_cluster.kubeone-cluster.master_ip
  }
}
shaase-ctrl commented 2 years ago

Hello @exocode, thank you for the contribution, we will consider Civo for future releases but please be aware that supporting providers is a complex task on the long run and we already support a broad variety.

exocode commented 2 years ago

sure.. I keep watching this feature request. If you want, close it.

shaase-ctrl commented 2 years ago

If you want to, we would of course accept your contribution.

exocode commented 2 years ago

What I provided is only a template to have a base to start. It spins up a 3 tier k8s cluster in Civo. But I am not that familiar with Terraform to extend this base to the needs of KubeOne. I only saw the output.tf for Hetzner's implementation and thought that someone with Terraform experience could achieve that in less than one day.

xmudrii commented 2 years ago

@exocode It's a bit more complicated. For KubeOne to support a cloud provider, that cloud provider must be also supported by Kubermatic machine-controller. machine-controller should use the Civo Go API to create worker nodes. Once machine-controller supports it, we can bump the MC version in KubeOne and add Terraform support for Civo. This means adding Terraform scripts, but also updating Terraform integration to be able to parse that output. If you're interested to work on this, we can give you pointers how to do it but expect it to be a little bit more effort than just one day.

kron4eg commented 2 years ago

TBH, I don't even understand why one would need KubeOne for civo, if it's already a KUBERNETES PROVIDER.

resource "civo_kubernetes_cluster" "cluster" {

gives you a functioning cluster, why would you need help of kubeone?!

exocode commented 2 years ago

TBH, I don't even understand why one would need KubeOne for civo, if it's already a KUBERNETES PROVIDER.

resource "civo_kubernetes_cluster" "cluster" {

gives you a functioning cluster, why would you need help of kubeone?!

You're right. 🤔 They also offer bare-metal.. I didn't thought that far. I had so much providers in focus the last weeks, that I cant see the wood for the trees. 😅 If you say, that KubeOne is exactly that what Civo offers, then I understand you. I had the "self-healing" functionality in my mind. But that could also be done with something like Crossplane.

I will close this issue now, sorry for making noise