Wednesday, April 12, 2023

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


# 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



# Set Cluster Name



# 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)


# 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 configure Self-Hosted GitHub Actions Runner | How to install Self-Hosted GitHub Actions Runner | Configure EC2 instance as self-hosted runner in GitHub Actions

A self-hosted GitHub runner is a machine (physical or virtual) that you set up and manage to run GitHub Actions workflows.  A self-hosted ru...