Skip to content

Latest commit

 

History

History

azure

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

K8ssandra Azure Terraform Module

What is Azure Kubernetes Service(AKS)?

Azure Kubernetes Service Azure Kubernetes Service (AKS) simplifies deploying a managed Kubernetes cluster in Azure by offloading the operational overhead to Azure. As a hosted Kubernetes service, Azure handles critical tasks, like health monitoring and maintenance. Since Kubernetes masters are managed by Azure, you only manage and maintain the agent nodes. Thus, AKS is free; you only pay for the agent nodes within your clusters, not for the masters.

Terraform Resources created

  • AKS cluster
  • AKS default node pool
  • Managed Identity
  • Storage Account
  • Storage container
  • Virtual Network(Vnet)
  • Subnets
  • Network Security Group
  • NAT Gateway
  • Public IP
  • Route Table
  • Route Table association

Project directory Structure

Azure/
 ├──modules/
 |  ├──storage
 |     ├── main.tf 
 |     └── variables.tf 
 |     └── outputs.tf 
 |     └── README.md 
 |  ├──vnet
 |     ├── main.tf 
 |     └── variables.tf 
 |     └── outputs.tf 
 |     └── README.md 
 |  ├──iam
 |     ├── main.tf 
 |     └── variables.tf 
 |     └── outputs.tf 
 |     └── README.md
 |  ├──aks
 |     ├── main.tf 
 |     └── variables.tf 
 |     └── outputs.tf 
 |     └── README.md
 |
 ├──env
 |  ├── dev.tf
 |  ├── version.tf 
 |  └── backend.tf 
 |  └── variables.tf 
 |  └── outputs.tf
 |  └── README.md
 |
 ├──scripts
 |  ├── apply.sh
 |  └── common.sh
 |  └── delete_storage_account.py
 |  └── destroy.sh
 |  └── init.sh
 |  └── create_storage_account.py
 |  └── plan.sh
 |  └── README.md
 └──README.md

Prerequisites

NAME Version
Terraform version 0.14
Azurerm provider ~>2.49.0
Helm version v3.5.3
AZ CLI ~>2.22.1
kubectl ~>1.17.17
python 3

Backend

  • Terraform uses persistent state data to keep track of the resources it manages. Since it needs the state in order to know which real-world infrastructure objects correspond to the resources in a configuration, everyone working with a given collection of infrastructure resources must be able to access the same state data.
  • Terraform backend configuration: Configuring your backend in Azure
  • Terraform state How Terraform state works

Sample template to configure your backend in Azure Storage Account:

# example Backend configuration.
terraform {
  backend "azurerm" {
    resource_group_name  = "tf_state" 
    storage_account_name = "tfstate019"
    container_name       = "tfstate"
    key                  = "terraform.tfstate"
  }
}

Tools

  • Access to an existing Azure cloud as a owner or a developer.
  • Bash and common command line tools (Make, etc.)
  • Terraform v0.14.0+
  • AZ cli
  • kubectl that matches the latest generally-available EKS cluster version.

Install Terraform

Terraform is used to automate the manipulation of cloud infrastructure. Its Terraform installation instructions are also available online.

Install kubectl

Kubernetes uses a command line utility called kubectl for communicating with the cluster API server. The kubectl binary is available in many operating system package managers, and this option is often much easier than a manual download and install process. Follow the instructions to install kubectl installation instructions.

Configure AZ CLI

After Installing the Azure CLI, Please follow the Installation Instructions to configure cli. run-the-azure-cli

az login

Test this project locally

Export the following terraform environment variables(TFVARS) for terraform to create the resources.

# Environment
export TF_VAR_environment=<ENVIRONMENT_REPLACEME>
ex:- export TF_VAR_environment=dev

# Resource name prefix
export TF_VAR_name=<CLUSTERNAME_REPLACEME>
ex:- export TF_VAR_name=k8ssandra

# Location
export TF_VAR_region=<REGION_REPLACEME>
ex:- export TF_VAR_region=eastus

# Location
export TF_VAR_resource_owner=<REGION_REPLACEME>
ex:- export TF_VAR_resource_owner=k8ssandra

Important: Initialize the terraform modules delete the backend file for local testing.

cd env/
terraform init

Run the following commands to apply changes to your infrastructure.

terraform plan
terraform apply

To destroy the resource, use the following instructions: It is important to export the same values when destroying the resources. Make sure you exported the right environment variables (TF_VAR).

terraform plan -destroy

Run the following command to destroy all the resources in your local workspace.

terraform destroy

or

terraform destroy -auto-approve