Create Private AKS Cluster using Bicep

Published Jul 13 2021 10:22 AM 3,821 Views
Microsoft

Overview

This is a blog on how to use a modular approach for Infrastructure as Code (IaC) in provisioning a private AKS cluster and other related resources. The Bicep modules in the repository are designed keeping the AKS baseline architecture in mind. You can start using these modules as is or modify to suit your own needs.

Architecture

PrivateCluster.jpg

Setup

The Bicep modules will provision the following Azure Resources under subscription scope:

  1. A Resource Group with Baseline variables
  2. Hub VNet with required subnets
  3. Azure Firewall Subnet
  4. Azure Bastion Subnet
  5. A jumpbox subnet
  6. Spoke VNET with AKS cluster subnet and additional subnet for other services like Azure Container Registry etc.
  7. Azure Firewall and required routes
  8. Azure Bastion resource and a jumpbox VM without public IP for securing traffic
  9. Azure Container Registry for storing images.
  10. A Private Endpoint for ACR
  11. Private DNS Zone
  12. AAD Enabled, Managed Private AKS Cluster with monitoring Addon and Azure Policy enabled
  13. Private AK Cluster need the UDR routes enabled via Firewall.

Resource Provisioning

Clone the repo

git clone https://github.com/ssarwa/bicep
cd bicep
# You could use deploy.azcli as your working file. Don't run the script as is!

Login to Azure

az login

az account set -s <Subscription ID>

Initialize variables

# Change the variables as required (baseline and location) on deploy.azcli
# Deploy the bicep script
az deployment sub create -n $baseline'Dep' -l $location -f main.bicep

The deployment could take somewhere around 20 to 30 mins. Once provisioning is completed you can use the cluster for your needs.

Next Steps

  1. Enable GitOps using Flux operator for Application deployment
  2. Enable IaC using CI/CD pipelines on Github Actions
