- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
I am creating a series of blog posts around AKS as part of my own self-learning and research. My primary goal is to learn the basics of AKS and how to use it. The first post (found here) is about obtaining a general understanding of AKS and the terminology used.
The next step is about creating an AKS environment that can support my continued learning and future posts
. This brings us to this step: Creating an AKS Cluster. My objective here is to not only create an AKS cluster, but automate the process to be able to spin-up AKS clusters at my will. This will allow me to shut down and remove Azure resources as needed and saving costs while learning and blogging about AKS. This post will show how to automate the creation of an AKS cluster using anyone of the three different tools (pick you favorite)
- Azure CLI
- Terraform
- BICEP
Azure CLI
I execute the following Azure CLI script inside the Azure Portal:
# Set variables
RESOURCE_GROUP="myResourceGroup"
AKS_CLUSTER_NAME="myAKSCluster"
LOCATION="eastus"
NODE_COUNT=1
NODE_VM_SIZE="Standard_DS2_v2"# Create a resource group
az group create --name $RESOURCE_GROUP --location $LOCATION
# Create AKS cluster
az aks create \
--resource-group $RESOURCE_GROUP \
--name $AKS_CLUSTER_NAME \
--node-count $NODE_COUNT \
--node-vm-size $NODE_VM_SIZE \
--generate-ssh-keys
# Get AKS credentials
az aks get-credentials --resource-group $RESOURCE_GROUP --name $AKS_CLUSTER_NAME
Terraform
I store the following Terraform script in main.tf and execute the Terraform Init, Plan , and Apply to deploy the AKS service. I need to do future blog post on executing Terraform scripts. Terraform is my default IAC tool.
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "aks_rg" {
name = "myResourceGroup"
location = "eastus"
}
resource "azurerm_kubernetes_cluster" "aks_cluster" {
name = "myAKSCluster"
location = azurerm_resource_group.aks_rg.location
resource_group_name = azurerm_resource_group.aks_rg.name
dns_prefix = "myaks"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}
identity {
type = "SystemAssigned"
}
tags = {
environment = "development"
}
}
output "kube_config" {
value = azurerm_kubernetes_cluster.aks_cluster.kube_config_raw
sensitive = true
}
Bicep
I created the following main.bicep scrip
t;
resource aksCluster 'Microsoft.ContainerService/managedClusters@2023-01-01' = {
name: 'myAKSCluster'
location: resourceGroup().location
identity: {
type: 'SystemAssigned'
}
properties: {
dnsPrefix: 'myaks'
agentPoolProfiles: [
{
name: 'agentpool'
count: 1
vmSize: 'Standard_DS2_v2'
osType: 'Linux'
mode: 'System'
}
]
kubernetesVersion: '1.25.0' // Example version, update as necessary
enableRBAC: true
}
}
output aksName string = aksCluster.name# Create a resource groupaz group create --name myResourceGroup --location eastus# Deploy the Bicep templateaz deployment group create --resource-group myResourceGroup --template-file main.bicep
All 3 options will create a Kubernetes Service with cluster named "myAKSCluster" with a single node in the resource group called "myResourceGroup". After a few minutes I had an AKS cluster shown below:
Testing my installation
Use "kubectl get nodes" to test you installation...
This post is more technical in nature and is about setting up the environment to continue my learning going forward. I can quickly delete the created resource group and no recreate my AKS cluster as needed. Please feel free to contact me if you need more details on setting up your AKS cluster.
see also:
Azure Kubernetes Service (AKS) with .NET : Getting Started
- Get link
- X
- Other Apps