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 flavor list 
 
$ openstack network list

$ openstack subnet list


and for the Magnum cluster templates :

Code Block
openstack coe cluster template list
Note

The cluster templates are maintained by ECMWF can be recognized by the name which follow the convention "kubernetes-(k8s version)-(ubuntu version name)" (e.g. kubernetes-1-32-jammy)


The predefined settings of the provided cluster templates can be explored by running  the command:

Code Block
openstack coe cluster template show <cluster-template>

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" #cloud name in clouds.yaml
}

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 required:



  • 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 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" #cloud name in clouds.yaml
}

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_containerinfra_cluster_v1" "cluster" {
  name                = "mycluster"
  cluster_template_id = data.openstack_containerinfra_clustertemplate_v1.clustertemplate.id
  master_count        = "3"
  master_flavor       = "4cpu-4gbmem-30gbdisk"
  node_count          = "2"
  flavor              = "4cpu-4gbmem-30gbdisk"
  keypair             = "mykeypair"
  fixed_network       = "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: 

Section
bordertrue
Column

Terraform

Code Block
$ terraform plan


Column

OpenTofu

Code Block
$ tofu 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



...