Home - About me - Browse by categories

How to: Use Terraform to deploy Azure Kubernetes Service in Custom VNET with Kubenet

05/21/2019 UPDATE: the route table and NSG assignation are now directly managed by the Azure Kubernetes Service provider, you don’t need to run extra script anymore! This blog post has been updated according to this.

Few months ago, I have written this post that explains how to deploy an Azure Kubernetes Service cluster inside a custom virtual network with the Kubenet plugin, instead of AzureCNI.

Note: The AKS docs has also been updated with this scenario, here.

In this new post, I describe all what you need to know/do to get the same result, but fully automated using Terraform :-)

There is a GitHub repository with everything here.

This repository contains all you need to use Terraform to deploy Azure Kubernetes Service with Kubenet plugin, inside a custom VNET.

It automatically creates:

How it works

All the AKS cluster definition is in the tf/aks.tf file. Some of the parameters are variable that can be overriden in the tf/variables.tf file.

How to deploy

You need to have Terraform installed and Azure CLI 2.0 installed, obviously.

Go to the tf directory:

cd tf

Optional: update the variables.tf and aks.tf files with desired values.

Export the following environment variables for the service principal client id and client secret that should be used by the Azure Kubernetes Service cluster:

export TF_VAR_client_secret=YOUR_CLIENT_SECRET
export TF_VAR_client_id=YOUR_CLIENT_ID

Initialize Terraform

terraform init

Plan the deployment:

terraform plan -out out.plan

Apply the plan to start the deployment:

terraform apply "out.plan"

Wait for the deployment to be completed.

How to destroy

Go to the tf directory:

cd tf

Call Terraform destroy:

terraform destroy

Hope this helps!

Any question about this post? Feel free to drop a comment below or contact me on Twitter @jcorioland