You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.4 KiB

  1. Param(
  2. [parameter(Mandatory=$true)][string]$resourceGroupName,
  3. [parameter(Mandatory=$true)][string]$location,
  4. [parameter(Mandatory=$true)][string]$serviceName,
  5. [parameter(Mandatory=$true)][string]$dnsNamePrefix,
  6. [parameter(Mandatory=$false)][string]$registryName,
  7. [parameter(Mandatory=$true)][bool]$createAcr=$true,
  8. [parameter(Mandatory=$false)][int]$nodeCount=3,
  9. [parameter(Mandatory=$false)][string]$nodeVMSize="Standard_D2_v2",
  10. [parameter(Mandatory=$false)][bool]$enableHttpApplicationAddon=$true,
  11. [parameter(Mandatory=$false)][bool]$enableAzureMonitoring=$false,
  12. [parameter(Mandatory=$false)][ValidateSet("VirtualMachineScaleSets","AvailabilitySet",IgnoreCase=$true)]$vmSetType="VirtualMachineScaleSets"
  13. )
  14. # Create resource group
  15. Write-Host "Creating Azure Resource Group..." -ForegroundColor Yellow
  16. az group create --name=$resourceGroupName --location=$location
  17. if ($createAcr -eq $true) {
  18. # Create Azure Container Registry
  19. if ([string]::IsNullOrEmpty($registryName)) {
  20. $registryName=$serviceName
  21. }
  22. Write-Host "Creating Azure Container Registry named $registryName" -ForegroundColor Yellow
  23. az acr create -n $registryName -g $resourceGroupName -l $location --admin-enabled true --sku Basic
  24. }
  25. # Create kubernetes cluster in AKS
  26. Write-Host "Creating AKS $resourceGroupName/$serviceName" -ForegroundColor Yellow
  27. az aks create --resource-group=$resourceGroupName --name=$serviceName --dns-name-prefix=$dnsNamePrefix --generate-ssh-keys --node-count=$nodeCount --node-vm-size=$nodeVMSize --vm-set-type $vmSetType
  28. if ($enableHttpApplicationAddon) {
  29. Write-Host "Enabling Http Applciation Routing in AKS $serviceName" -ForegroundColor Yellow
  30. az aks enable-addons --resource-group $resourceGroupName --name $serviceName --addons http_application_routing
  31. }
  32. if ($enableAzureMonitoring) {
  33. Write-Host "Enabling Azure Monitoring in AKS $serviceName" -ForegroundColor Yellow
  34. az aks enable-addons --resource-group $resourceGroupName --name $serviceName --addons monitoring
  35. }
  36. # Retrieve kubernetes cluster configuration and save it under ~/.kube/config
  37. Write-Host "Getting Kubernetes config..." -ForegroundColor Yellow
  38. az aks get-credentials --resource-group=$resourceGroupName --name=$serviceName
  39. if ($createAcr -eq $true) {
  40. # Show ACR credentials
  41. Write-Host "ACR $registryName credentials:" -ForegroundColor Yellow
  42. az acr credential show -n $registryName
  43. }