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

DevOps Interview Preparation Useful real time tips | Crack DevOps Interviews | How to clear DevOps Interviews

Are you failing in DevOps Interviews? Are you not be able to next round in the Interview process?  Let's find out how to fix this:   Fir...