Infrastructure as Code: Provision OVHcloud Kubernetes with Terraform

What You'll Learn
  • Use Terraform to provision an OVHcloud Managed Kubernetes cluster
  • Automate node pool creation
  • Generate the kubeconfig file to connect and deploy apps
Prerequisites
  • OVHcloud Public Cloud account
  • OpenStack-compatible credentials (from OVHcloud panel)
  • Terraform installed (v1.0+)
  • A configured OVHcloud project with credit
  • Basic knowledge of HCL (HashiCorp Configuration Language)
Get Your OVHcloud API Credentials

In the OVHcloud Control Panel:

  • Go to Public Cloud → Users & Roles → OpenStack
  • Create a user and download the OpenStack RC file
  • Note:
    • OS_TENANT_ID / OS_PROJECT_ID
    • OS_USERNAME, OS_PASSWORD
    • OS_AUTH_URL, usually something like https://auth.cloud.ovh.net/v3/
Set Up Terraform Configuration

Create a new folder and add these files:

main.tf

provider "openstack" {
  user_name   = var.os_username
  tenant_id   = var.os_tenant_id
  password    = var.os_password
  auth_url    = var.os_auth_url
  region      = var.os_region
  domain_name = "Default"
}

resource "openstack_containerinfra_cluster_v1" "k8s" {
  name            = var.cluster_name
  keypair         = var.keypair_name
  cluster_template_id = var.template_id
  node_count      = var.node_count
  master_count    = 1
  discovery_url   = ""
}

output "cluster_id" {
  value = openstack_containerinfra_cluster_v1.k8s.id
}

variables.tf

variable "os_username" {}
variable "os_password" {}
variable "os_tenant_id" {}
variable "os_auth_url" {}
variable "os_region" {
  default = "GRA9"
}

variable "cluster_name" {
  default = "ovhcloud-k8s"
}

variable "keypair_name" {
  default = "default"
}

variable "template_id" {
  default = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # Replace with your own
}

variable "node_count" {
  default = 2
}

terraform.tfvars (never commit this!)

os_username     = "your-user"
os_password     = "your-pass"
os_tenant_id    = "your-project-id"
os_auth_url     = "https://auth.cloud.ovh.net/v3/"
Find Your Cluster Template ID

OVHcloud provides default Kubernetes templates. You can list them using the OpenStack CLI or from the control panel.

Using OpenStack CLI:

openstack coe cluster template list

Pick one like kubernetes-1.27.0 and use its ID in variables.tf.

Deploy with Terraform
terraform init
terraform plan
terraform apply

Once complete, your cluster will be provisioned.

Get the kubeconfig File

Use the OVHcloud CLI or Terraform output to get the kubeconfig and save it to ~/.kube/config:

ovh kubernetes cluster kubeconfig --region GRA9 --name ovhcloud-k8s > ~/.kube/config

Or download it via the OVHcloud dashboard → Kubernetes section.

Verify the Cluster
kubectl get nodes
kubectl get pods --all-namespaces

You're connected and ready to deploy workloads.

Destroy the Cluster

To clean everything up:

terraform destroy