Using Terraform
In a new folder, we create the following Terraform configuration files; they contain all the resources to create an 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 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
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 initWe verify everything is correctly configured, simulating the creation.
terraform planThen, if no error is raised, we create the cluster and the related resources.
terraform applyWe use the file named “kubeconfig”, created in the current folder, to configure our local kubectl binary.
export KUBECONFIG=$PWD/kubeconfigThen, we verify we can access the cluster, listing its nodes.
kubectl get nodesOnce you have completed the workshop, don’t forget to delete the cluster and the associated resources with the following command:
terraform destroy