Exercise - Create an AKS cluster
In this exercise, you will:
- Create a new registry in Azure Container Registry using the Azure portal.
- Build an express.js Docker image and upload it to your container registry.
- Create a Kubernetes cluster using AKS and connect it to your container registry.
- Build a Next.js Docker image and upload it to your container registry.
Important
You need your own Azure subscription to complete this exercise, and you might incur charges. If you don't already have an Azure subscription, create a free account before you begin.
Create a registry in Azure Container Registry
Sign in to the Azure portal with your Azure subscription.
Select Create a resource > Containers > Container Registry.
Specify the values in the following table for each of the properties:
Property Value Subscription Select your default Azure subscription in which you're allowed to create and manage resources. Resource group Create a new resource group with the name learn-cna-rg. If you choose a different resource group name, remember it for the rest of the exercises in this module. Registry name Enter a unique name and make a note of it for later. Location Leave as default, or select a location close to you. Pricing plan Standard Select Review + create > Create.
The container registry takes a few minutes to create.
Build a Docker image and upload it to Azure Container Registry
Navigate to Azure Cloud Shell. If you're prompted to choose a shell, select Bash.
Create environment variables for your registry name and resource group using the following commands. Make sure you replace
{registry_name}
with your unique registry name.# Set the registry name REGISTRYNAME={registry_name} # Set the resource group name RESOURCEGROUP=learn-cna-rg
Download the source code for the Node.js app from GitHub using the
git clone
command.git clone https://github.com/MicrosoftDocs/mslearn-cloud-native-apps-express.git
Change directories to the source code folder using
cd
.cd mslearn-cloud-native-apps-express/src
Build and store the Docker image in your container registry using the
az acr build
command. Make sure to include the.
at the end of the command.az acr build --registry $REGISTRYNAME --image expressimage .
Return to the main directory of the source code using
cd ..
.cd ..
The Docker file contains the step-by-step instructions for building a Docker image from the source code for the Node.js application. Azure Container Registry runs these steps to build the image, and as each step completes, a message is generated. The build process should finish after a couple of minutes.
Create an AKS cluster
On the Azure portal Home page, select Create a resource.
Select Containers > Azure Kubernetes Service (AKS).
On the Basics tab, enter the following information:
Parameter Value Subscription Select the same subscription as you used to set up the container registry. Resource group Select the same resource group as you used to set up the container registry. Cluster preset configuration Select Dev/Test. Kubernetes cluster name Choose a unique name, such as cna-demo-aks. Region Leave as default, or select a region close to you. Select Next > Next > Next.
On the Integrations tab, select the container registry you created earlier.
Select Review + create > Create.
The cluster takes a few minutes to create.
Return to the Azure Cloud Shell, and create an environment variable for your cluster using the following command. Make sure you replace
{cluster-name}
with your Kubernetes cluster name.CLUSTERNAME={cluster-name}
Build the management app Docker image
In Azure Cloud Shell, change directories into the source code folder for the management app using
cd
.cd react/
Build and store the Docker image in your container registry using the
az acr build
command. Make sure to include the.
at the end of the command.az acr build --registry $REGISTRYNAME --image webimage .
Return to the main directory of the source code using
cd ..
.cd ..
Congratulations! You just created a container registry, built express.js and Next.js container images, and stored the images in the registry. You also created a Kubernetes cluster in AKS that's connected to your container registry.
Leave your Cloud Shell open. You'll use it again in the next exercise.