Creating Kubernetes Cluster on Azure
In this tutorial, you will set up a Kubernetes cluster from scratch on Azure with the dependencies Nevis needs. For a general overview of the Nevis-on-Kubernetes deployment solution, see Kubernetes Deployment (Cloud).
For an easier installation process, check Azure deployment automation, where the cluster is set up automatically with nevisAdmin4 already running in a few minutes.
The tutorial creates the following resources in Azure:
- A Terraform storage account, which will hold our cluster configuration.
- A Kubernetes cluster.
- An Azure Database for PostgreSQL flexible server, on which we will create our databases containing the Nevis-related data.
- A container registry, which will hold our docker images.
- A virtual network, which the cluster will use.
- Two IP addresses, one to access the cluster, and one to the cluster itself.
See Restrictions in Kubernetes Setups, which includes limitations specific to Kubernetes.
Prerequisites
This documentation uses Terraform to manage the infrastructure on the cloud service provider. Terraform allows managing the infrastructure as code, which provides additional benefits such as version control.
A couple of things are required to get started with Nevis on Kubernetes:
- Have an Azure subscription and have enough permissions to create resource groups and resources. This includes
Application Administratorfor creating the service principal, andOwnerto assign the required Role to it. - The supported Kubernetes versions for this guide are listed in the Kubernetes versions support policy.
- A Linux environment with the following software pre-installed:
- terraform: Terraform command line tool.
- az: Azure command line interface.
This guide requires basic knowledge of Linux, Terraform and the Azure CLI. In case you are new to these topics, we recommend to use the Azure deployment automation instead.
Downloading Template Files
All files required to set up the Kubernetes cluster are provided in the terraform/aks-cluster-setup directory of the nevis-kubernetes-support repository.
First, clone the repository, or download the terraform/aks-cluster-setup directory.
| File | Description |
|---|---|
| bootstrap/terraform-storage.tf | Defines the storage account used to store the state of the Terraform managed infrastructure. |
| aks-cluster.tf | Defines the actual Kubernetes cluster. |
| container-registry.tf | Defines a Docker container registry accessible in the cluster. |
| azure.tf | Points the Terraform state at the storage account. |
| providers.tf | Declares the required Terraform providers. |
| db.tf | Defines the Azure Database for PostgreSQL flexible server. |
| db_config.tf | Configures the Azure PostgreSQL server. |
| variables.tf | Contains the variables used in the template files. |
| terraform.tfvars | Contains the variable values. |
| validate-tfvars.sh | Validates terraform.tfvars against the naming rules Azure enforces, without requiring terraform init. |
Setting Terraform Variables
Most values in the provided terraform.tfvars file already have working defaults. The following ones are left empty and must be filled in, since Terraform cannot pick a sensible default for them — either they need to be globally unique across Azure, or they identify your specific subscription:
| Variable | Why it's required |
|---|---|
subscription | Your Azure subscription ID. Determines which subscription every resource is created in. Find it with az account show --query id. |
resource_group_name | Name of the main resource group Terraform creates, holding almost every resource (storage account, AKS cluster, container registry, PostgreSQL server, virtual network, public IP). Must be unique within your subscription. |
node_resource_group_name | AKS always places the node pool's VMs, disks, and networking in a second, separate resource group. This names it explicitly; otherwise Azure assigns an auto-generated name such as MC_<resource_group_name>_<cluster_name>_<location>. Must be unique within your subscription, and different from resource_group_name. |
storage_account_name | Name of the storage account created to hold the Terraform remote state (not a Nevis resource). Azure Storage Account names must be globally unique across all of Azure, 3-24 characters, lowercase letters and numbers only. |
cluster_name | Name of the AKS cluster resource, also used to derive the virtual network and subnet names. Must be unique within your subscription. Recommended to match the resource group name. |
registry_name | Name of the Azure Container Registry Terraform creates for you (not a reference to an existing one). The Nevis Docker images are pushed to and pulled from this registry later, during the nevisAdmin4 installation. Must be globally unique across Azure, alphanumeric characters only. |
dns_prefix | Prefix for the AKS API server's public hostname (<dns_prefix>-<random-id>.hcp.<location>.azmk8s.io). This is only the Kubernetes API server's DNS name, not the URL where nevisAdmin4 or the Nevis applications will be reachable — that domain is configured separately, later, during the nevisAdmin4 installation. Must be unique within the Azure region. |
db_server | Name of the Azure Database for PostgreSQL flexible server created to host the Nevis databases (nevisIDM, nevisAdmin4, etc.). Must be globally unique across Azure, since it becomes part of the server's public DNS name (<db_server>.postgres.database.azure.com). |
db_root_user | Administrator login name for the PostgreSQL server above — the DB_ROOT_USER used later when preparing the database credential secret during the nevisAdmin4 installation. Cannot be a reserved name such as "root" or "azure_superuser". |
The template validates the format of these values (length, allowed characters, reserved names) when you run terraform plan. To check this upfront without running terraform init first, run the provided script instead:
./validate-tfvars.sh terraform.tfvars
Neither the script nor terraform plan can check whether a name that has to be globally unique across Azure is actually still available — that only happens once Terraform tries to create the resource. To catch a naming conflict before running terraform apply, check availability upfront:
az storage account check-name-availability --name <storage_account_name>
az acr check-name --name <registry_name>
For db_server, cluster_name, and dns_prefix, there is no dedicated availability-check command; if terraform apply fails because one of these is already taken, pick a different value and re-run it.
Creating the Kubernetes Cluster with Terraform
The next step is to create a Kubernetes cluster with Terraform. Bootstrap Terraform before you can create the cluster.
Bootstrapping Terraform
Terraform can be used to easily set up a Kubernetes cluster and a Docker registry on Azure. Perform the next steps/execute the following commands:
Set the following environment variables, use the same values that were used in the terraform.tfvars
export SUBSCRIPTION_ID=
export RESOURCE_GROUP_NAME=
export STORAGE_ACCOUNT_NAME=
export CLUSTER_NAME=
export DB_SERVER=
Set azure connection
az login
az account set --subscription $SUBSCRIPTION_ID
az configure --defaults group=$RESOURCE_GROUP_NAME