Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Create an AKS service and Container Registry

As a first step you will need to create your Azure Kubernetes Service together with an Azure Container Registry. Make sure you pre-create as well a virtual network for your AKS service. This will make it easier in the following labs to add additional networking features.You can use the following guidance:

Step by step guidance

  1. On your lab computer, open the Git Bash window and, from the Git Bash prompt, run the following command to sign in to your Azure subscription:

    az login
    

    In case you are running this lab in a GitHub codespace, use az login --use-device-code.

  2. Executing the command will automatically open a web browser window prompting you to authenticate. Once prompted, sign in using the user account that has the Owner role in the target Azure subscription that you will use in this lab and close the web browser window.

  3. Make sure that you are logged in to the right subscription for the consecutive commands.

    az account list -o table
    
  4. If in the above statement you don’t see the right account being indicated as your default one, change your environment to the right subscription with the following command, replacing the <subscription-id>.

    az account set --subscription <subscription-id>
    
  5. Run the following commands to create a resource group that will contain all of your resources (replace the <azure-region> placeholder with the name of any Azure region in which you can create an AKS cluster and an Azure Database for MySQL Flexible Server instance, see this page for regional availability details of those services:

    UNIQUEID=$(openssl rand -hex 3)
    APPNAME=petclinic
    RESOURCE_GROUP=rg-$APPNAME-$UNIQUEID
    LOCATION=<azure-region>
    az group create -g $RESOURCE_GROUP -l $LOCATION
    

    This lab uses quite some environment variables. In case you are using a codespace for running this lab, your environment variables will be lost if the codespace restarts. You can find a couple of methods for persisting these environment variables across codespace restarts in the LabTips.

  6. Create a new Azure Container Registry (ACR) instance.

    MYACR=acr$APPNAME$UNIQUEID
    az acr create \
        -n $MYACR \
        -g $RESOURCE_GROUP \
        --sku Basic
    
  7. Create a virtual network and subnet for your AKS cluster.

    VIRTUAL_NETWORK_NAME=vnet-$APPNAME-$UNIQUEID
    az network vnet create \
        --resource-group $RESOURCE_GROUP \
        --name $VIRTUAL_NETWORK_NAME \
        --location $LOCATION \
        --address-prefix 10.1.0.0/16
       
    AKS_SUBNET_CIDR=10.1.0.0/24
    az network vnet subnet create \
        --resource-group $RESOURCE_GROUP \
        --vnet-name $VIRTUAL_NETWORK_NAME \
        --address-prefixes $AKS_SUBNET_CIDR \
        --name aks-subnet 
    
  8. You will need to ID of the subnet when you create the AKS cluster.

    SUBNET_ID=$(az network vnet subnet show --resource-group $RESOURCE_GROUP --vnet-name $VIRTUAL_NETWORK_NAME --name aks-subnet --query id -o tsv)
    
  9. Create your AKS instance and link it to the container registry and subnet you just created.

    AKSCLUSTER=aks-$APPNAME-$UNIQUEID
    az aks create \
        -n $AKSCLUSTER \
        -g $RESOURCE_GROUP \
        --location $LOCATION \
        --generate-ssh-keys \
        --attach-acr $MYACR \
        --vnet-subnet-id $SUBNET_ID
    

    Wait for the provisioning to complete. This might take about 5 minutes.

  10. In your browser navigate to the Azure portal.

  11. Navigate to resource groups and select the resource group you just created.

  12. In the resource group overview you will see your newly created AKS and ACR instances.

    In case you don’t see the AKS and ACR services in the overview list of the resource group, hit the refresh button a couple of times, until they show up.

    You may also notice an additional resource group in your subscription, which name will start with MC. This resource group got created by the AKS creation process. It holds the resources of your AKS cluster. For learning purposes it might be good to check this resource group from time to time and to see what got created there.