2-Olly
Grafana-Stack
Minikube
K8s Grafana Prometheus

Grafana and Prometheus Setup in Kubernetes Using Helm

This README provides step-by-step instructions for setting up Grafana and Prometheus for monitoring in a Kubernetes cluster using Helm.

Prerequisites

  1. Kubernetes Cluster: A running Kubernetes cluster. You can use Minikube, a managed cluster, or any other Kubernetes provider.
  2. Helm: Installed and configured in your environment. Follow Helm’s installation guide (opens in a new tab) if needed.
  3. kubectl: Installed and configured for your Kubernetes cluster. Refer to the kubectl installation guide (opens in a new tab) for setup instructions.

Step 1: Create a Namespace

First, create a namespace for monitoring resources:

kubectl create namespace monitoring

Step 2: Add Helm Repositories

Add the required Helm chart repositories for Prometheus and Grafana:

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

Step 3: Install Prometheus

Install Prometheus using Helm:

helm install prometheus prometheus-community/prometheus -n monitoring

The Prometheus server can be accessed via port 80 using the following DNS name from within your cluster:

http://prometheus-server.monitoring.svc.cluster.local

Step 4: Install Grafana

Install Grafana using Helm:

helm install grafana grafana/grafana -n monitoring

Accessing Grafana

  1. Get your 'admin' user password by running the following command:

    kubectl get secret --namespace monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

    The default password will be displayed. For example:

    PASS : aIwX6UK5LLkHQWKmGGQvCtME0BA93YKaH4T91tZt
  2. You can access Grafana at:

grafana.monitoring.svc.cluster.local

Step 5: Expose Services to Localhost

To access Prometheus and Grafana from your local machine, use port-forwarding: (or you can use LB or ingress )

kubectl port-forward service/prometheus-server --namespace monitoring 8090:80
kubectl port-forward service/grafana --namespace monitoring 3000:80
kubectl patch svc grafana -n monitoring -p '{"spec": {"type": "NodePort"}}'

Now you can access:

  • Prometheus: http://localhost:8090
  • Grafana: http://localhost:3000

Step 6: Configure Prometheus as a Data Source in Grafana

  1. Open Grafana (http://localhost:3000) and log in.
  2. Go to Configuration > Data Sources.
  3. Click Add Data Source and select Prometheus.
  4. Set the URL to http://prometheus-server.monitoring.svc.cluster.local:80.
  5. Click Save & Test to verify the data source is working.

Step 7: Import Dashboards

You can enhance your Grafana setup by importing pre-configured dashboards. Here are some popular Kubernetes dashboards:

Dashboard IDs

Refer to the following dashboards from dotdc/grafana-dashboards-kubernetes (opens in a new tab):

Dashboard NameDashboard ID
k8s-addons-prometheus.json19105
k8s-addons-trivy-operator.json16337
k8s-system-api-server.json15761
k8s-system-coredns.json15762
k8s-views-global.json15757
k8s-views-namespaces.json15758
k8s-views-nodes.json15759
k8s-views-pods.json15760

Cleanup (Optional)

To uninstall Prometheus and Grafana, run the following commands:

helm uninstall prometheus -n monitoring
helm uninstall grafana -n monitoring
kubectl delete namespace monitoring

Troubleshooting

  • Grafana or Prometheus Not Accessible: Ensure port-forwarding is set up correctly or check the service type for external access.
  • Data Not Showing in Grafana: Confirm that the Prometheus data source URL is correct in Grafana.

Additional Resources


This README provides a foundational setup for Grafana and Prometheus, which you can further customize based on your monitoring needs.


💬 Need a Quick Summary?

Hey! Don't have time to read everything? I get it. 😊
Click below and I'll give you the main points and what matters most on this page.
Takes about 5 seconds • Uses Perplexity AI