> For the complete documentation index, see [llms.txt](https://fusionauth.io/docs/llms.txt)

# Microsoft Azure Kubernetes Service (AKS)

Learn how to provision an AKS cluster in Microsoft Azure.

# Microsoft Azure Kubernetes Service (AKS)

This guide will show you how to quickly setup an AKS cluster on Microsoft Azure. When completed, you will have a fully functional Kubernetes cluster ready to deploy FusionAuth as well as a supporting Azure Database for PostgresSQL. The following method uses the default settings when provisioning an AKS cluster with the required resources and services. It is recommended that you consult the [Azure Kubernetes Service docs](https://docs.microsoft.com/en-us/azure/aks/) for details on how to customize the configuration for your use case.

## Requirements

*   A [Microsoft Azure account](https://portal.azure.com/) and active subscription with sufficient permissions to create resources.
*   `az` - Azure command Line tool used to manage resources on Azure. For installation instructions, see [How to install the Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli).

*   `kubectl` - Command line tool that interacts with the Kubernetes API server and is useful for managing Kubernetes clusters. Before proceeding, follow the installation documentation that corresponds to your platform found [here](https://kubernetes.io/docs/tasks/tools/). This guide will be using version `1.22`

## Architecture

The resulting architecture for this guide centers around creating an AKS cluster. By default, AKS creates a virtual network hosted in the Azure cloud; the worker nodes will connect to this network. You will create a PostgreSQL database and Elasticsearch cluster that will reside within the same virtual network.

The following reference architecture shows an example application deployed in AKS.

![EKS Architecture](https://fusionauth.io/img/docs/get-started/download-and-install/kubernetes/aks.png)

## Create an AKS cluster

### Create a Resource Group

Before you create the cluster, you need to first create a [Resource Group](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/), a logical grouping of Azure resources. A resource group location is where resources will run by default when a region is not provided on creation.

Create a new resource group

```shell
az group create --name fusionauthResourceGroup --location westus
```

JSON output of the resource group creation command

```json
{
  "id": "/subscriptions/2683a458-c361-4b5e-87d9-a4e5237d5b91/resourceGroups/fusionauthResourceGroup",
  "location": "westus",
  "managedBy": null,
  "name": "fusionauthResourceGroup",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}
```

### Create the cluster

Create a new AKS cluster

```shell
az aks create \
  --resource-group fusionauthResourceGroup \
  --name fusionauthCluster \
  --node-count 1 \
  --enable-addons monitoring \
  --generate-ssh-keys
```

More on these arguments:

*   `resource-group` - The name of the resource group where the cluster will be created.
*   `name` - The name of the cluster.
*   `node-count` - The number of nodes in the replica set.
*   `enable-addons` - The Kubernetes addons to enable.
*   `generate-ssh-keys` - Generates SSH public and private key files in the ~/.ssh directory.

For more information on the [create](https://docs.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az_aks_create) command, see [az aks create](https://docs.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az_aks_create) documentation.

### Update Kubernetes Configuration

The following retrieves credentials for the newly created cluster and then configures your `~/.kube/config` file so that you can use `kubectl` to connect to this cluster.

Get access credentials and update Kubeconfig

```shell
az aks get-credentials \
  --resource-group fusionauthResourceGroup \
  --name fusionauthCluster
```

### Verify Cluster Information

Execute the [list](https://docs.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az_aks_list) command to see AKS clusters that have been configured.

Get list of AKS clusters

```shell
az aks list
```

You now have a fully functional provisioned AKS cluster. For good measure, view the nodes that have been created. Use `kubectl` to make requests to the Kubernetes API Server.

Get list of nodes running on the cluster

```shell
kubectl get nodes -o wide

NAME                                STATUS   ROLES   AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION     CONTAINER-RUNTIME
aks-nodepool1-13281124-vmss000000   Ready    agent   8m42s   v1.20.9   10.240.0.4    <none>        Ubuntu 18.04.6 LTS   5.4.0-1059-azure   containerd://1.4.9+azure
```

Great! You have a node in a `READY` status. This means that the node is healthy and ready to accept pods.

## Create a Database

For this setup, you will create a PostgreSQL database. Such a database is required for FusionAuth. Replace `fusionauth-db-<my-organization>` with the desired database name.

caution

Azure database names are globally unique and you may encounter the error, "Specified server name is already used". Consider appending your own unique identifier such as an organization name in this example.

Create a PostgreSQL flexible server

```shell
az postgres flexible-server create \
  --resource-group fusionauthResourceGroup \
  --name fusionauth-db-<my-organization> \
  --location westus \
  --admin-user postgres \
  --admin-password changeMeToSomethingSecure \
  --version 12 \
  --public-access 0.0.0.0
```

More on these arguments:

*   `resource-group` - The name of the resource group where the cluster will be created.
*   `name` - The name of the database.
*   `location` - The location.
*   `admin-user` - The database admin user.
*   `admin-password` - The database admin user password.
*   `version` - The version of PostgreSQL to install.
*   `public-access` - Allows public access in the firewall rules. The `0.0.0.0` parameter allows access to this database from any resource deployed in Azure.

For more information on the [create](https://docs.microsoft.com/en-us/cli/azure/postgres/flexible-server?view=azure-cli-latest#az_postgres_flexible_server_create) command, see [az postgres flexible-server create](https://docs.microsoft.com/en-us/cli/azure/postgres/flexible-server?view=azure-cli-latest#az_postgres_flexible_server_create) documentation.

Upon successful database creation, you will receive a JSON object that contains important information about your new database.

JSON output from a successful database creation

```json
{
  "connectionString": "postgresql://postgres:<your-password>@fusionauth-db-example.postgres.database.azure.com/postgres?sslmode=require",
  "databaseName": "flexibleserverdb",
  "firewallName": "AllowAllAzureServicesAndResourcesWithinAzureIps_2021-10-10_23-34-29",
  "host": "fusionauth-db-example.postgres.database.azure.com",
  "id": "/subscriptions/2683a458-c361-4b5e-87d9-a4e5237d5b91/resourceGroups/fusionauthResourceGroup/providers/Microsoft.DBforPostgreSQL/flexibleServers/fusionauth-db-example",
  "location": "West US",
  "password": "your-password",
  "resourceGroup": "fusionauthResourceGroup",
  "skuname": "Standard_D2s_v3",
  "username": "postgres",
  "version": "12"
}
```

Take note of the database username, password and hostname, as those will be needed to configure FusionAuth. If you need to retrieve this information later, you can use the following command to get a list:

List available flexible servers

```shell
az postgres flexible-server list
```

## Deploy Elasticsearch using Elastic Cloud

Azure offers its Elasticsearch Service through Elastic Cloud. This section will guide you through setting up your account and deploying an Elasticsearch cluster.

From the Azure Portal home screen, enter a search for "Elasticsearch" and click on the Elasticsearch (Elastic Cloud) service.

![Navigate to Elasticsearch service](https://fusionauth.io/img/docs/get-started/download-and-install/kubernetes/az-es-start.png)

Click on the Create Elasticsearch (Elastic Cloud) button.

![Create Elasticsearch](https://fusionauth.io/img/docs/get-started/download-and-install/kubernetes/az-es-create.png)

Create an Elastic Resource by selecting the resource group you created in the first section of this guide and a name for the resource. Click on Review + Create after providing the required fields.

![Create resource screen](https://fusionauth.io/img/docs/get-started/download-and-install/kubernetes/az-es-create-resource.png)

Review your selections and press the Create button when ready.

![Review and create screen](https://fusionauth.io/img/docs/get-started/download-and-install/kubernetes/az-es-review-create.png)

Your deployment will now be in-progress as indicated on the next screen. This may take a few minutes to complete.

![In-progress screen](https://fusionauth.io/img/docs/get-started/download-and-install/kubernetes/az-es-in-progress.png)

When the deployment is complete, click on Go to resource group and then click on the Elasticsearch resource that you just created.

![Resources screen](https://fusionauth.io/img/docs/get-started/download-and-install/kubernetes/az-es-resource-group.png)

Click on the Manage changes in Elastic Cloud link.

![Elasticsearch resource detail screen](https://fusionauth.io/img/docs/get-started/download-and-install/kubernetes/az-es-example.png)

You will be directed to your Elastic Cloud dashboard and will see your new deployment listed.

Click on the name of your deployment to manage it. On the next page, you have access to all of the necessary endpoint information you will need to connect to your deployment. Under pplications , click on the Copy endpoint link next to Elasticsearch to copy the URL to your clipboard. You will need to save this URL for use when [deploying FusionAuth](https://fusionauth.io/docs/get-started/download-and-install.md) to your AKS cluster. Next, click on the Security link seen on the left navigation panel.

![Example dashboard on Elastic Cloud](https://fusionauth.io/img/docs/get-started/download-and-install/kubernetes/az-es-copy-endpoint.png)

Click on the Reset Password button to set your administrative credentials for your cluster.

![Security screen](https://fusionauth.io/img/docs/get-started/download-and-install/kubernetes/az-es-security.png)

You now have your Elasticsearch cluster deployed and the required credentials to connect to it.

## Next Steps

You now are running all the necessary infrastructure to deploy a containerized application to AKS.

Next up, [Deploy FusionAuth in Kubernetes](https://fusionauth.io/docs/get-started/download-and-install/kubernetes/fusionauth-deployment.md).