Prerequisites

  • Terraform installed
  • NPM installed
  • An existing Rancher server. Create it if you don’t have one.
  • A Latitude.sh account with an API key

Important notes

  • Ensure you have an existing Rancher server where the cluster will be created. This Terraform plan does not create the Rancher server.
  • The rancher_api_url should be in the format https://<your-rancher-server>/v3.
  • Make sure your Rancher server is accessible from the internet, as the Latitude.sh servers will need to communicate with it.
  • The default configuration creates a cluster with 3 worker nodes. Adjust the node_count variable if you need a different number of nodes.
1

Download the example files

Download the example files using degit:
npx degit latitudesh/examples/terraform/kubernetes-rancher my-kubernetes-cluster
cd my-kubernetes-cluster
2

Initialize Terraform

bash terraform init
3

Update variables

Update the variables.tf file with your details:
  • LATITUDESH_AUTH_TOKEN: Don’t hardcode this. You will be asked for it when planning and applying your plan.
  • project_id: The ID of the project you want to deploy to. Find this from the home page in the console by clicking on the three dots above the project followed by Copy ID.
  • plan: The plan slug. Simply replace the plan name with hyphens instead of dots. For example, for the m4.metal.medium, use m4-metal-medium
  • region: The slug of the location you want to deploy to. E.g., for Dallas use DAL. Find all with the api.latitude.sh/locations endpoint.
  • ssh_key_id: The ID of the SSH key you want to use for the nodes. Find this in the console under Project settings > SSH keys
  • private_key_path: This script will access your servers during setup. Add the local path in your computer where the private key of the SSH Key inserted above.
  • rancher_api_url: The rancher_api_url should be in the format https://<your-rancher-server>/v3.
  • RANCHER_ACCESS_KEY: The access key is available in your control plane. Find more details on the Rancher docs. Create one from the Rancher UI by going to User > Account & API Keys.
  • RANCHER_SECRET_KEY: The token’s password. Find more details on Rancher Doc in the API Keys.
  • server_count: Number of nodes to provision and add to the cluster.
4

Plan your Terraform execution

bash terraform plan -var-file="secret.tfvars"
5

Apply the changes

If the plan looks good, apply the changes:
terraform apply -var-file="secret.tfvars"
Confirm by typing yes when prompted.

Cleaning Up

To destroy the resources created by this Terraform plan:
terraform destroy

Support

If you encounter any issues or have questions, please open an issue in the examples repository.