One-Click Kubernetes Cluster Creation on Rancher
Previously, I was creating Kubernetes clusters on Rancher manually. Since I frequently create and delete clusters for testing purposes, doing this by hand every time gets tedious quickly.
In this post, I’ll walk through creating a Rancher cluster and the follow-up steps needed afterward.
Creating a Cluster
To deploy a new cluster on a fresh Rancher installation, the following steps are required:
- Create a Cloud Credential, which will be needed by the Node Template later.
- Create Kubernetes Master and Worker Node Templates. As of Rancher 2.3.5, you can manually select configuration options such as Datacenter, Datastore, Folder, and Network.
- Create a Cluster.
- (Optional) Configure the Kubernetes Cloud Provider.
This is a repetitive process, so I tried to codify these steps using Terraform — Infrastructure as Code. I’ve saved the code on GitHub: https://github.com/chengqing-su/vsphere-cluster-on-rancher
How to Use
First, clone the repository.
1 | git clone git@github.com:chengqing-su/vsphere-cluster-on-rancher.git |
Then, create a new file terraform/terraform.tfvars, and fill in the following content:
1 | name = "<YOUR-CLUSTER-NAME>" |
Then, run the automation script auto/deploy to deploy with a single command.
When the cluster is no longer needed, run auto/destory to tear it down with a single command.
After Creating the Cluster
Once a cluster is up and running, a few follow-up steps can improve the experience.
Create a Default Storage Class
PersistentVolumes (PVs) can be provisioned in two ways: administrators can create them manually, or they can be dynamically provisioned through a StorageClass. As a result, creating a StorageClass is often necessary to make storage resources available.
Below is the StorageClass manifest:
1 | apiVersion: storage.k8s.io/v1 |
Apply the manifest above with kubectl to create a default StorageClass.
Configure a Load Balancer
When creating a Service of type LoadBalancer, I found that it would never succeed.
To resolve this, you can install an application called metallb from the App catalog. After installation, you also need to create a ConfigMap with the following content:
1 | apiVersion: v1 |