This page describes how to create a new Kubernetes cluster via OpenStack Magnum by using Terraform or OpenTofu.
The following pre-requisites must be satisfied.
There is a set of mandatory inputs required to create a new cluster which are:
- flavor : the resources (CPU, RAM, Disk) configuration for the nodes (see as reference EWC VM plans )
- keypair : configured SSH key which is needed to connect to the VM (see EWC - OpenStack Command-Line client for how to import it )
- network : the network to be attached to the cluster ; private-<tenant>: local private network within the tenant.
- subnet : network subnet within the tenant
- cluster templates : existing set of provided Magnum Kubernetes cluster templates
| 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> |
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 |
|---|
| title | Click 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"
} |
|
Initialize the directory : | Section |
|---|
| | Column |
|---|
Terraform | Code Block |
|---|
$ terraform init |
|
|
Review the required changes: | Section |
|---|
| | Column |
|---|
Terraform | Code Block |
|---|
$ terraform plan |
|
|
Apply the changes to create the Kubernetes cluster : | Section |
|---|
| | Column |
|---|
Terraform | Code Block |
|---|
$ terraform apply |
|
|
Status can be then seen via: | Section |
|---|
| | Column |
|---|
Terraform | Code Block |
|---|
$ terraform show |
|
|
|
| Excerpt Include |
|---|
| ECMWF EWC Managed Kubernetes Service - Create a Kubernetes cluster via the OpenStack CLI |
|---|
| ECMWF EWC Managed Kubernetes Service - Create a Kubernetes cluster via the OpenStack CLI |
|---|
| nopanel | true |
|---|
|