Monitoring Kubernetes with Prometheus and Grafana

Monitoring Kubernetes with Prometheus and Grafana

Monitoring your Kubernetes cluster is critical for ensuring that your services are always available and running. And before you scour the internet for a monitoring system, why not try Grafana and Prometheus Kubernetes cluster monitoring?

Grafana and Prometheus Kubernetes Cluster Monitoring report on potential performance bottlenecks, cluster health, and performance metrics. Visualize network consumption, pod resource utilization trends, and a high-level summary of cluster activity all at once.

In this article, you will learn what are Prometheus and Grafana for Kubernetes monitoring and how to monitor your Kubernetes cluster, viewing internal state metrics with Prometheus and the Grafana dashboard.

Table of contents:

  1. Introduction to Prometheus and Grafana
  2. How to monitor Kubernetes cluster using Prometheus and Grafana?
  3. Create Namespace and Add Helm Charts Repo
  4. Deploying Helm Charts to Created Namespace
  5. Accessing the Prometheus Instance and Viewing the Internal State Metrics
  6. Visualizing a Cluster’s Internal State Metric on Prometheus
  7. Monitoring and Visualizing with Grafana Dashboards
  8. Conclusion

  1. Introduction to Prometheus and Grafana

Prometheus

There are many open-source time-series databases available today, including Graphite, InfluxDB, and Cassandra, but none are as well-liked among Kubernetes users as Prometheus. Prometheus, which started out as a SoundCloud project and is now a part of CNCF (Cloud Native Computing Foundation), has become the open-source de-facto standard for monitoring Kubernetes.

In a nutshell, Prometheus's multi-dimensional data model, PromQL (the Prometheus querying language), built-in alerting features, a pull vs. push approach, and, of course, the always expanding community are what set it apart from other time-series databases. The two projects are now tightly connected, allowing users to quickly operate Prometheus on top of Kubernetes using the Prometheus Operator. These differentiators make Prometheus a great option for Kubernetes users.?

Grafana?

An open-source, cross-platform online application for interactive visualization and analytics is called Grafana. When connected to supported data sources, it offers charts, graphs, and alerts for the web. It is extendable using a plug-in architecture. A licensed Grafana Enterprise version with additional features is also available as a self-hosted installation or an account on the Grafana Labs cloud service. Using interactive query builders, end users may design sophisticated monitoring dashboards. The front end and back end of Grafana are each composed of TypeScript and Go code, respectively.

There are a number of reasons Grafana is so popular, its ability to integrate with a long list of data sources being one of them. Grafana is extremely robust, featuring a long list of capabilities such as alerts, annotations, filtering, data source-specific querying, visualization and dashboarding, authentication/authorization, cross-organizational collaboration, and plenty more.?

  1. How to monitor Kubernetes cluster using Prometheus and Grafana: step by step guide

If you want to create your own monitoring dashboard for your Kubernetes cluster. You’ll be using Prometheus (https://prometheus.io//) to handle the extraction, transformation, and loading of all your assets from the Kubernetes cluster.?Grafana?will be used for querying, visualizing, monitoring, and notifying.

Prerequisites:?

?

  1. Create Namespace and Add Helm Charts Repo

The first step is to create a namespace in the Kubernetes cluster. It will establish a separate place in your Kubernetes cluster for the Prometheus and Grafana servers to be deployed into.

kubectl create namespace monitoring

After you have run the above commands, you need to add the Prometheus-community helm repo and also update the repo. To do so, run the following commands.

# Add prometheus-community repo

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

# Update helm repo

helm repo update

  1. Deploying Helm Charts to Created Namespace

Run the helm install command listed below to deploy the Helm chart for the kube-prometheus stack after adding the Helm repo. You can use any other name in place of "monitoring."

This Helm chart configures a thorough Prometheus Kubernetes monitoring stack by acting on a collection of Custom Resource Definitions (CRDs). Run the following commands to deploy the chart to the Kubernetes cluster.

helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring

To verify the deployment of your Kube-Prometheus stack, run the following command.

kubectl get pods -n monitoring

  1. Accessing the Prometheus Instance and Viewing the Internal State Metrics

The next step is to utilize Prometheus and Grafana to monitor your Kubernetes cluster after you have successfully deployed their instances there. To accomplish this, we must allow traffic to the Prometheus pod in order to monitor the internal metrics of your cluster. You will be able to use your browser to access the Prometheus server as a result. To find out which Prometheus server you will be redirecting traffic to, run the command below.

kubectl get svc -n monitoring

Next, run the below kubectl port-forward command to forward the local port 9090 to your cluster via the Prometheus service (svc/monitoring-kube-prometheus-prometheus). To do so run the following commands.

kubectl port-forward svc/prometheus-kube-prometheus-prometheus -n monitoring 9090

Open a web browser, and navigate to either of the URLs below to access your Prometheus instance.

Navigate to https://localhost:9090 if you’re following along with local windows, Linux, or mac machines. Navigate to your server’s IP address followed by port 9090 (i.e., https://YOUR_SERVER_IP:9090) if you’re using a cloud server.

  1. Visualizing a Cluster’s Internal State Metric on Prometheus

Now, to view the internal status metrics of our Kubernetes cluster, we will now run some Prometheus queries. We'll concentrate on CPU usage. For additional information on the Prometheus query language, You can visit Prometheus’ official website.


No alt text provided for this image


  1. Monitoring and Visualizing with Grafana Dashboard

Prometheus visualization options are limited, only a Graph. Prometheus is great for collecting metrics from targets set as tasks, aggregating the metrics, and storing them locally on the workstation. However, when it comes to traditional resource monitoring adding Grafana is a great option.

Metrics produced by server components such as node exporter, CoreDNS, and others are collected by Prometheus. Grafana obtains these metrics from Prometheus and displays them in a number of ways on its dashboard.

  1. Conclusion

In this article, we learned about Kubernetes monitoring using Prometheus and Grafana. We also saw step by step guide to set up Prometheus to Kubernetes cluster nodes and Grafana dashboard to visualize key internal metrics

References:

[1]?https://adamtheautomator.com/prometheus-kubernetes/

[2]?https://earthly.dev/blog/grafana-and-prometheus-k8s/

[3]?https://grafana.com/grafana/dashboards/315-kubernetes-cluster-monitoring-via-prometheus/

[4]?https://logz.io/blog/open-source-monitoring-tools-for-kubernetes/

要查看或添加评论,请登录

社区洞察

其他会员也浏览了