Prometheus-Grafana
It all starts with Monitoring
Monitoring your Kubernetes cluster is essential for ensuring the health and performance of your applications and infrastructure. Here are some reasons why monitoring your Kubernetes cluster is important:
· Identify issues and troubleshoot: By monitoring your Kubernetes cluster, you can quickly identify issues such as application crashes, resource bottlenecks, and network problems. With real-time monitoring, you can troubleshoot issues before they escalate and impact your users.
· Optimize performance and capacity: Monitoring allows you to track the performance of your applications and infrastructure over time, and identify opportunities to optimize performance and capacity. By understanding usage patterns and resource consumption, you can make informed decisions about scaling your infrastructure and improving the efficiency of your applications.
· Ensure high availability: Kubernetes is designed to provide high availability for your applications, but this requires careful monitoring and management. By monitoring your cluster and setting up alerts, you can ensure that your applications remain available even in the event of failures or unexpected events.
· Security and compliance: Monitoring your Kubernetes cluster can help you identify potential security risks and ensure compliance with regulations and policies. By tracking access logs and other security-related metrics, you can quickly detect and respond to potential security threats.
Using Prometheus for monitoring
Prometheus is an open-source monitoring and alerting system that helps you collect and store metrics about your software systems and infrastructure, and analyze that data to gain insights into their health and performance. It provides a powerful query language, a flexible data model, and a range of integrations with other tools and systems. With Prometheus, you can easily monitor metrics such as CPU usage, memory usage, network traffic, and application-specific metrics, and use that data to troubleshoot issues, optimize performance, and create alerts to notify you when things go wrong.
Why Prometheus over other monitoring tools ?
Prometheus is a popular choice for Kubernetes monitoring for several reasons:
· Open-source: Prometheus is an open-source project that is free to use and has a large community of contributors. This means that you can benefit from ongoing development, bug fixes, and feature enhancements without paying for a commercial monitoring solution.
· Native Kubernetes support: Prometheus is designed to work seamlessly with Kubernetes, making it easy to deploy and integrate with your Kubernetes environment. It provides pre-configured Kubernetes dashboards and supports auto-discovery of Kubernetes services and pods.
· Powerful query language: Prometheus provides a powerful query language that allows you to easily retrieve and analyze metrics data. This allows you to create custom dashboards and alerts, and to troubleshoot issues more easily.
· Scalability: Prometheus is designed to be highly scalable, allowing you to monitor large and complex Kubernetes environments with ease. It supports multi-node architectures and can handle large volumes of data without significant performance degradation.
· Integrations: Prometheus integrates with a wide range of other tools and systems, including Grafana for visualization, Alertmanager for alerting, and Kubernetes API server for metadata discovery.
Prometheus Architecture
What is Grafana ?
Grafana is a popular open-source data visualization and analytics platform that allows you to create custom dashboards and visualizations based on a variety of data sources. Grafana is often used for monitoring and analyzing metrics and logs in real-time, making it an ideal tool for monitoring systems and applications, including Kubernetes environments.
Grafana supports a wide range of data sources, including databases, time-series databases, and other data storage systems. It provides a powerful query language that allows you to retrieve and analyze data from these sources, and to create custom dashboards and alerts based on that data.
In addition to its powerful data visualization and analysis capabilities, Grafana is also highly extensible. It supports a wide range of plugins and integrations, including integrations with popular monitoring and logging tools like Prometheus, Elasticsearch, and InfluxDB.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Pre-Requisite
- Kubernetes Cluster (can be minikube)
- Helm
Steps to install Minikube :
……………………….Run These Commands on Ubuntu Server………………….
$ sudo su
$ Now install docker
$ sudo apt update && apt -y install docker.io
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
install Kubectl
$ curl -LO “https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
$ chmod +x kubectl
$ sudo mv kubectl /usr/local/bin/
$ kubectl version — short
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -
install Minikube
$ curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/v1.24.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
********************************************************************
Install Conntrack
$ apt install conntrack
*******************************************************************
Start Minikube
$ minikube start — vm-driver=none
$ minikube status
To download helm
$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh
To verify the installation use the following command
$ which helm
Install Grafana using Helm
Add helm repo
$ helm repo add grafana https://grafana.github.io/helm-charts
Update helm repo
$ helm repo update
Install helm
$ helm install grafana grafana/grafana
Expose Grafana Service
$kubectl expose service grafana --type=NodePort --target-port=3000 --name=grafana-ext
(Now Access the grafana dashboard with ip and nodeport.)
<Ipadress>:<nodeport> e.g 43.204.238.237:32181
You can get nodeport id through
$ kubectl get services
Get your ‘admin’ user password by running:
kubectl get secret — namespace default grafana -o jsonpath=”{.data.admin-password}” | base64 — decode ; echo
Username: admin
Password: you get through command
Now you are loggedin to grafana dashboard
Expose to get data from new end point
kubectl expose service prometheus-kube-state-metrics — type=NodePort — target-port=8080 — name=prometheus-kube-state-metrics-ext
(Through this you can expose matrics of the cluster)
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Install prometheus
using Helm
Add helm repo
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
Update helm repo
helm repo update
Install helm
helm install prometheus prometheus-community/prometheus
Expose Prometheus Service
This is required to access prometheus-server using your browser.
kubectl expose service prometheus-server --type=NodePort --target-port=9090 --name=prometheus-server-ext
Now you Expose the Prometheus server , access it on any browser through nodeport. <ipadress>:<nodeport> e.g:43.54.64.64:31900
Prometheus is successfully running.
Now you have to add data source in grafana for vitalizing, in our case we used promethus url as a data source.
Now login grafana and create new dashboard.
Goto Home>Connections>Datasource
and add new datasource.
Paste the url of you promethus server and click on save and test.
Now Create dash board for vitulizing
You can used already created dashboard from grafana official website.
https://grafana.com/grafana/dashboards/
Now go to Home>Dashboard>importDashboard, and paste the id that you copy. E.g 6336,3662 etc
Now your dashboard is ready for vitalizing, it collect matrics of server from promethus and display it on grafana.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
As a seasoned DevOps engineer with over 4 years of hands-on experience, I thrive on tackling complex infrastructure challenges and optimizing workflows. Whether you’re looking to streamline your CI/CD pipelines, implement robust cloud solutions, or enhance security through automation, I’m here to help.
Feel free to contact me for expert advice, consultation services, or project collaborations:
LinkedIn: Linkedin Profile
WhatsApp: +923084155287
Medium: Medium Profile
Email: uzairsheikh153@gmail.com
Let’s innovate and transform together!