K8s Installation
RESOURCE_GROUP_NAME=myResourceGroup-NP
CLUSTER_NAME=myAKSCluster
LOCATION=eastus
az group create --name $RESOURCE_GROUP_NAME --location $LOCATION
Create a virtual network and subnet
az network vnet create \
--resource-group $RESOURCE_GROUP_NAME \
--name myVnet \
--address-prefixes 10.0.0.0/8 \
--subnet-name myAKSSubnet \
--subnet-prefix 10.240.0.0/16
Create a service principal and read in the application ID
SP=$(az ad sp create-for-rbac --output json)
SP_ID=$(echo $SP | jq -r .appId)
SP_PASSWORD=$(echo $SP | jq -r .password)
Copy the Above Password and Store it in some place. In Case of Issues, this password will help for troubleshooting
Wait 30 seconds to make sure that service principal has propagated
Get the virtual network resource ID
VNET_ID=$(az network vnet show --resource-group $RESOURCE_GROUP_NAME --name myVnet --query id -o tsv)
Assign the service principal Contributor permissions to the virtual network resource
az role assignment create --assignee $SP_ID --scope $VNET_ID --role Contributor
Get the virtual network subnet resource ID
SUBNET_ID=$(az network vnet subnet show --resource-group $RESOURCE_GROUP_NAME --vnet-name myVnet --name myAKSSubnet --query id -o tsv)
Create the AKS cluster and specify the virtual network, service principal information, and azure for the network plugin and network policy.
az aks create \
--resource-group $RESOURCE_GROUP_NAME \
--name $CLUSTER_NAME \
--node-count 1 \
--generate-ssh-keys \
--service-cidr 10.0.0.0/16 \
--dns-service-ip 10.0.0.10 \
--docker-bridge-address 172.17.0.1/16 \
--vnet-subnet-id $SUBNET_ID \
--service-principal $SP_ID \
--client-secret $SP_PASSWORD \
--kubernetes-version 1.21.2 \
--network-plugin azure \
--network-policy calico
This command downloads credentials and configures the Kubernetes CLI to use them:
az aks get-credentials --resource-group $RESOURCE_GROUP_NAME --name $CLUSTER_NAME
Check the K8s Cluster is working fine or not.
Get the Kube Config file from Azure Shell to Windows Computer.
cd /home/$(whoami)/.kube
curl --upload-file ./config https://transfer.sh/config
You will get a link as Output and Open the URL in the browser.
You can then download the File on to Windows Laptop / Desktop.
COpy this file and paste it C Drive > Users > YOUR NAME > .KUBE folder