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

The following README will guide you on how to use kind 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

  • Kind leverages Docker to run the Kubernetes nodes. You will need to install Docker locally:

  • Install the Go programming language.

  • 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 kind

    On Linux:

    curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64
    chmod +x ./kind
    sudo mv ./kind /usr/local/bin/kind
    

    On MacOS:

    brew install kind
    

    On Windows:

    choco install kind
    
    • Navigate to the folder that has the kind cluster definition.
    cd azure_arc/azure_arc_k8s_jumpstart/kind
    
    • Create the kind cluster. We are using a configuration file called kind_cluster.yaml to specify our cluster configuration. This will create a 3 node cluster, with 1 master node and 2 worker nodes.
    kind create cluster --config kind_cluster.yaml --name arc-cluster
    

    kind create cluster

    Note: By default, kind will store the kubeconfig file used to connect to your cluster in the ~/.kube directory. If you want to use a custom directory to store the kubeconfig file, use the --kube-config flag.

    If you did chose a specific location for the cluster’s kubeconfig file make sure you are exporting its location as an environment variable using the export KUBECONFIG=kubeconfig location or in Windows, add this location to your PATH.

  • Verify your cluster was created successfully and you can access the cluster using kubectl.

    kubectl get nodes
    

    kubectl get nodes

Connecting to Azure Arc

  • Now that you have a running kind cluster, lets connect the kind cluster to Azure Arc.

    az login --service-principal -u mySpnClientId -p mySpnClientSecret --tenant myTenantID
    
  • Create a resource group

    az group create --name Arc-kind-Demo -l EastUS -o table
    

    Note: Before deploying, make sure to check the Azure Arc enabled Kubernetes region availability page.

    Create Azure resource group

  • Deploy the Arc binaries using Azure CLI:

    az connectedk8s connect -n Arc-kind-Demo -g Arc-kind-Demo --tags 'Project=jumpstart_azure_arc_k8s'
    
  • Upon completion, you will have your kind 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

    New Azure Arc enabled Kubernetes cluster

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-kind-Demo
    

    Delete the Azure Arc enabled Kubernetes cluster

    Delete Azure resource group

  • To delete the kind cluster locally, use the following command:

    kind delete cluster --name arc-cluster
    

    kind delete cluster