Deploy a local Kubernetes Cluster using kind and connect it to Azure Arc
The following Jumpstart scenario 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.25.0 and above. Use the below command to check your current installed version.
az --version
-
Kind leverages Docker to run the Kubernetes nodes. You will need to install Docker locally:
- If you are a Windows user, install Docker Desktop. You can also use the Chocolatey package to automate the installation.
- If you are a MacOS User, install Docker Desktop for Mac.
- If you are a Linux user, use your package manager to install the Docker engine.
-
Install the Go programming language.
-
Create Azure service principal (SP)
The Azure service principal assigned with the “Contributor” role is required to complete the scenario and its related automation. To create it, log in to your Azure account run the below command (you could also do this in Azure Cloud Shell).
az login subscriptionId=$(az account show --query id --output tsv) az ad sp create-for-rbac -n "<Unique SP Name>" --role "Contributor" --scopes /subscriptions/$subscriptionId
For example:
az login subscriptionId=$(az account show --query id --output tsv) az ad sp create-for-rbac -n "JumpstartArcK8s" --role "Contributor" --scopes /subscriptions/$subscriptionId
Output should look like this:
{ "appId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX", "displayName": "JumpstartArcK8s", "password": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX", "tenant": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX" }
NOTE: If you create multiple subsequent role assignments on the same service principal, your client secret (password) will be destroyed and recreated each time. Therefore, make sure you grab the correct password.
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 az provider register --namespace Microsoft.ExtendedLocation
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 az provider show -n Microsoft.ExtendedLocation -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 below 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
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 chose a specific location for the cluster’s kubeconfig file, make sure you export its location as an environment variable using the
export KUBECONFIG=/path/to/kubeconfig
location or in Windows, add this location to your PATH. -
Verify that kind has created the cluster successfully, and you can access the cluster using
kubectl
.kubectl get nodes
Connecting to Azure Arc
-
Now that you have a running kind cluster let’s 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.
-
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.
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
-
To delete the kind cluster locally, use the following command:
kind delete cluster --name arc-cluster