Setting Up Kube-Prometheus-Stack on Kubernetes Services

Suman Srivastava
3 min readJun 27, 2023

--

Effective Kubernetes cluster monitoring is essential for guaranteeing the stability and performance of applications in today’s continuously changing technological environment. The Kube Prometheus stack comes with enrich default dashboard solution to enhance your monitoring needs. Let us catch on all the steps for a basic and quick setup for the Kube Prometheus stack.

Prerequisites:

  1. Helm: Helm is a Kubernetes package manager that makes it easier to deploy applications and services. Install Helm by adhering to your operating system’s official documentation.
  2. kubectl: You can communicate with Kubernetes clusters using the kubectl command-line tool. Follow the instructions in your operating system’s official documentation to install kubectl.
  3. Azure CLI: With the Azure CLI, you can control Azure resources directly from the command line. Follow the instructions in your operating system’s official manual to install Azure CLI.

Setting Up the AKS Cluster:

Let’s start by utilising the Azure CLI to build an Azure Kubernetes Service (AKS) cluster. With straightforward d2 series virtual machines, we will set up a basic cluster. Enter the commands below into your terminal:

Preparing Helm Repositories:

Next, we need to set up the necessary Helm repositories for both Nginx Ingress and Kube Prometheus Stack. Run the following commands:

# Add the Nginx Ingress Helm repository
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

# Update the Helm repositories
helm repo update

# Add the Kube Prometheus Stack Helm repository
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

Deployment of Kube Prometheus Stack:

We can move forward with the deployment of the Kube Prometheus Stack in the “monitoring” namespace now that our AKS cluster is ready and the Helm repositories are established. ‘Kube-Prometheus-Values.yaml’ should be created and should contain the following information:

# Sample kube-prometheus-values.yaml
prometheus:
enabled: true

alertmanager:
enabled: true

grafana:
enabled: true

Execute the following commands to deploy the Kube Prometheus Stack:

# Create the "monitoring" namespace
kubectl create namespace monitoring

# Deploy the Kube Prometheus Stack
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack -n monitoring -f kube-prometheus-values.yaml

# Deploy the nginx ingress
helm install ingress-nginx ingress-nginx/ingress-nginx \
--namespace monitoring \
--set controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-health-probe-request-path"=/healthz

Setting Up Grafana Ingress and Data Source:

# Sample grafana-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: grafana-ingress
namespace: monitoring
spec:
rules:
- host: *
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: kube-prometheus-stack-grafana
port:
number: 80

kubectl apply -f grafana-ingress.yaml

Next, let’s set up a data source in Grafana to source the metrics from Prometheus. Follow these steps:

1. Access the Grafana dashboard using the external IP or hostname configured for the Ingress.

2. Log in to Grafana using the initial username and password.

3. Navigate to the Configuration section and click on “Add data source”.

4. Select “Prometheus” as the data source type.

5. Configure the URL of the Prometheus server. By default, it should be `http://prometheus-operator:9090`.
6. Save and Test the connection. Upon successful connection you can see a success message.

7. Now you can navigate to the Dashboard section and check the available dashboards.

Conclusion:

In conclusion, we have seen how the Kube Prometheus Stack can quickly staple to your Kubernetes monitoring and provide an enhanced monitoring experience for clusters. By following the steps outlined in this blog post, you can set up and configure the Kube Prometheus Stack on AKS, including setting up Grafana ingress and configuring the Prometheus data source.

#please use code with caution!

--

--

Suman Srivastava
Suman Srivastava

Written by Suman Srivastava

A DevOps professional experienced in setting up secure, highly scalable, available and scalable infrastructure on cloud

No responses yet