1 Comment
%3CLINGO-SUB%20id%3D%22lingo-sub-2499201%22%20slang%3D%22en-US%22%3ECreate%20Private%20AKS%20Cluster%20using%20Bicep%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2499201%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22overview%22%20id%3D%22toc-hId--434493488%22%20id%3D%22toc-hId--434493488%22%20id%3D%22toc-hId--434493488%22%20id%3D%22toc-hId--434493488%22%3EOverview%3C%2FH2%3E%0A%3CP%3EThis%20is%20a%20blog%20on%20how%20to%20use%20a%20modular%20approach%20for%20Infrastructure%20as%20Code%20(IaC)%20in%20provisioning%20a%20private%20AKS%20cluster%20and%20other%20related%20resources.%20The%20Bicep%20modules%20in%20the%20repository%20are%20designed%20keeping%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Farchitecture%2Freference-architectures%2Fcontainers%2Faks%2Fsecure-baseline-aks%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EAKS%20baseline%20architecture%3C%2FA%3E%20in%20mind.%20You%20can%20start%20using%20these%20modules%20as%20is%20or%20modify%20to%20suit%20your%20own%20needs.%3C%2FP%3E%0A%3CH2%20id%3D%22architecture%22%20id%3D%22toc-hId-2053019345%22%20id%3D%22toc-hId-2053019345%22%20id%3D%22toc-hId-2053019345%22%20id%3D%22toc-hId-2053019345%22%3EArchitecture%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId-245564882%22%20id%3D%22toc-hId-245564882%22%20id%3D%22toc-hId-245564882%22%20id%3D%22toc-hId-245564882%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22PrivateCluster.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F292439i9DFCCF57E151C10B%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22PrivateCluster.jpg%22%20alt%3D%22PrivateCluster.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CH2%20id%3D%22setup%22%20id%3D%22toc-hId--1561889581%22%20id%3D%22toc-hId--1561889581%22%20id%3D%22toc-hId--1561889581%22%20id%3D%22toc-hId--1561889581%22%3ESetup%3C%2FH2%3E%0A%3CP%3EThe%20Bicep%20modules%20will%20provision%20the%20following%20Azure%20Resources%20under%20subscription%20scope%3A%3C%2FP%3E%0A%3COL%20style%3D%22list-style-type%3A%20decimal%3B%22%3E%0A%3CLI%3EA%20Resource%20Group%20with%20Baseline%20variables%3C%2FLI%3E%0A%3CLI%3EHub%20VNet%20with%20required%20subnets%3C%2FLI%3E%0A%3CLI%3EAzure%20Firewall%20Subnet%3C%2FLI%3E%0A%3CLI%3EAzure%20Bastion%20Subnet%3C%2FLI%3E%0A%3CLI%3EA%20jumpbox%20subnet%3C%2FLI%3E%0A%3CLI%3ESpoke%20VNET%20with%20AKS%20cluster%20subnet%20and%20additional%20subnet%20for%20other%20services%20like%20Azure%20Container%20Registry%20etc.%3C%2FLI%3E%0A%3CLI%3EAzure%20Firewall%20and%20required%20routes%3C%2FLI%3E%0A%3CLI%3EAzure%20Bastion%20resource%20and%20a%20jumpbox%20VM%20without%20public%20IP%20for%20securing%20traffic%3C%2FLI%3E%0A%3CLI%3EAzure%20Container%20Registry%20for%20storing%20images.%3C%2FLI%3E%0A%3CLI%3EA%20Private%20Endpoint%20for%20ACR%3C%2FLI%3E%0A%3CLI%3EPrivate%20DNS%20Zone%3C%2FLI%3E%0A%3CLI%3EAAD%20Enabled%2C%20Managed%20Private%20AKS%20Cluster%20with%20monitoring%20Addon%20and%20Azure%20Policy%20enabled%3C%2FLI%3E%0A%3CLI%3EPrivate%20AK%20Cluster%20need%20the%20UDR%20routes%20enabled%20via%20Firewall.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22resource-provisioning%22%20id%3D%22toc-hId-925623252%22%20id%3D%22toc-hId-925623252%22%20id%3D%22toc-hId-925623252%22%20id%3D%22toc-hId-925623252%22%3EResource%20Provisioning%3C%2FH2%3E%0A%3CH4%20id%3D%22clone-the-repo%22%20id%3D%22toc-hId--180766633%22%20id%3D%22toc-hId--180766633%22%20id%3D%22toc-hId--180766633%22%20id%3D%22toc-hId--180766633%22%3EClone%20the%20repo%3C%2FH4%3E%0A%3CPRE%20class%3D%22sourceCode%20bash%22%3E%3CCODE%20class%3D%22sourceCode%20bash%22%3E%3CSPAN%20class%3D%22kw%22%3Egit%3C%2FSPAN%3E%20clone%20https%3A%2F%2Fgithub.com%2Fssarwa%2Fbicep%0A%3CSPAN%20class%3D%22kw%22%3Ecd%3C%2FSPAN%3E%20bicep%0A%3CSPAN%20class%3D%22co%22%3E%23%20You%20could%20use%20deploy.azcli%20as%20your%20working%20file.%20Don't%20run%20the%20script%20as%20is!%3C%2FSPAN%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH4%20id%3D%22login-to-azure%22%20id%3D%22toc-hId--1988221096%22%20id%3D%22toc-hId--1988221096%22%20id%3D%22toc-hId--1988221096%22%20id%3D%22toc-hId--1988221096%22%3ELogin%20to%20Azure%3C%2FH4%3E%0A%3CPRE%20class%3D%22sourceCode%20bash%22%3E%3CCODE%20class%3D%22sourceCode%20bash%22%3E%3CSPAN%20class%3D%22kw%22%3Eaz%3C%2FSPAN%3E%20login%0A%0A%3CSPAN%20class%3D%22kw%22%3Eaz%3C%2FSPAN%3E%20account%20set%20-s%20%3CSPAN%20class%3D%22kw%22%3E%26lt%3B%3C%2FSPAN%3ESubscription%20ID%3CSPAN%20class%3D%22kw%22%3E%26gt%3B%3C%2FSPAN%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH4%20id%3D%22initialize-variables%22%20id%3D%22toc-hId-499291737%22%20id%3D%22toc-hId-499291737%22%20id%3D%22toc-hId-499291737%22%20id%3D%22toc-hId-499291737%22%3EInitialize%20variables%3C%2FH4%3E%0A%3CPRE%20class%3D%22sourceCode%20bash%22%3E%3CCODE%20class%3D%22sourceCode%20bash%22%3E%3CSPAN%20class%3D%22co%22%3E%23%20Change%20the%20variables%20as%20required%20(baseline%20and%20location)%20on%20deploy.azcli%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22co%22%3E%23%20Deploy%20the%20bicep%20script%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22kw%22%3Eaz%3C%2FSPAN%3E%20deployment%20sub%20create%20-n%20%3CSPAN%20class%3D%22ot%22%3E%24baseline%3C%2FSPAN%3E%3CSPAN%20class%3D%22st%22%3E'Dep'%3C%2FSPAN%3E%20-l%20%3CSPAN%20class%3D%22ot%22%3E%24location%3C%2FSPAN%3E%20-f%20main.bicep%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20deployment%20could%20take%20somewhere%20around%2020%20to%2030%20mins.%20Once%20provisioning%20is%20completed%20you%20can%20use%20the%20cluster%20for%20your%20needs.%3C%2FP%3E%0A%3CH2%20id%3D%22next-steps%22%20id%3D%22toc-hId--2009227304%22%20id%3D%22toc-hId--2009227304%22%20id%3D%22toc-hId--2009227304%22%20id%3D%22toc-hId--2009227304%22%3ENext%20Steps%3C%2FH2%3E%0A%3COL%20style%3D%22list-style-type%3A%20decimal%3B%22%3E%0A%3CLI%3EEnable%20GitOps%20using%20Flux%20operator%20for%20Application%20deployment%3C%2FLI%3E%0A%3CLI%3EEnable%20IaC%20using%20CI%2FCD%20pipelines%20on%20Github%20Actions%3C%2FLI%3E%0A%3C%2FOL%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2499201%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20blog%20uses%20new%20Bicep%20modules%20to%20deploy%20a%20complete%20Private%20AKS%20cluster%20with%20baseline%20architecture%20practices.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2499201%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EApp%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ECloud%20Native%20Apps%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EInfra%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2549178%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Private%20AKS%20Cluster%20using%20Bicep%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2549178%22%20slang%3D%22en-US%22%3E%3CP%3EWell%20explained!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Version history
Last update:
‎Jul 13 2021 10:25 AM
Updated by: