Skip to content

Instantly share code, notes, and snippets.

@robece
Last active March 3, 2021 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robece/7ae9ccc299c4fac16f3e428d03e7b42d to your computer and use it in GitHub Desktop.
Save robece/7ae9ccc299c4fac16f3e428d03e7b42d to your computer and use it in GitHub Desktop.
AKS Powershell deployment script
# NOTE: before run this script ensure you are logged in Azure by using "az login" command.
$DeploymentAlias = Read-Host -Prompt "Introduce a lowercase unique alias for your deployment (max length suggested of 9 chars)"
$ResourceGroupName = "$($DeploymentAlias)-group"
$Location = "westus2"
$AKSClusterName = "$($DeploymentAlias)ks"
$AKSK8sVersion = "1.17.13"
$ContainerRegistryName = "$($DeploymentAlias)cr"
# PRINT
Write-Host "**********************************************************************"
Write-Host " CREATING: GENERAL RESOURCE GROUP"
Write-Host ""
Write-Host " Description:"
Write-Host ""
Write-Host " A container that holds related resources for an Azure solution."
Write-Host "**********************************************************************"
# create cluster resource group
az group create --name $ResourceGroupName --location $Location
# PRINT
Write-Host "**********************************************************************"
Write-Host " CREATING: CONTAINER REGISTRY"
Write-Host ""
Write-Host " Description:"
Write-Host ""
Write-Host " A registry of Docker and Open Container Initiative (OCI) images, with"
Write-Host " support for all OCI artifacts."
Write-Host "**********************************************************************"
# create acr
az acr create -n $ContainerRegistryName -g $ResourceGroupName --sku basic --admin-enabled true
# get acr id
$ACR_ID = $(az acr show -n $ContainerRegistryName -g $ResourceGroupName --query id -o tsv)
# PRINT
Write-Host "**********************************************************************"
Write-Host " CREATING: KUBERNETES SERVICE"
Write-Host ""
Write-Host " Description:"
Write-Host ""
Write-Host " Highly available, secure, and fully managed Kubernetes service."
Write-Host "**********************************************************************"
# create cluster
az aks create --name $AKSClusterName `
--resource-group $ResourceGroupName `
--node-count 3 --kubernetes-version $AKSK8sVersion `
--attach-acr $ACR_ID `
--generate-ssh-keys `
--vm-set-type AvailabilitySet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment