Creating An AKS Cluster Using Azure Cli
Creation of kubernetes cluster on Azure
Using Azure CLI
1. Install Azure CLI
You can check Installation of Azure CLI from here for your preferred workstation - https://learn.microsoft.com/en-us/cli/azure/install-azure-cli. Example for MacOS
2. Log In to Azure
You can use multiple methods to login through the Azure CLI
3. Get the necessary details for the next steps
-
Subscription details - Check if the current subscription you want is correct or not
-
Region - Check the region where you want to deploy your k8s cluster. Also make sure that GPU workloads are available in your region. You can check types of GPU instances and Availability of GPU instances in your specific region. To get a list of all regions
- Make sure to use the second column as the region name in the above output.
- Resource group - A new resource group is recommended. However an existing resource group can also be used.
- To create a new resource with some tags, execute the command in step 5.
4. Export all the necessary details into a variable
Set the subscription ID for all the below steps and add the aks-preview
extension.
5. Creating Resource group
All the Azure resources (mostly) are deployed in some resource group. For our AKS cluster we will create a resource group. We are naming it as tfy-datascience
but feel free to name it according to your preferred naming conventions. We are creating two tags team=datascience
and owner=truefoundry
6. Create user assigned identity
To authenticate to AKS cluster post-creation we need to create a user-assigned identity. Managed Identity is the way to authenticate to Azure resource (AKS here) using Azure AD. There are two kinds of managed identities and we will use user-assigned identities among them. Copy the unique ID of the user assigned identity from the below steps
7. Creating AKS Cluster
We can create AKS cluster in mostly two ways. You can chose any one of the following ways.
A. Creating AKS cluster without specifying network requirements
In this we can skip the network requirements during AKS creation as it is handled automatically by Azure. We are using tfy-aks-cluster
as the cluster name and node pool size will autoscale from 2 to 4 nodes. You need to pass the user assigned identity through the argument --assign-identity
Get the kubeconfig
file for the AKS cluster
B. Creating AKS cluster with specific network requirements
-
Exporting the address and the vnet name
-
You can export the below command
-
You can use this as an example for the default prefixes
-
-
Creating a virtual network
tfy-virtual-net
. Make sure to copy the unique ID of the Virtual network created. All the nodes will be part of this virtual network. -
Create an AKS cluster
tfy-aks-cluster-with-vnet
with the above network. We are using the user assigned identity we created above along with the unique ID of the virtual network. We are again setting the node pool size to autoscale from 2 to 4 nodes. -
Getting the
kubeconfig
file for the AKS cluster
az aks create commanad Error: unrecognized arguments: —enable-node-restriction, —enable-workload-identity
While creation of aks if you face this error it is because of
Attaching a user based spot node pool
It is advised to attach a user spot node pool in AKS to schedule your workloads that can handle interruptions. There are two kinds of node pools available in Azure system
and user
. System is used to assign AKS related applications and workloads. User
is only used to assign workloads. Moreover each of these node pools can also contains instances which are of type on-demand
or spot
.
The first node pool we created was of type on-demand and now we will create one of type spot.
Update autoscaling configurations
Run the below command to update the default cluster-autoscaler configurations
Attaching a user based GPU node pool (on-demand) [GPU]
As we deploy machine learning models we might want to deploy the GPU node pool so that we can bring the GPU instances. You can check types of GPU instances and Availability of GPU instances in your specific region.
In the below command we have assumed we will use NC6 for the node pools. Make sure to set the min, max and the required count according to the specific needs.
Read Understanding Azure Node Pools for more details on how to configure your node pools