arrow-left arrow-right brightness-2 chevron-left chevron-right circle-half-full facebook-box facebook loader magnify menu-down rss-box star twitter-box twitter white-balance-sunny window-close
Using Terraform to Deploy a Kubernetes (RKE) Cluster on
4 min read

Using Terraform to Deploy a Kubernetes (RKE) Cluster on

Using Terraform to Deploy a Kubernetes (RKE) Cluster on

Here is a quick walkthrough deploying a simple Kubernetes cluster from Rancher RKE using a plugin for Terraform. This tutorial will deploy a Kubernetes cluster compose of a single Master node, 2 Worker nodes, a kubectl configuration file on your workstation so you can securely manage your apps over a VPN connection.

This article was previously posted on blog.

The GitHub project page can be found here offers a regional cloud that delivers scalable, secure, and resilient multi-tenant and private cloud computing services.

I'm working there for few months and we provides some cool stuffs behind our IaaS like bare metal, edge deployments, integrated DevOps tooling...

I wrote this article with David Grenier. You can find him on Linkedin and you can find more informations about here.

Overview of RKE

Rancher Kubernetes Engine (RKE) is a CNCF-certified Kubernetes distribution that runs entirely within Docker containers. It works on bare-metal and virtualized servers. RKE solves the problem of installation complexity, a common issue in the Kubernetes community. With RKE, the installation and operation of Kubernetes is both simplified and easily automated, and it’s entirely independent of the operating system and platform you’re running. As long as you can run a supported version of Docker, you can deploy and run Kubernetes with RKE.


Install Terraform

On your workstation, install Terraform and make sure it is placed in your binary folder such as /usr/local/bin/ as executable for Linux/OSX:

Terraform Plugins

Download and install Terraform plugins for RKE and

To download the latest Terraform plugins:

On a Linux workstation, the following would apply:

mkdir -p ~/.terraform/plugins
cd /tmp
unzip -d ~/.terraform.d/plugins
unzip -d ~/.terraform.d/plugins

Remote Management VPN

We use the VPC Remote Management VPN service to create a secure connection between your workstation and VMs. This avoid the need to create port forwarding rules for SSH over the Internet.

Create/Connect to your VPN, In your portal, go to services -> <region name> -> <environment name> -> networking -> click on your VPC -> Remote access VPN (in the left menu)

For additional help on accessing your VPN go to

Terraform vars

First you will need to collect your api_key and id's : go to your portal interface.

For API key, go to profile -> API credentials -> Generate API key.

For environment_id, go to services -> <region name> -> click on the right side ... of your environment name and select Copy environment ID

For network_id, go to services -> <region name> -> <environment name> -> networking -> click on your VPC -> Networks (in the left menu) -> click on your network -> and collect the first ID under Attributes.

Install Kubectl

Install kubectl command on your workstation to manage the kubernetes cluster, follow offical documentation:

For mac OS:

brew install kubectl

Terraform Project

Next, clone the Terraform project repository from GitHub:

git clone

Then in the terraform project create a file called: terraform.tfvars in the git project directory and place your IDs in there as such:

api_key = "<ID>"
environment_id = "<ID>"
network_id = "<ID>"

Deploy RKE

Validate the Terraform project repository and initialize the Terraform plan with your IDs from the project:

make init plan 

Apply the Terraform plan on to deploy RKE:

make apply


Once the deployment is completed, test your Kubernetes connection by moving your file ./generated/kube_config.yaml in the following directory ~/.kube/config and run kubectl get pods -A to see your running pods.

$ mv ./generated/kube_config.yaml ~/.kube/config
$ kubectl get pods -A
ingress-nginx default-http-backend-97bf46cd4-wvdh6 1/1 Running 0 159m
ingress-nginx nginx-ingress-controller-67sq5 1/1 Running 0 159m
ingress-nginx nginx-ingress-controller-pj5g5 1/1 Running 0 159m
kube-system canal-jf6hf 2/2 Running 0 159m

With access to Kubernetes using kubectl, you can now manage Kubernetes resources from your workstation and deploy an application stack.

Updates, Management and OS Compatibility

If you plan on doing any updates or adding a node, do not use the RKE cli, apply the changes using Terraform and re-run the deployment.

Changes to the quantity of nodes for the master/worker nodes can be changed in the file, As for OS compatibility, this tutorial use Ubuntu 18.04 template. However if you wish to use different Distro, them you can change the value template in nodes/

  1. Update
  2. make plan
  3. make apply

And that's how you deploy a simple Kubernetes cluster from Rancher RKE using a plugin for Terraform!