Wednesday, April 12, 2023

Shell Script for creating AKS Cluster with Monitoring enabled | Setup monitoring on AKS Cluster and Log Analytics Workspace

#!/bin/sh

# This is the shell script for creating AKS cluster with Monitoring enabled. you can Monitor AKS cluster using Grafana or Azure Monitor


#Create Resource Group

AKS_RESOURCE_GROUP=aks-rg

AKS_REGION=centralus

# Set Cluster Name

AKS_CLUSTER=aks-cluster


echo $AKS_RESOURCE_GROUP, $AKS_REGION, $AKS_CLUSTER


# Create Resource Group

az group create --location ${AKS_REGION} --name ${AKS_RESOURCE_GROUP}


# Create Log Analytics Workspace and store the ID in a variable

AKS_MONITORING_LOG_ANALYTICS_WORKSPACE_ID=$(az monitor log-analytics workspace create --resource-group ${AKS_RESOURCE_GROUP} \

--workspace-name aks-workspace \

--query id \

        -o tsv)

echo $AKS_MONITORING_LOG_ANALYTICS_WORKSPACE_ID


# Create AKS cluster with monitoring enabled and pass on log analytics workspace ID

az aks create --resource-group ${AKS_RESOURCE_GROUP} \

              --name ${AKS_CLUSTER} \

              --node-count 2 \

              --enable-addons monitoring \

              --workspace-resource-id ${AKS_MONITORING_LOG_ANALYTICS_WORKSPACE_ID} \


# Configure Kube Credentials

az aks get-credentials --name ${AKS_CLUSTER}  --resource-group ${AKS_RESOURCE_GROUP}


# Create service principal with monitoring reader role

az ad sp create-for-rbac --role="Log Analytics Reader" --scopes="$(az group show --name ${AKS_RESOURCE_GROUP} --query id --output tsv)"

No comments:

Post a Comment

How to create Ubuntu 22.0.4 Virtual Machine (VM) in Azure? | Create Ubuntu 22.0.4 VM in Azure | How to connect to Azure VM from your local machine

 How to Create Ubuntu 22.0.4 Virtual Machines(VM) in Azure portal? Creating Virtual Machine is easy and straight forward in Azure Cloud. Let...