This guide will walk you through the process of creating a basic Azure Kubernetes Service (AKS) cluster using the Azure CLI. AKS simplifies deploying and managing containerized applications.
Open your terminal or command prompt and log in to your Azure account:
az login
This command will open a browser window for you to authenticate with your Azure credentials.
Azure resources are organized into logical containers called resource groups. Create a new resource group for your AKS cluster:
az group create --name myResourceGroup --location eastus
Replace myResourceGroup with a unique name for your resource group and eastus with your desired Azure region.
Now, create your AKS cluster. This command creates a cluster with a default configuration. You can customize many parameters for production environments.
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 1 --enable-addons monitoring --generate-ssh-keys
--resource-group myResourceGroup: Specifies the resource group created in the previous step.--name myAKSCluster: Sets the name for your AKS cluster.--node-count 1: Configures the cluster with a single node. For production, you'd typically use more.--enable-addons monitoring: Enables Azure Monitor for containers.--generate-ssh-keys: Generates SSH public and private key files for secure access to the nodes.This operation can take several minutes to complete.
To connect to your Kubernetes cluster, you need to configure kubectl, the Kubernetes command-line client. Use Azure CLI to retrieve the cluster's credentials:
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
This command downloads credentials and configures the kubectl command to use them.
Verify that the cluster is accessible by listing the nodes in your cluster:
kubectl get nodes
You should see output listing the single node that was created with your cluster.
You have successfully created an AKS cluster. Here are some suggested next steps: