> ## Documentation Index
> Fetch the complete documentation index at: https://www.latitude.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Rancher RKE2

> Deploy Kubernetes clusters using Rancher and Terraform on bare metal servers

## Prerequisites

* [Terraform](https://www.terraform.io/downloads.html) installed
* [NPM](https://www.npmjs.com/get-npm) installed
* An existing Rancher server. [Create it](/guides/kubernetes-on-bare-metal) 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.

<Steps>
  <Step title="Download the example files">
    Download the example files using degit:

    ```bash theme={null}
    npx degit latitudesh/examples/terraform/kubernetes-rancher my-kubernetes-cluster
    cd my-kubernetes-cluster
    ```
  </Step>

  <Step title="Initialize Terraform">`bash terraform init `</Step>

  <Step title="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](https://www.latitude.sh/dashboard) 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](https://ranchermanager.docs.rancher.com/reference-guides/user-settings/api-keys). 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](https://ranchermanager.docs.rancher.com/reference-guides/user-settings/api-keys) in the API Keys.
    * `server_count`: Number of nodes to provision and add to the cluster.
  </Step>

  <Step title="Plan your Terraform execution">
    `bash terraform plan -var-file="secret.tfvars" `
  </Step>

  <Step title="Apply the changes">
    If the plan looks good, apply the changes:

    ```bash theme={null}
    terraform apply -var-file="secret.tfvars"
    ```

    Confirm by typing `yes` when prompted.
  </Step>
</Steps>

## Cleaning Up

To destroy the resources created by this Terraform plan:

```bash theme={null}
terraform destroy
```

## Support

If you encounter any issues or have questions, please open an issue in the [examples repository](https://github.com/latitudesh/examples/issues).
