Deploy a local Kubernetes Cluster using MicroK8s and connect it to Azure Arc

The following README will guide you on how to use MicroK8s to run a Kubernetes cluster locally and connect it as an Azure Arc enabled Kubernetes cluster resource.

Prerequisites

  • Clone the Azure Arc Jumpstart repository

    git clone https://github.com/microsoft/azure_arc.git
    
  • Install or update Azure CLI to version 2.15.0 and above. Use the below command to check your current installed version.

    az --version
    
  • Install and Set Up kubectl

  • Install Helm 3

  • Create Azure service principal (SP)

    To be able to complete the scenario and its related automation, Azure service principal assigned with the “Contributor” role is required. To create it, login to your Azure account run the below command (this can also be done in Azure Cloud Shell).

    az login
    az ad sp create-for-rbac -n "<Unique SP Name>" --role contributor
    

    For example:

    az ad sp create-for-rbac -n "http://AzureArcK8s" --role contributor
    

    Output should look like this:

    {
    "appId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "displayName": "AzureArcK8s",
    "name": "http://AzureArcK8s",
    "password": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "tenant": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    }
    

    Note: The Jumpstart scenarios are designed with as much ease of use in-mind and adhering to security-related best practices whenever possible. It is optional but highly recommended to scope the service principal to a specific Azure subscription and resource group as well considering using a less privileged service principal account

  • Enable subscription with the two resource providers for Azure Arc enabled Kubernetes. Registration is an asynchronous process, and registration may take approximately 10 minutes.

    az provider register --namespace Microsoft.Kubernetes
    az provider register --namespace Microsoft.KubernetesConfiguration
    

    You can monitor the registration process with the following commands:

    az provider show -n Microsoft.Kubernetes -o table
    az provider show -n Microsoft.KubernetesConfiguration -o table
    
  • Install the Azure Arc for Kubernetes CLI extensions connectedk8s and k8s-configuration:

    az extension add --name connectedk8s
    az extension add --name k8s-configuration
    

    Note: If you already used this guide before and/or have the extensions installed, use the bellow commands:

    az extension update --name connectedk8s
    az extension update --name k8s-configuration
    

Deployment

  • Install MicroK8s following the specific install guide for your operating system. For convenience, we’ve added some commands below:

    Windows:

    Download the MicroK8s installer for Windows and follow the instructions.

     MicroK8s installer for Windows

    Once installed, enable MicroK8s with:

    microk8s status --wait-ready
    microk8s enable dns
    

    Linux:

    sudo snap install microk8s --classic
    microk8s status --wait-ready
    microk8s enable dns
    

    MacOS:

    brew install ubuntu/microk8s/microk8s
    microk8s install
    microk8s status --wait-ready
    microk8s enable dns
    

    brew install microk8s

    WSL2:

    This blog post walks through an installation of MicroK8s in WSL 2.

  • Export MicroK8s cluster kubeconfig file path

    MicroK8s will not update your .kube/config file, and accessing the cluster is done using the microk8s cli, eg: microk8s kubectl get nodes. To be able to use this config with the Azure Arc CLI, we need to export it into a file.

    Windows:

    microk8s config view > %HOMEPATH%\.kube\microk8s
    

    Linux and MacOS:

    microk8s config view > ~/.kube/microk8s
    

Connect the cluster to Azure Arc

  • Authenticate Azure CLI

    We’ll start by authenticating our CLI with Azure, replacing the values below with the output from the command we issued to create service principal earlier (az ad sp create-for-rbac) in the prerequisite section of this guide.

    az login --service-principal -u appId -p password --tenant tenant
    

    Authenticate Azure CLI

  • Create a resource group

    az group create -n Arc-MicroK8s-Demo -l EastUS
    

    Create new Azure resource group

    Create new Azure resource group

  • Connect the cluster to Azure Arc

    Windows:

    az connectedk8s connect --name Arc-MicroK8s-Demo --resource-group Arc-MicroK8s-Demo --kube-config %HOMEPATH%\.kube\microk8s --kube-context microk8s --tags 'Project=jumpstart_azure_arc_k8s'
    

    Linux and MacOS:

    az connectedk8s connect --name Arc-MicroK8s-Demo --resource-group Arc-MicroK8s-Demo  --kube-config ~/.kube/microk8s --kube-context microk8s --tags 'Project=jumpstart_azure_arc_k8s'
    

    New Azure Arc enabled Kubernetes cluster

  • Upon completion, you will have your MicroK8s cluster connected as a new Azure Arc Kubernetes cluster resource in a new resource group.

    New Azure Arc enabled Kubernetes cluster

    New Azure Arc enabled Kubernetes cluster

Optional - Day 2 Operations

Now that your Kubernetes cluster is connected to Azure Arc, you might want to explore the following Day 2 scenarios:

Delete the deployment

  • In Azure, the most straightforward way is to delete the cluster or the resource group via the Azure Portal or through the CLI.

    az group delete --name Arc-MicroK8s-Demo
    

    Delete Azure resource group

  • To stop the MicroK8s cluster locally, use the following command:

    microk8s stop
    
  • The uninstall process of MicroK8s depends on your operating system.

    Windows

    Stop the MicroK8s VM in Multipass:

    multipass stop microk8s-vm
    

    Launch Add or Remove Programs and uninstall MicroK8s.

    Uninstall MicroK8s from Windows

    multipass delete microk8s-vm
    multipass purge
    

    If you want to completely uninstall Multipass, launch Add or Remove Programs and uninstall Multipass.

    Uninstall Multipass from Windows

    Linux:

    sudo snap remove microk8s
    

    MacOS:

    brew uninstall ubuntu/microk8s/microk8s