The available selectable options could also be checked using the Opnstack CLI commands : $ openstack keypair list
$ openstack image list
$ openstack flavor list
$ openstack network list |
Write configuration filesCreate a directory for your configuration and change directory into it: $ mkdir example-magnum-k8s
$ cd example-magnum-k8s |
Create the main configuration file to define the infrastructure:
Open the main.tf file in a text editor and fill it as needed like in the following minimal example : 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"
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
For instance for ECMWF can be : resource "openstack_compute_instance_v2" "test-server" {
name = "test-server"
image_name = "Rocky-9.4-20240717094419"
flavor_name = "2cpu-2gbmem-30gbdisk"
key_pair = "mykey"
security_groups = ["default", "ssh"]
network {
name = "private-cci1-ewcloud-ms-nmhs-project"
}
} |
Run Terraform or OpenTofu to create a Kubernetes cluster via OpenStack MagnumInitialize the directory :
Review the required changes:
Apply the changes to create the Kubernetes cluster :
Status can be then seen via: Destroy the ClusterThe created cluster can be then destroyed by simply running:
|