How to Configure Istio, Prometheus and Grafana for Monitoring
Learn to configure metrics in Prometheus from Istio service mesh to understand Kubernetes application performance and visualize graphs of metrics using Grafana.
Join the DZone community and get the full member experience.
Join For FreeIntro to Istio Observability Using Prometheus
Istio service mesh abstracts the network from the application layers using sidecar proxies. You can implement security and advance networking policies to all the communication across your infrastructure using Istio.
But another important feature of Istio is observability. You can use Istio to observe the performance and behavior of all your microservices in your infrastructure (see the image below). One of the primary responsibilities of Site reliability engineers (SREs) in large organizations is to monitor the golden metrics of their applications, such as CPU utilization, memory utilization, latency, and throughput.
In this article, we will discuss how SREs can benefit from integrating three open-source software- Istio, Prometheus, and Grafana. While Istio is the most famous service software, Prometheus is the most widely used monitoring software, and Grafana is the most famous visualization tool.
Note: The steps are tested for Istio 1.17.X
Watch the Video of Istio, Prometheus, and Grafana Configuration
Watch the video if you want to follow the steps from the video:
Step 1: Go to Istio Add-Ons and Apply Prometheus and Grafana YAML File
First, go to the add-on folder in the Istio directory using the command. Since I am using 1.17.1, the path for me is istio-1.17.1/samples/addons
You will notice that Istio already provides a few YAML files to configure Grafana, Prometheus, Jaeger, Kiali, etc. You can configure Prometheus by using the following command:
kubectl apply -f prometheus.yaml
kubectl apply -f grafana.yaml
Note these add-on YAMLs are applied to istio-system
namespace by default.
Step 2: Deploy New Service and Port-Forward Istio Ingress Gateway
To experiment with the working model, we will deploy the httpbin
service to an Istio-enabled namespace. We will create an object of the Istio ingress gateway to receive the traffic to the service from the public.
We will also port-forward the Istio ingress gateway to a particular port-7777.
You should see the below screen at localhost:7777
Step 3: Open Prometheus and Grafana Dashboard
You can open the Prometheus dashboard by using the following command.
istioctl dashboard prometheus
istioctl dashboard grafana
Both the Grafana and Prometheus will open in the localhost.
Step 4: Make HTTP Requests From Postman
We will see how the httpbin
service is consuming CPU or memory when there is a traffic load. We will create a few GET
and POST
requests to the localhost:7777
from the Postman app.
Once you GET
or POST
requests to httpbin
service multiple times, there will be utilization of resources, and we can see them in Grafana. But at first, we need to configure the metrics for httpbin
service in Prometheus and Grafana.
Step 5: Configuring Metrics in Prometheus
One can select a range of metrics related to any Kubernetes resources such as API server, applications, workloads, envoy, etc. We will select container_memory_working_set_bytes
metrics for our configuration.
In the Prometheus application, we will select the namespace to scrape the metrics using the following search term: container_memory_working_set_bytes { namespace= “istio-telemetry”}
(istio-telemetry
is the name of our Istio-enabled namespace, where httpbin
service is deployed)
Note that, simply running this, we get the memory for our namespace. Since we want to analyze the memory usage of our pods, we can calculate the total memory consumed by summing the memory usage of each pod grouped by pod. The following query will help us in getting the desired result : sum(container_memory_working_set_bytes{namespace=”istio-telemetry”}) by (pod)
Note: Prometheus provides a lot of flexibility to filter, slice, and dice the metric data. The central idea of this article was to showcase the ability of Istio to emit and send metrics to Prometheus for collection
Step 6: Configuring Istio Metrics Graphs in Grafana
Now, you can simply take the query sum(container_memory_working_set_bytes{namespace=”istio-telemetry”}) by (pod)
in Prometheus and plot a graph with time. All you need to do is create a new dashboard in Grafana and paste the query into the metrics browser. Grafana will plot a time-series graph. You can edit the graph with proper names, legends, and titles for sharing with other stakeholders in the Ops team.
There are several ways to tweak and customize the data and depict the Prometheus metrics in Grafana. You can choose to make all the customization based on your enterprise needs. I have done a few experiments in the video; feel free to check it out.
Conclusion
Istio service mesh is extremely powerful in providing overall observability across the infrastructure. In this article, we have just offered a small use case of metrics scrapping and visualization using Istio, Prometheus, and Grafana. You can perform logging and tracing of logs and real-time traffic using Istio; we will cover those topics in our subsequent blogs.
Published at DZone with permission of Md Azmal. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments