Using Terraform

In a new folder, we create the following Terraform configuration files, they contain all the resources to create a SKS cluster and the related components:

  • provider.tf specifies the version of the Exoscale provider
  • security_group.tf specifies the security group and the rules to be applied to the cluster’s nodes
  • cluster.tf defines the cluster’s configuration
  • node_pool.tf defines the group of nodes associated to the cluster
  • kubeconfig.tf is used to create a local kubeconfig file to access the cluster
  • variables.tf defines the input information
  • output.tf specifies the information to be displayed back
terraform {
  required_providers {
    exoscale = {
      source  = "exoscale/exoscale"
      version = "~> 0.60.0"
    }
  }
}

provider "exoscale" {}

Next, we need to set env variables so that Terraform can use the Exoscale API.

export EXOSCALE_API_KEY=...
export EXOSCALE_API_SECRET=...

Next, we initialize terraform so it gets the correct version of the provider.

terraform init

We verify everything is correctly configured simulating the creation.

terraform plan

Then, if no error is raised, we create the cluster and the related resources.

terraform apply

A file named “kubeconfig” is created in the current folder. We can configure our local kubectl binary and access the cluster.

export KUBECONFIG=$PWD/kubeconfig
$ kubectl get nodes
NAME               STATUS   ROLES    AGE   VERSION
pool-92e0f-fqjys   Ready    <none>   2m    v1.31.0
pool-92e0f-ofcko   Ready    <none>   2m    v1.31.0
pool-92e0f-tygzv   Ready    <none>   2m    v1.31.0

Once you are done using the cluster, don’t forget to delete it, and the associated resources, with the following command:

terraform destroy