Setting up Kubernetes cluster on Azure using Kubeadm, Terraform & Ansible- Part 1

Kubernetes (K8s), the hotshot of the decade, and de-facto choice for container orchestration have gained mammoth popularity since its initial release in 2015. It has now become the mandatory arrow in the quiver for any software engineers irrespective of domain & technology stack. And the best way to learn K8s is to actually deploy it by yourself from scratch, especially if you are preparing to appear for CKA certification and not using managed K8s cluster on various cloud platforms. We often are required to spin up and destroy K8s multiple times during our initial learnings. To avoid unnecessary efforts on setting up the cluster manually each time, it’s best to automate it. Hence I decided to write a blog post consisting of two-part series, to help everyone set up a single master node cluster with two worker nodes in Azure cloud platform using Terraform for setting up virtual machines and we will look into configuring these VMs to run K8s using Ansible in part-2 of this series. Now let’s get started with Terraform.

Getting started with Terraform: Infrastructure as Code

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.


  1. Users must have an Azure subscription and sufficient privileges to create required resources. To create a new Azure account, follow the below link

2. Download & Install of Terraform CLI

Network topology:

Network topology

As part of the cluster setup, We will be created the following Azure resources:

  1. Resource Group
  2. Virtual Network
  3. Subnet
  4. Network Security Group
  5. Virtual Machines: bastion, master (1) & worker nodes (2)

Setting up base infrastructure:

The terraform code to set up the base infrastructure is available in the following repository

Next Steps:

In the next part of the series, as shared below, we shall look at ansible scripts to configure these virtual machines to spin up basic single master K8s cluster using kubeadm.


Written by

Full stack developer | devops | IoT

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store