In the era of DevOps and micro-services, Kubernetes is playing an important role in the IaaS ecosystem, enabling flexibility and simplification of the application's underlying platform implementation.
However, this is true to certain level of extent meaning only when you have a wide-range of tools that allow you to control, monitor and scale your infrastructure upon your application needs.
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.
Note. 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
- 3 VMs for Master (etcd + control_plane) and Worker nodes
with 4 vCPU, 4 GB RAM and 50GB of disk size.
Also, we will use RancherOS, the smallest and easiest way to run Docker, even in production.
The Rancher RKE project folder containing the Terraform configuration is available in our 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 `terraform init`
We can now apply the configuration with `terraform apply`:
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.
Note. terraform.tfstate and kube_config_cluster.yaml can possibly contain sensitive information.
Step 4 - Verify the cluster
Now that the configuration is successfully applied, use the following commands to check connectivity:
of your cluster.
Step 5 - Access the Kubernetes Dashboard
Before accessing the Kubernetes Dashboard a token is needed to log in.
Note. To find out more about how to configure and use Bearer Tokens, please refer to the Kubernetes Authentication section.
Generate your token using the following command:
Set up the kubectl proxy using:
and login at:
using the token generated in the previous step.
You should then finally be able to access the Kubernetes Dashboard.
Step 6 - Access the Rancher UI
Open the link prompted at the end of the terraform configuration using "admin123" as password.
As this is just an example and no real certificates have been used.We recommend to use an old version of your browser or less strict browsers as Firefox or Safari (Mac)
Step 7 - Import your cluster nodes
Once in the Dashboard, add a new cluster selecting '⚙️ From existing nodes (Custom)'
Enter your cluster name and as Cloud Provider select 'Custom'. Press Next.
You will now be prompted different roles you might want to have for your nodes.
For simplicity, we will tick all 3 node roles: etcd, Control Plane and Worker.
Login into the first VM using the floating IPs prompted in Step 4.
and run the command prompted by the UX interface, similar to the one shown below:
Repeat this step for the other 2 VMs.
Rancher will then start importing your 3 VMs into your newly created cluster one at the time.
A notification bar like the one below will be also prompted.
Once done, you will then be able to see all resources allocated to your cluster and you can start deploying any application on top of it by using Rancher too.
You have just created your first Kubernetes Cluster and imported it into Rancher, one of the most complete open-source Kubernetes Manager.
* Please report any typos, bugs or errors you find in the documentation or code.