상세 컨텐츠

본문 제목

Comprehensive Setup Guide for Prometheus and Grafana in AKS - Powershell

본문

I will explain easy and comprehensive way to install and setup Prometheus and Grafana in AKS (Azure Kubernetes Service).
 
In Kubernetes eco-system, the monitoring and alerting get handled by Prometheus and Grafana.  The main purpose of Prometheus is to gather monitoring logs, but it is not user-friendly to visualize data in Prometheus.  Grafana is to help you visualize the log data because it is fairly easy to visualize log data in Grafana.  One of the shortcomings of Grafana is that it cannot gather and store monitoring log data.  Therefore, Prometheus and Grafana complement each other and usually work together in Kubernetes environment.
 

728x90

1. Prerequisites

a. Windows Environment (10 or 11)

b. Azure CLI

Installation instructions are listed below:
https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli

 

Install the Azure CLI for Windows

To install the Azure CLI on Windows, you must use Powershell, or an MSI installer, which gives you access to the CLI through the Windows Command Prompt (CMD).

learn.microsoft.com

c. chocolatey

chocolatey is a tool for PowerShell that lets you install various tools or plugins. The link below has instructions and also I have separately explained it below the link:
https://chocolatey.org/install

 

Installing Chocolatey

Chocolatey is software management automation for Windows that wraps installers, executables, zips, and scripts into compiled packages. Chocolatey integrates w/SCCM, Puppet, Chef, etc. Chocolatey is trusted by businesses to manage software deployments.

chocolatey.org

chocolatey instructions
1. Open PowerShell (run as Administrator !!!!)
2. Enter the command below:

Get-ExecutionPolicy

3. If the return value is Restricted, then enter ONE of the following commands below. 
If the return value is NOT Restricted, then skip to the next step.

Set-ExecutionPolicy AllSigned
Set-ExecutionPolicy Bypass -Scope Process

4. Install chocolatey using the following command:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

d. helm & base64

helm and base64 can be easily installed by chocolatey using the commands below:

choco install kubernetes-helm
choco install base64

Helm - https://github.com/helm/helm

 

GitHub - helm/helm: The Kubernetes Package Manager

The Kubernetes Package Manager. Contribute to helm/helm development by creating an account on GitHub.

github.com

base64 - https://community.chocolatey.org/packages/base64

 

Base64 encoder/decoder 1.0.0

a command-line Base64 tool

community.chocolatey.org

 

반응형

2. Instructions

a. Open PowerShell

b. Set Azure login and subscription using Azure CLI

az login
az account set --subscription <Subscription ID - DO NOT include brackets>

c. Download kubectl account information 

az aks get-credentials --name <AKS Cluster Name - DO NOT include brackets> --resource-group <AKS Cluster Resource Group Name - DO NOT include brackets>

d. Install Prometheus and Grafana 

Enter each command below in PowerShell

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

helm repo update

helm repo list

kubectl create ns prometheus

helm install prometheus prometheus-community/kube-prometheus-stack -n prometheus

kubectl get all -n prometheus

If you did not have any errors, it is all set.  Please keep in mind that your namespace and service names may be different if you set different names during the installation.


3. Accessing Prometheus and Grafana After Installation

In a production environment, you will use Public ID and DNS to access them.  In a dev environment, you will use Port Forwarding and use localhost in a browser. Please keep in mind that your namespace and service names may be different if you set different names during the installation.

a. Prometheus 

By entering the command below in PowerShell, you can access it on your browser, located at localhost:9090

kubectl port-forward -n prometheus prometheus-prometheus-kube-prometheus-prometheus-0 9090

b. Grafana

Entering the command below, you can access Grafana using your browser, located at localhost:3000.  However, you need Grafana's admin user account information when accessing it (shown in the code block below).

# Grafana Admin Username Info
kubectl get secret -n prometheus prometheus-grafana -o=jsonpath='{.data.admin-user}' |base64 -d

# Grafana Admin Password Info
kubectl get secret -n prometheus prometheus-grafana -o=jsonpath='{.data.admin-password}' |base64 -d

# Port forward the Grafana service
kubectl port-forward -n prometheus <Name of Grafana's POD in AKS - DO NOT include brackets> 3000

You must change Grafana's admin password after the first login.  It is possible in Grafana's GUI.


 

728x90
반응형

관련글 더보기