Configuring Access to Prometheus and Grafana via Sub-paths

1. Introduction

Grafana and Prometheus stand as integral tools for monitoring infrastructures across various industry sectors. This document aims to illustrate the process of redirecting Grafana and Prometheus to operate under the same domai…


This content originally appeared on DEV Community and was authored by Raymond

1. Introduction

Grafana and Prometheus stand as integral tools for monitoring infrastructures across various industry sectors. This document aims to illustrate the process of redirecting Grafana and Prometheus to operate under the same domain while utilizing distinct paths.

2. How does the story begin?

As a seasoned DevOps engineer, my commitment lies in sharing knowledge with a broader audience. My pursuit involves identifying tools conducive to enhancing the monitoring capabilities of both general users and fellow DevOps Engineers.

3. Prerequisites

Functioning Kubernetes Cluster
Proficiency in Kubernetes Management
Helm Installation
Optional: K9s for Kubernetes Cluster Observation (GitHub link)

4. Goals & Objectives

After researching, I found a lack of available information on this topic despite numerous related questions online. Hence, I’m writing a guide to fill this gap.

5. Step-by-Step Guide

Step 1: Installing Kube-prometheus-stack

Create a values.yml file to configure the Helm chart values for both Prometheus and Grafana.

grafana:
  env:
    GF_SERVER_SERVE_FROM_SUB_PATH: true
grafana.ini:
  server:
    domain: "<domain>"
    root_url: "<protocol>:<domain>/<path>/"
prometheus:
  prometheusSpec:
    externalUrl: "<protocol>:<domain>/<path>/"
    routePrefix: /path`

For instance

grafana:
  env:
    GF_SERVER_SERVE_FROM_SUB_PATH: true
  grafana.ini:
    server:
      domain: "example.com"
      root_url: "https://example.com/grafana/"
prometheus:
  prometheusSpec:
    externalUrl: "https://example.com/prometheus/"
    routePrefix: /prometheus
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install <relase-name> prometheus-community/kube-prometheus-stack -n <namespace> -f values.yml

Step 2. Create Ingress for mapping domain

There are two methods to accomplish this task:

Define in the values.yml file for automatic creation.
Another approach involves manually creating a YAML file for the ingress. I opted for this method because it allows centralized management, facilitating easy problem identification if any issues arise.
Create ingress.yml file

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: prometheus
  namespace: monitoring
  annotations:
    kubernetes.io/ingressClassName: "traefik"
spec:
  rules:
    - host: ""
      http:
        paths:
          - path: /prometheus
            pathType: Prefix
            backend:
              service:
                name: <helm-release-name>-kube-prometheus-prometheus
                port:
                  number: 9090
          - path: /grafana
            pathType: Prefix
            backend:
              service:
                name: <helm-release-name>-grafana
                port:
                  number: 80

Execute the following command to apply the changes:

kubectl apply -f ingress.yml

The result is shown below

Prometheus

Grafana

6. Conclusion

As I venture into writing for Medium, I acknowledge potential errors in this documentation. I invite feedback and further inquiries from readers to improve the accuracy and comprehensiveness of this guide. Thank you for your attention and engagement.


This content originally appeared on DEV Community and was authored by Raymond


Print Share Comment Cite Upload Translate Updates
APA

Raymond | Sciencx (2024-06-18T00:41:30+00:00) Configuring Access to Prometheus and Grafana via Sub-paths. Retrieved from https://www.scien.cx/2024/06/18/configuring-access-to-prometheus-and-grafana-via-sub-paths/

MLA
" » Configuring Access to Prometheus and Grafana via Sub-paths." Raymond | Sciencx - Tuesday June 18, 2024, https://www.scien.cx/2024/06/18/configuring-access-to-prometheus-and-grafana-via-sub-paths/
HARVARD
Raymond | Sciencx Tuesday June 18, 2024 » Configuring Access to Prometheus and Grafana via Sub-paths., viewed ,<https://www.scien.cx/2024/06/18/configuring-access-to-prometheus-and-grafana-via-sub-paths/>
VANCOUVER
Raymond | Sciencx - » Configuring Access to Prometheus and Grafana via Sub-paths. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/18/configuring-access-to-prometheus-and-grafana-via-sub-paths/
CHICAGO
" » Configuring Access to Prometheus and Grafana via Sub-paths." Raymond | Sciencx - Accessed . https://www.scien.cx/2024/06/18/configuring-access-to-prometheus-and-grafana-via-sub-paths/
IEEE
" » Configuring Access to Prometheus and Grafana via Sub-paths." Raymond | Sciencx [Online]. Available: https://www.scien.cx/2024/06/18/configuring-access-to-prometheus-and-grafana-via-sub-paths/. [Accessed: ]
rf:citation
» Configuring Access to Prometheus and Grafana via Sub-paths | Raymond | Sciencx | https://www.scien.cx/2024/06/18/configuring-access-to-prometheus-and-grafana-via-sub-paths/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.