Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt

The available selectable options could also be checked using the Opnstack CLI commands :

Code Block
$ openstack keypair list
 
$ openstack image list
 
$ openstack flavor list 
 
$ openstack network list


Write configuration files

Create a directory for your configuration and change directory into it:

Code Block
$ mkdir example-magnum-k8s

$ cd example-magnum-k8s


Create the main configuration file to define the infrastructure:

Code Block
$ touch main.tf


Open the main.tf file in a text editor and fill it as needed like in the following minimal example :

Code Block
terraform {
  required_providers {
    openstack = {
      source = "terraform-provider-openstack/openstack"
    }
  }
}

provider "openstack" {
  cloud = "openstack"
}

variable "magnum_cluster_template" {
  description = <<EOT
  The name of the Magnum cluster template to create the kubernetes cluster with

  You may view a list of available template by running `openstack coe cluster template list`
  EOT
  type        = string
  default     = "cluster-template-name"
}

data "openstack_containerinfra_clustertemplate_v1" "clustertemplate" {
  name = var.magnum_cluster_template
}

resource "openstack_containerinfra_cluster_v1" "cluster" {
  name                = "cluster-name"
  cluster_template_id = data.openstack_containerinfra_clustertemplate_v1.clustertemplate.id
  master_count        = "master-count"
  master_flavor       = "master-flavor-name"
  node_count          = "worker-node-count"
  flavor              = "worker-node-flavor-name"
  keypair             = "ssh-keypair-name"
  fixed_network       = "private-network-name"
  fixed_subnet        = "private-subnet-name"
  labels              = {
     monitoring_enabled   = "true"
     auto_healing_enabled = "true"
     }
  merge_labels        = "true"
  create_timeout      = "180"

}


Replace the following fields as desired:



  • cluster-template-name
  • cluster-name
  • master-count
  • master-flavor-name
  • worker-node-count
  • worker-node-flavor-name
  • ssh-keypair-name
  • private-network-name
  • private-subnet-name


For instance for ECMWF it can be :

Expand
titleClick here to expand the example...
Code Block
terraform {
  required_providers {
    openstack = {
      source = "terraform-provider-openstack/openstack"
    }
  }
}

provider "openstack" {
  cloud = "openstack"
}

variable "magnum_cluster_template" {
  description = <<EOT
  The name of the Magnum cluster template to create the kubernetes cluster with

  You may view a list of available template by running `openstack coe cluster template list`
  EOT
  type        = string
  default     = "kubernetes-1-32-jammy"
}

data "openstack_containerinfra_clustertemplate_v1" "clustertemplate" {
  name = var.magnum_cluster_template
}

resource "openstack_
compute
containerinfra_
instance
cluster_
v2
v1" "
test-server
cluster" {
  name                = "
test-server"
mycluster"
  cluster_template_id = data.openstack_containerinfra_clustertemplate_v1.clustertemplate.id
  
image
master_
name
count        = "
Rocky-9.4-20240717094419
3"
  master_flavor
_name
       = "
2cpu
4cpu-
2gbmem
4gbmem-30gbdisk"
  
key
node_
pair
count          = "
mykey
2"
  flavor             
security_groups
 = 
[
"
default", "ssh"] network {
4cpu-4gbmem-30gbdisk"
  keypair             = "mykeypair"
  fixed_network      
name
 = "private-cci1-ewcloud-ms-nmhs-project"
  fixed_subnet        = "cci1-ewcloud-ms-nmhs-project-private"
  labels              = {
     monitoring_enabled   = "true"
     auto_healing_enabled = "true"
     }
  merge_labels        = "true"
  create_timeout      = "180"

}



Run Terraform or OpenTofu to create a Kubernetes cluster via OpenStack Magnum

Initialize the directory :

Section
bordertrue
Column

Terraform

Code Block
$ terraform init


Column

OpenTofu

Code Block
$ tofu init



Review the required changes: 

Code Block
$ terraform plan


Apply the changes to create the Kubernetes cluster :

Section
bordertrue
Column

Terraform

Code Block
$ terraform apply


Column

OpenTofu

Code Block
$ tofu apply



Status can be then seen via:

Section
bordertrue
Column

Terraform

Code Block
$ terraform show


Column

OpenTofu

Code Block
$ tofu show


Destroy the Cluster

The created cluster can be then destroyed by simply running:

Section
bordertrue
Column

Terraform

Code Block
$ terraform destroy


Column

OpenTofu

Code Block
$ tofu destroy




...