Quickstart: Deploy an Azure Kubernetes Service (AKS) cluster using Azure CLI
Azure Kubernetes Service (AKS) is a managed Kubernetes service that lets you quickly deploy and manage clusters. In this quickstart, you:
- Deploy an AKS cluster using the Azure CLI.
- Run a sample multi-container application with a web front end and a Redis instance in the cluster.
Before you begin
- This quickstart assumes a basic understanding of Kubernetes concepts. For more information, see Kubernetes core concepts for Azure Kubernetes Service (AKS).
- You need an Azure account with an active subscription. If you don't have one, create an account for free.
- To learn more about creating a Windows Server node pool, see Create an AKS cluster that supports Windows Server containers.
Prerequisites
Use the Bash environment in Azure Cloud Shell. For more information, see Quickstart for Bash in Azure Cloud Shell.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
This article requires Azure CLI version 2.0.64 or later. If you're using Azure Cloud Shell, the latest version is already installed.
Make sure the identity you use to create your cluster has the appropriate minimum permissions. For more details on access and identity for AKS, see Access and identity options for Azure Kubernetes Service (AKS).
If you have multiple Azure subscriptions, select the appropriate subscription ID in which the resources should be billed using the
az account
command.Verify you have the Microsoft.OperationsManagement and Microsoft.OperationalInsights providers registered on your subscription. These Azure resource providers are required to support Container insights. Check the registration status using the following commands:
az provider show -n Microsoft.OperationsManagement -o table az provider show -n Microsoft.OperationalInsights -o table
If they're not registered, register them using the following commands:
az provider register --namespace Microsoft.OperationsManagement az provider register --namespace Microsoft.OperationalInsights
Note
If you plan to run the commands locally instead of in Azure Cloud Shell, make sure you run the commands with administrative privileges.
Create a resource group
An Azure resource group is a logical group in which Azure resources are deployed and managed. When you create a resource group, you're prompted to specify a location. This location is the storage location of your resource group metadata and where your resources run in Azure if you don't specify another region during resource creation.
The following example creates a resource group named myResourceGroup in the eastus location.
Create a resource group using the
az group create
command.az group create --name myResourceGroup --location eastus
The following output example resembles successful creation of the resource group:
{ "id": "/subscriptions/<guid>/resourceGroups/myResourceGroup", "location": "eastus", "managedBy": null, "name": "myResourceGroup", "properties": { "provisioningState": "Succeeded" }, "tags": null }
Create an AKS cluster
The following example creates a cluster named myAKSCluster with one node and enables a system-assigned managed identity.
Create an AKS cluster using the
az aks create
command with the--enable-addons monitoring
and--enable-msi-auth-for-monitoring
parameters to enable Azure Monitor Container insights with managed identity authentication (preview).az aks create -g myResourceGroup -n myAKSCluster --enable-managed-identity --node-count 1 --enable-addons monitoring --enable-msi-auth-for-monitoring --generate-ssh-keys
After a few minutes, the command completes and returns JSON-formatted information about the cluster.
Note
When you create a new cluster, AKS automatically creates a second resource group to store the AKS resources. For more information, see Why are two resource groups created with AKS?
Connect to the cluster
To manage a Kubernetes cluster, use the Kubernetes command-line client, kubectl. kubectl
is already installed if you use Azure Cloud Shell.
Install
kubectl
locally using theaz aks install-cli
command.az aks install-cli
Configure
kubectl
to connect to your Kubernetes cluster using theaz aks get-credentials
command.This command executes the following operations:
- Downloads credentials and configures the Kubernetes CLI to use them.
- Uses
~/.kube/config
, the default location for the Kubernetes configuration file. Specify a different location for your Kubernetes configuration file using --file argument.
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
Verify the connection to your cluster using the
kubectl get
command. This command returns a list of the cluster nodes.kubectl get nodes
The following output example shows the single node created in the previous steps. Make sure the node status is Ready.
NAME STATUS ROLES AGE VERSION aks-nodepool1-31718369-0 Ready agent 6m44s v1.12.8
Deploy the application
A Kubernetes manifest file defines a cluster's desired state, such as which container images to run.
In this quickstart, you use a manifest to create all objects needed to run the Azure Vote application. This manifest includes two Kubernetes deployments:
- The sample Azure Vote Python applications.
- A Redis instance.
It also creates two Kubernetes Services:
- An internal service for the Redis instance.
- An external service to access the Azure Vote application from the internet.
Create a file named
azure-vote.yaml
and copy in the following manifest.apiVersion: apps/v1 kind: Deployment metadata: name: azure-vote-back spec: replicas: 1 selector: matchLabels: app: azure-vote-back template: metadata: labels: app: azure-vote-back spec: nodeSelector: "kubernetes.io/os": linux containers: - name: azure-vote-back image: mcr.microsoft.com/oss/bitnami/redis:6.0.8 env: - name: ALLOW_EMPTY_PASSWORD value: "yes" resources: requests: cpu: 100m memory: 128Mi limits: cpu: 250m memory: 256Mi ports: - containerPort: 6379 name: redis --- apiVersion: v1 kind: Service metadata: name: azure-vote-back spec: ports: - port: 6379 selector: app: azure-vote-back --- apiVersion: apps/v1 kind: Deployment metadata: name: azure-vote-front spec: replicas: 1 selector: matchLabels: app: azure-vote-front template: metadata: labels: app: azure-vote-front spec: nodeSelector: "kubernetes.io/os": linux containers: - name: azure-vote-front image: mcr.microsoft.com/azuredocs/azure-vote-front:v1 resources: requests: cpu: 100m memory: 128Mi limits: cpu: 250m memory: 256Mi ports: - containerPort: 80 env: - name: REDIS value: "azure-vote-back" --- apiVersion: v1 kind: Service metadata: name: azure-vote-front spec: type: LoadBalancer ports: - port: 80 selector: app: azure-vote-front
For a breakdown of YAML manifest files, see Deployments and YAML manifests.
Deploy the application using the
kubectl apply
command and specify the name of your YAML manifest.kubectl apply -f azure-vote.yaml
The following example resembles output showing successfully created deployments and services.
deployment "azure-vote-back" created service "azure-vote-back" created deployment "azure-vote-front" created service "azure-vote-front" created
Test the application
When the application runs, a Kubernetes service exposes the application front end to the internet. This process can take a few minutes to complete.
Monitor progress using the
kubectl get service
command with the--watch
argument.kubectl get service azure-vote-front --watch
The EXTERNAL-IP output for the
azure-vote-front
service will initially show as pending.NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE azure-vote-front LoadBalancer 10.0.37.27 <pending> 80:30572/TCP 6s
Once the EXTERNAL-IP address changes from pending to an actual public IP address, use
CTRL-C
to stop thekubectl
watch process.The following example output shows a valid public IP address assigned to the service:
azure-vote-front LoadBalancer 10.0.37.27 52.179.23.131 80:30572/TCP 2m
Open a web browser to the external IP address of your service to see the Azure Vote app in action.
Delete the cluster
If you don't plan on going through the following tutorials, clean up unnecessary resources to avoid Azure charges.
Remove the resource group, container service, and all related resources using the
az group delete
command.az group delete --name myResourceGroup --yes --no-wait
Note
The AKS cluster was created with a system-assigned managed identity, which is the default identity option used in this quickstart. The platform manages this identity so you don't need to manually remove it.
Next steps
In this quickstart, you deployed a Kubernetes cluster and deployed a simple multi-container application to it.
To learn more about AKS, and walk through a complete code-to-deployment example, continue to the Kubernetes cluster tutorial.
This quickstart is for introductory purposes. For guidance on creating full solutions with AKS for production, see AKS solution guidance.
Feedback
Submit and view feedback for