Creating an Azure Kubernetes Service (AKS) Cluster
This guide walks you through the process of creating a new Azure Kubernetes Service (AKS) cluster using the Azure portal, Azure CLI, and Azure PowerShell.
Prerequisites
- An Azure subscription. If you don't have one, you can create a free account.
- Azure CLI installed and configured (for CLI method).
- Azure PowerShell installed and configured (for PowerShell method).
Method 1: Using the Azure Portal
The Azure portal provides a user-friendly graphical interface for cluster creation.
- Sign in to the Azure portal.
- In the search bar, type "Kubernetes services" and select it from the services list.
- Click + Create then Create a Kubernetes cluster.
- Basics tab:
- Select your Azure subscription and a resource group. Create a new one if needed.
- Enter a name for your AKS cluster.
- Choose a region for your cluster.
- Select the Kubernetes version.
- Specify the node count for your initial node pool.
- Choose the VM size for your nodes.
- Node pools tab: Configure your system and user node pools, including VM sizes, auto-scaling, and availability zones.
- Networking tab: Configure networking settings like Kubernetes service address range and network policy.
- Integrations tab: Enable features like Azure Monitor, Container Registry, etc.
- Advanced tab: Configure advanced settings such as admission controllers, API server access, and pod security policy.
- Tags tab: Apply tags for organizing your Azure resources.
- Review your configuration and click Create.
Method 2: Using Azure CLI
The Azure Command-Line Interface (CLI) is a powerful tool for automating Azure resource management.
First, log in to your Azure account:
az login
Create a resource group (if you don't have one):
az group create --name MyResourceGroup --location eastus
Create the AKS cluster:
az aks create \
--resource-group MyResourceGroup \
--name myAKSCluster \
--node-count 3 \
--enable-addons monitoring \
--generate-ssh-keys \
--location eastus
This command creates a cluster named myAKSCluster
with 3 nodes in the MyResourceGroup
resource group in the East US region. The --enable-addons monitoring
flag enables Azure Monitor for containers.
Method 3: Using Azure PowerShell
Azure PowerShell provides another way to manage your Azure resources programmatically.
First, connect to your Azure account:
Connect-AzAccount
Create a resource group (if you don't have one):
New-AzResourceGroup -Name "MyResourceGroup" -Location "East US"
Create the AKS cluster:
New-AzAksCluster -ResourceGroupName "MyResourceGroup" -Name "myAKSCluster" -Location "East US" -NodeCount 3 -EnableMonitoring
Connecting to your Cluster
Once your cluster is created, you need to configure kubectl
to connect to it.
Get credentials for your cluster:
az aks get-credentials --resource-group MyResourceGroup --name myAKSCluster
Verify the connection:
kubectl get nodes