Skip to content

Terraform

Creating a SKS cluster with Terraform

The current folder contains the terraform configuration files needed to create a SKS cluster and its related resources:

  • 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 defined 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

First 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

Next we verify everything is correctly configured by simulating the creation

terraform plan

Next, if no error are raised, we create the cluster and the related resources

terraform apply

A file named "kubeconfig" is created in the current folder. We can then 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

Cleanup

Once we are done we can delete the cluster and its associated resources

terraform destroy