Monitoring Kubernetes Clusters with Prometheus and Grafana
Last Updated :
26 Jul, 2024
In modern era of containers, Kubernetes has emerged as a leading band. like any robust system, effective assessment is critical to ensuring it works, reliably and is scalable. Prometheus and Grafana, two powerful tools, combine to provide robust solution for managing a Kubernetes clusters. This article will guide you through setting up and using Prometheus and Grafana to manage your Kubernetes clusters.
Monitoring Kubernetes Clusters with Prometheus and Grafana Primary Terminologies
- Cluster: A set of nodes can be (worker machines running containerized applications managed by Kubernetes.
- Pod: A small deployable container in Kubernetes that contains one or more containers that share resources.
- Metrics: In a data point collected by a Prometheus, organized as counters, gauges, histograms, or summaries,.
- Scrape: A Prometheus method of collecting metrics from endpoints on periodic basis.
- PromQL: The Prometheus Query Language is used to query and manipulate time-series data.
- Dashboard: The Grafana software, which interacts with multiple monitors for visualization and metrics.
- Alert manager: A process that works with Prometheus to identify the alerts and is used to route, silence and group the alerts.
Introduction to Prometheus and Grafana
Prometheus
In a open-source time-collection databases available these days, together with Graphite, InfluxDB, and Cassandra, however none are as nicely-preferred amongst Kubernetes customers as Prometheus. Prometheus, which began out as a SoundCloud mission and is now a part of CNCF (Cloud Native Computing Foundation), has turn out to be the open-supply de-facto widespread for monitoring Kubernetes.
for nutshell, Prometheus's multi-dimensional facts version, PromQL (the Prometheus querying language), built-in alerting features, a pull vs. Push approach, and, of direction, the usually increasing network are what set it apart from other time-series databases. The initiatives are actually tightly connected, allowing users to quick function Prometheus on pinnacle of Kubernetes the use of the Prometheus Operator. These differentiators make Prometheus a notable choice for Kubernetes users.
Grafana
An open-source, go-platform online utility for interactive visualization and analytics is called Grafana. When related to supported records assets, it gives charts, graphs, and signals for the web. It is extendable the usage of a plug-in structure. A certified Grafana Enterprise model with additional functions is likewise to be had as a self-hosted set up or an account on the Grafana Labs cloud service. Using interactive question developers, cease customers may additionally design sophisticated monitoring dashboards. The front give up and returned stop of Grafana are every composed of TypeScript and Go code, respectively.
In a number of reasons Grafana is so popular, its capability to integrate with an extended listing of information sources being one of them. Grafana is extremely robust, providing a long listing of talents which include indicators, annotations, filtering, facts source-particular querying, visualization and dashboarding, authentication/authorization, pass-organizational collaboration, and lots more.
Step-By-Step to Monitoring Kubernetes Clusters with Prometheus and Grafana
Here are the detained steps to monitor Kubernetes cluster using the Prometheus and Grafana.
Step 1: Create a Namespace and Add Helm Charts Repo
- In a first step is to create a namespace within the Kubernetes cluster. It will be establish a separate vicinity on your Kubernetes cluster for the Prometheus and Grafana servers to be deployed into.
kubectl create namespace monitoring
- After you have run the above instructions, you want to be add the Prometheus community helm repo and additionally update repo. To a achieve this, run the following Command.
# Add Prometheus-community repo
helm repo add Prometheus-community https://prometheus-community.github.io/helm-charts
# Update helm repo
helm repo update
- The Deploying Helm Charts to a Created Namespace
helm install monitoring Prometheus-community/Kube-Prometheus-stack \
--namespace Kubernetes-monitoring
Pods running in NamespaceStep 2: Deploying a Helm Charts to Created a Namespace
- Run a helm install command indexed under to installation the Helm chart for the kube-prometheus stack after including the Helm repo. You can use another call in place of "monitoring."
- In This Helm chart configures a radical Prometheus Kubernetes monitoring stack by using performing on a group of Custom Resource Definitions (CRDs). Run the subsequent commands to installation the chart to the Kubernetes cluster.
helm install Prometheus Prometheus-community/kube-Prometheus-stack --namespace monitoring
- To a verify the deployment of your Kube-Prometheus stack, and run the following command.
kubectl get pods -n monitoring
Step 3: For Accessing a Prometheus Instance and Viewing a Internal State Metrics
- In a next step is to make use of Prometheus and Grafana to display your Kubernetes cluster after you've got efficiently deployed their instances there. You could be able to use your browser to get entry to the Prometheus server as a end result. To discover which Prometheus server you will be redirecting traffic to, run the command under.
kubectl get svc -n monitoring
running a Servers the Namespace- In Next, run the beneath kubectl port forward command to forward the nearby port 9090 for your cluster thru the Prometheus provider (svc/monitoring-kube-Prometheus-Prometheus). To be achieve this run the following commands.
kubectl port-forward svc/Prometheus-kube-Prometheus-Prometheus -n monitoring 9090
for Open a web browser, and navigate to either of the URLs below to access your Prometheus instance.
- In a Navigate to http://localhost:9090 if you’re following along local windows, Linux, or mac machines. In Navigate to your server’s IP address followed by port 9090 (i.e., http://YOUR_SERVER_IP:9090) .
Home Page of PrometheusStep 4: For Visualizing a Cluster’s Internal State Metric on a Prometheus
- To view the inner fame metrics of our Kubernetes cluster, we are able to now run few Prometheus queries. We'll focus on CPU usage. For a extra statistics on the Prometheus query language, You can be visit Prometheus' reliable internet site.
- Click the graph icon in top bar, enter following commands in search box to run query, and then click on the graph bar below search bar.
Sum by (cpu)(m=node_cpu_seconds_total{mode!="idle"})
PromQL query of a cluster metric in Graphical viewStep 5: Monitoring and a Visualizing with a Grafana Dashboard
- For Prometheus visualization alternatives are constrained, best a Graph. Prometheus is tremendous for gathering metrics from targets set as responsibilities, aggregating the metrics, and storing them regionally at the computer. However, while it comes to standard useful resource tracking including Grafana is a exquisite alternative.
kubectl get secret -n kubernetes-monitoring monitoring-grafana -o yaml
$ kubectl get secret -n kubernetes-monitoring monitoring-grafana -o yaml
apiVersion: v1
Data:
admin-password: chjvb51vcGVyYXRvcg
admin-user: YWRtaw4-
kind: secret
metadata
annotations:
meta.heml.sh/release-name: monitoring
meta.heml.sh/release-namespace: kubernetes-monitoring
creationTimestamp: "2022-07-30T11:14:592"
Labels:
app.kubernetes.io/insance: monitoring
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: monitoring
app.kubernetes.io/version: monitoring
helm.sh/chart: grafana-6.32.9
name: monitoring-grafana
namespace: kubernetes-monitoring
resourcesVersion: "3966"
vid: 3774e7dd-a294-473e-8482-2bda3769b37a
type: opaque
- In a Metrics produced via server components which includes node exporter, Core DNS, and others are accrued through Prometheus. Grafana obtains these metrics from Prometheus and shows them in some of methods on its dashboard.
kubectl port-forward svc/monitoring-grafana -n kubernetes-monitoring 3001:80
- In a Next type the admin-username and the password you have be a decoded to login.
Login page of Grafana- Now to the start a monitoring, type of this URL in your browser
- In a http://localhost:3001/dashboards or http://YOUR_SERVER_IP:3001/dashboards> if you’re using the cloud server.
Dashboards of a Grafana Page- Follow same steps to select dashboards for a Kubernetes resources and you want to be manage and monitor.
Imported of the DashboardsConclusion
In a Prometheus and Grafana, you currently are at having a strong logging and visualization setup in your Kubernetes cluster. Prometheus measures and stores values while Grafana provides a flexible way to plot and examine the values collected in Prometheus. This way, by keeping track of your Kubernetes cluster all the time you can see how well it performs, quickly identify problems and guarantee the stability and flexibility of your programs.
Similar Reads
Kubernetes Monitoring and Logging: Tools and Best Practices
Kubernetes (K8s) is an open-source project under the CNCF organization that mainly helps in container orchestration by simplifying the deployment and management of containerized applications. It is widely used in DevOps and cloud-native space, and one cannot imagine DevOps workflow without it. Durin
15+ min read
Setup Prometheus Node Exporter on Kubernetes
In monitoring has always been an essential layer of any powerful cloud-native architecture, and Kubernetes is not an exception. One of the most frequently used and mentioned open-source monitoring tools is Prometheus which is usually used in conjunction with Grafana for metrics visualization. of all
6 min read
What is Prometheus and Grafana
In a ever evolving of technological landscape, the need for management and insightful data visualization has never have been greater. for Two powerful tools, Prometheus and Grafana, In emerged as leaders this field, enabling to organizations to manage their processes and visualize metrics in compreh
7 min read
What is Prometheus Monitoring ?
In a dynamic era of international reality, important to maintain the capacity and effectiveness of systems. an increasing number of teams rely on robust and distributed architectures, the need for effective tracking solutions has once again to be discussed. Prometheus, an open supply chain monitorin
6 min read
How to Upgrade a Kubernetes Cluster?
Kubernetes, the open-source field orchestration platform, is continuously evolving to satisfy the demands of modern applications. Regularly upgrading your Kubernetes cluster is essential to leverage new capabilities, safety patches, and overall performance enhancements. In this article, we can dive
10 min read
Kubernetes Pods: How to Create and Manage Them
Kubernetes is an open-source container orchestration system mainly used for automated software deployment, management, and scaling. Kubernetes is also known as K8s. Kubernetes was originally developed by Google, but it is now being maintained by the Cloud Native Computing Foundation. It was original
13 min read
Kubernetes Node Vs. Pod Vs. Cluster: Whatâs The Difference?
Kubernetes automates most container management operations, allowing developers to operate high-performance, modern apps at scale. This includes built-in commands that handle most of the heavy lifting involved in application administration, allowing you to automate day-to-day tasks. Several component
7 min read
Fundamental Kubernetes Components and their role in Container Orchestration
Kubernetes or K8s is an open-sourced container orchestration technology that is used for automating the manual processes of deploying, managing and scaling applications by the help of containers. Kubernetes was originally developed by engineers at Google and In 2015, it was donated to CNCF (Cloud Na
12 min read
Working with Prometheus and Grafana Using Helm
Pre-requisite: HELM Package Manager Helm is a package manager for Kubernetes that allows you to install, upgrade, and manage applications on your Kubernetes cluster. With Helm, you can define, install, and upgrade your application using a single configuration file, called a Chart. Charts are easy to
5 min read
How to Add Node to Existing Kubernetes Cluster
Kubernetes allows the management and orchestration of containerized deployments. We can use various cluster managing tools, but Kubeadm allows us to create and manage Kubernetes clusters from scratch. Kubernetes cluster can be autoscaled with the use of Cluster management services. In this article,
4 min read