Open In App

Monitoring Kubernetes Clusters with Prometheus and Grafana

Last Updated : 26 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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
podsrunning
Pods running in Namespace

Step 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
serverrunning
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) .
homepage
Home Page of Prometheus

Step 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.
monitoring
  • 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-(1)-(1)
PromQL query of a cluster metric in Graphical view

Step 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.
grafanalogin-(1)_11zon
Login page of Grafana
  • Now to the start a monitoring, type of this URL in your browser
homepagediag-(1)-(1)
  • In a http://localhost:3001/dashboards or http://YOUR_SERVER_IP:3001/dashboards> if you’re using the cloud server.
grafanadash-(1)-(1)
Dashboards of a Grafana Page
  • Follow same steps to select dashboards for a Kubernetes resources and you want to be manage and monitor.
imported-(1)-(1)
Imported of the Dashboards

Conclusion

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.


Next Article
Article Tags :

Similar Reads