This page describes how to create a new Kubernetes cluster via OpenStack Magnum by using Terraform or OpenTofu.
Pre-requisites
The following pre-requisites must be satisfied.
- Have read and followed the EWC - IaC via Terraform and OpenTofu page.
- The Terraform or OpenTofu CLI installed.
- Application credentials to access the Openstack cloud project
There is a set of mandatory inputs required to create a new cluster which are:
- flavor_name : the resources (CPU, RAM, Disk) configuration for the VM (see as reference EWC VM plans )
- key_pair : configured SSH key which is needed to connect to the VM (see EWC - OpenStack Command-Line client for how to import it )
- security_groups : security groups are sets of applied IP filter rules which define networking access to the instance
- network : the network to be attached to the VM : external-internet: access to the Internet with public IP ; private-<tenant>: local private network within the tenant.
Create a directory for your configuration and change directory into it: Create the main configuration file to define the infrastructure: Open the Replace the following fields as desired: For instance it can be : Initialize the directory : Terraform OpenTofu Review the required changes: Apply the changes to create the Kubernetes cluster : Terraform OpenTofu Status can be then seen via: Terraform OpenTofu The created cluster can be then destroyed by simply running: Terraform OpenTofu
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 files
$ mkdir example-magnum-k8s
$ cd example-magnum-k8s
$ touch main.tf
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-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"
}
Run Terraform or OpenTofu to create a Kubernetes cluster via OpenStack Magnum
$ terraform init
$ tofu init
$ terraform plan
$ terraform apply
$ tofu apply
$ terraform show
$ tofu show
Destroy the Cluster
$ terraform destroy
$ tofu destroy