Monitoring Your Kubernetes Cluster Using Prometheus and Grafana Dashboard
To monitor your cluster we need to install some tools before monitoring it
Minikube cluster or any other cluster
kubectl installed
docker or any other driver if you are using minikube
helm installed
Lets start
helm repo add grafana https://grafana.github.io/helm-charts
Now you can use Helm to access and install Prometheus-related charts from this repository.
helm repo update
Running this command will refresh the local cache of available Helm charts from all the repositories you have added, including the Grafana and Prometheus Community repositories you added earlier.
helm install prometheus prometheus-community/prometheus
This command will install Prometheus using the chart from the Prometheus Community Helm repository with the release name "prometheus
kubectl expose service prometheus-server --type=NodePort --target-port=9090 --name=prometheus-server-ext
The newly created NodePort service "prometheus-server-ext" will expose Prometheus on a random high port on each of your cluster's nodes, making it accessible externally. You can find the NodePort by describing the service or checking your cluster's service list.
Prometheus server is accessible at 31021 port.
helm repo add grafana https://grafana.github.io/helm-charts
This command will add the Grafana Helm repository with the name "grafana." Now you can use Helm to search for and install charts from this repository.
helm install grafana grafana/grafana
This command will install Grafana with the release name "grafana" using the chart from the official Grafana Helm repository.
kubectl get secret namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
This command fetches the admin password from the "grafana" secret in the "default" namespace, decodes it, and then prints it to the console. You'll see the Grafana admin password displayed in your terminal when you run this command.
kubectl expose service grafana --type=NodePort --target-port=3000 --name=grafana-ext
This command assumes that you have a Service named "grafana" already created, possibly as a result of installing Grafana using Helm. The newly created NodePort service "grafana-ext" will expose Grafana on a random high port on each of your cluster's nodes, making it accessible externally.
The default password username of grafan is admin
use password which you scrape in secrets.
- click on add your first data source.
Add data source as Prometheus.
- Put Prometheus URL and test.
- Click on Save and Exit.
- Click on create your first dashboard.
- Click on import.
- Type 3662 code and click on load.
- Click on import button to import dashboard.
The dashboard was able to scrape the matrix of the Kubernetes cluster.