This guide describes how to create a basic Kubernetes cluster in City Cloud using Terraform and Rancher/RKE provider and importing the newly created cluster in Rancher.
Rancher is a Kubernetes Cluster Manager and it can be installed into a Kubernetes Cluster which itself can be provisioned by Rancher RKE (Rancher Kubernetes Engine) or, within Terraform, by the RKE community provider.
Terraform is an open-source infrastructure as code software tool created by HashiCorp. It enables users to define and provision a datacenter infrastructure using a high-level configuration language known as Hashicorp Configuration Language, or optionally JSON. Source
- A CityCloud account
- Terraform software installed
- Terraform RKE Community provider plugin installed
- Kubectl software installed
In this example, we will follow the below steps
Step 1 - Create the Terraform configuration
In this step we will create the Terraform configuration to deploy our nodes and install the Rancher Server.
We will create the following VMs:
- 1 VM for the Rancher Server
- 1+2 VMs for a Kubernetes cluster: 1 Master (etcd+control_plane) and 2 Worker nodes
with 4 vCPU, 4 GB RAM and 50GB of disk size.
The Rancher example code containing the Terraform configuration is available in our public GitHub repository.
Step 2 - Source your Openstack project RC-file
Download your Openstack project RC-file from the control panel (How-to?).
Source the file with `source openstack.rc`
Terraform will automatically read and use the environment variables when needed.
More info about how Terraform uses the environment variables here.
Step 3 - Apply the configuration
Once you are ready with the configuration, it's time to initialise Terraform and apply the configuration.
Initialise Terraform In the same directory where the configuration files are stored by running:
We can now apply the configuration using the following command:
The terraform.tfstate file is generated and used by Terraform to store and maintain the state of your infrastructure as well as the kube_config_cluster.yaml for the connection to the Kubernetes Rancher cluster.
Step 4 - Verify the cluster
Now that the 1+2 cluster configuration is successfully applied, use the following commands to check cluster's connectivity:
Step 5 - Access the Kubernetes Dashboard
In this example we deployed the Kubernetes Dashboard alongside the Rancher dashboard.
To get access to the Kubernetes dashboard you need to retrieve your token using the following command:
Copy the command output and launch kubectl proxy with:
Paste the Token generated earlier and get access to the Kubernetes Dashboard.
Step 6 - Access the Rancher UI
Open the Rancher Server IP URL returned by the Terraform configuration:
As this is just an example and no real certificates have been used, you need to use a browser that allows you to override the certificate warnings as for example Firefox or Safari.
Set a password for the admin user and press Continue.
You have successfully installed the Rancher Management server and its dashboard:
Step 7 - Import your cluster nodes
Once in the Dashboard, create a new Kubernetes cluster from ⚙️Existing nodes
Enter your cluster name and as In-Tree Cloud Provider select Custom.
Select etcd and Control Plane role and copy the command.
Login into the cluster's Master VM using the floating IPs prompted in Step 4.
and run the command prompted by the UX interface, that looks like the one shown below:
Rancher will then start registering the VM into your newly created Rancher-managed cluster according to the selected role.
A notification bar like the one below will be prompted:
🔁 Repeat these steps on the Worker nodes, selecting Worker as role and by running the related prompted command in each VM.
Once done, you will then be able to see all resources allocated to your cluster.
You have just created your first Kubernetes Cluster and imported it into Rancher, one of the most complete open-source Kubernetes Manager.
This basic example presented an easy way to deploy your Kubernetes cluster using Openstack resources in CityCloud, and then manage them via the Rancher Management server.
Cluster creation can also be automated and our Rancher as a Service (RaaS) solution comes with a fully automated way to deploy and handle your cluster via our managed Rancher Management server available in Public and Compliant Cloud.
* Please report any typos, bugs or errors you find in the documentation or code.