<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Rayan Slim</title>
    <description>The latest articles on Forem by Rayan Slim (@rslim087a).</description>
    <link>https://forem.com/rslim087a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2222737%2F239627ce-0bdf-4e25-b9d6-862d5d5c5869.png</url>
      <title>Forem: Rayan Slim</title>
      <link>https://forem.com/rslim087a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rslim087a"/>
    <language>en</language>
    <item>
      <title>Installing Ingress Nginx</title>
      <dc:creator>Rayan Slim</dc:creator>
      <pubDate>Tue, 28 Jan 2025 18:03:12 +0000</pubDate>
      <link>https://forem.com/rslim087a/installing-ingress-nginx-1eaf</link>
      <guid>https://forem.com/rslim087a/installing-ingress-nginx-1eaf</guid>
      <description>&lt;p&gt;Install the NGINX Ingress Controller in your Kubernetes cluster with a single command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.2/deploy/static/provider/cloud/deploy.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>kubernetes</category>
      <category>nginx</category>
      <category>devops</category>
    </item>
    <item>
      <title>Installing Metrics Server</title>
      <dc:creator>Rayan Slim</dc:creator>
      <pubDate>Tue, 28 Jan 2025 17:59:36 +0000</pubDate>
      <link>https://forem.com/rslim087a/installing-metrics-server-238e</link>
      <guid>https://forem.com/rslim087a/installing-metrics-server-238e</guid>
      <description>&lt;h2&gt;
  
  
  Mac
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml &amp;amp;&amp;amp; kubectl patch deployment metrics-server -n kube-system --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value":"--kubelet-insecure-tls"}]'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Windows (Powershell)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml &amp;amp;&amp;amp; kubectl patch deployment metrics-server -n kube-system --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value":"--kubelet-insecure-tls"}]'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Windows (CMD)
&lt;/h2&gt;

&lt;p&gt;If you are using Windows CMD, you will need to enter these two commands separately. The first command installs all the necessary components for the Metrics Server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second command specifically patches the deployment manifest to add the --kubelet-insecure-tls flag to the Metrics Server configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl patch deployment metrics-server -n kube-system --type="json" -p="[{\"op\": \"add\", \"path\": \"/spec/template/spec/containers/0/args/-\", \"value\":\"--kubelet-insecure-tls\"}]"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Monitoring Redis with Prometheus Exporter and Grafana</title>
      <dc:creator>Rayan Slim</dc:creator>
      <pubDate>Fri, 18 Oct 2024 02:51:57 +0000</pubDate>
      <link>https://forem.com/rslim087a/monitoring-redis-with-prometheus-and-grafana-56pk</link>
      <guid>https://forem.com/rslim087a/monitoring-redis-with-prometheus-and-grafana-56pk</guid>
      <description>&lt;p&gt;A Prometheus exporter is a tool that collects metrics from a specific system and exposes them in a format that Prometheus can scrape. The Redis Prometheus Exporter specifically collects metrics from Redis databases.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ty7x2pdys9gowqrr07o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ty7x2pdys9gowqrr07o.png" alt="Redis Prometheus Exporter Metrics" width="800" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, you will deploy Redis alongside the Redis Prometheus Exporter to scrape metrics from your database. You'll then visualize these metrics using a Grafana dashboard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Clone the Repository&lt;/li&gt;
&lt;li&gt;Deploy Redis Resources&lt;/li&gt;
&lt;li&gt;Install Redis Exporter&lt;/li&gt;
&lt;li&gt;Verify Metrics&lt;/li&gt;
&lt;li&gt;Deploy Grafana Dashboard&lt;/li&gt;
&lt;li&gt;Access Grafana&lt;/li&gt;
&lt;li&gt;Cleaning Up Resources&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;This guide assumes you have already installed Helm and set up Prometheus in your Kubernetes cluster. If you haven't done this yet, please check out &lt;a href="https://kubernetestraining.io/blog/deploying-the-kube-prometheus-stack-a-comprehensive-guide-to-kubernetes-monitoring" rel="noopener noreferrer"&gt;this article on setting up Prometheus with Kubernetes&lt;/a&gt; before continuing with this guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clone the Repository
&lt;/h2&gt;

&lt;p&gt;First, clone the repository containing the necessary Redis resources, exporter configuration, and dashboard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/rslim087a/redis-prometheus-sample

&lt;span class="nb"&gt;cd &lt;/span&gt;redis-prometheus-sample
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy Redis Resources
&lt;/h2&gt;

&lt;p&gt;Create the namespace &lt;code&gt;database-monitoring&lt;/code&gt; if it doesn't already exist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl create namespace database-monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deploy the Redis resources (Secret, Service, and StatefulSet) using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; redis/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command applies all the Kubernetes manifests in the &lt;code&gt;redis/&lt;/code&gt; directory, setting up your Redis instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Redis Exporter
&lt;/h2&gt;

&lt;p&gt;Add the Prometheus Community Helm repository and update it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, install the Redis Exporter using the custom values file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;helm &lt;span class="nb"&gt;install &lt;/span&gt;redis-exporter prometheus-community/prometheus-redis-exporter &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-f&lt;/span&gt; redis-exporter/redis-exporter-values.yaml &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-n&lt;/span&gt; database-monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's examine the custom values in &lt;code&gt;redis-exporter-values.yaml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Redis Exporter Helm Values&lt;/span&gt;

&lt;span class="na"&gt;redisAddress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;redis://redis:6379&lt;/span&gt;
&lt;span class="na"&gt;auth&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;enabled&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;secret&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;redis-secret&lt;/span&gt;
    &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;REDIS_PASSWORD&lt;/span&gt;

&lt;span class="na"&gt;serviceMonitor&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;enabled&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;release&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prometheus&lt;/span&gt;

&lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ClusterIP&lt;/span&gt;
  &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;9121&lt;/span&gt;

&lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;limits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;100m&lt;/span&gt;
    &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;128Mi&lt;/span&gt;
  &lt;span class="na"&gt;requests&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;100m&lt;/span&gt;
    &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;128Mi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation of key fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;redisAddress&lt;/strong&gt;: Specifies the Redis connection details.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;auth&lt;/strong&gt;: Configures authentication for Redis.

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;enabled: true&lt;/code&gt;: Activates authentication.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;secret&lt;/code&gt;: Specifies the Kubernetes secret containing the Redis password.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;serviceMonitor&lt;/strong&gt;: Configuration for Prometheus to automatically discover and scrape metrics from the Redis exporter.

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;enabled: true&lt;/code&gt;: Activates the creation of a ServiceMonitor resource.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;labels&lt;/code&gt;: Ensures that the correct Prometheus instance picks up this ServiceMonitor.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;service&lt;/strong&gt;: Configures the Kubernetes service for the exporter.&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;resources&lt;/strong&gt;: Sets resource limits and requests for the exporter.&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Verify Metrics
&lt;/h2&gt;

&lt;p&gt;Port-forward the Redis Exporter pod and check the metrics:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl port-forward svc/redis-exporter-prometheus-redis-exporter 9121:9121 &lt;span class="nt"&gt;-n&lt;/span&gt; database-monitoring &amp;amp;

curl http://localhost:9121/metrics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After verifying, stop the port-forward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;kill&lt;/span&gt; %1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy Grafana Dashboard
&lt;/h2&gt;

&lt;p&gt;Apply the Grafana dashboard ConfigMap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; grafana &lt;span class="nt"&gt;-n&lt;/span&gt; monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a ConfigMap with the &lt;code&gt;grafana_dashboard: "1"&lt;/code&gt; label, which Grafana will automatically detect and import.&lt;/p&gt;

&lt;h2&gt;
  
  
  Access Grafana
&lt;/h2&gt;

&lt;p&gt;Port-forward the Grafana service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl port-forward svc/prometheus-grafana 3000:80 &lt;span class="nt"&gt;-n&lt;/span&gt; monitoring &amp;amp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Access Grafana at &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; using the default credentials (usually admin/prom-operator).&lt;/p&gt;

&lt;p&gt;The Redis dashboard should now be available in your Grafana instance. To find it, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log into Grafana&lt;/li&gt;
&lt;li&gt;Click on the "Dashboards" icon in the left sidebar&lt;/li&gt;
&lt;li&gt;Select "Browse"&lt;/li&gt;
&lt;li&gt;Look for a dashboard named "Redis Dashboard for Prometheus"&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpk8cvw9g9q4yh8kpiatt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpk8cvw9g9q4yh8kpiatt.png" alt="Redis Grafana Dashboard" width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This dashboard will provide detailed insights into your Redis performance and health, including metrics on connections, memory usage, operations per second, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cleaning Up Resources
&lt;/h2&gt;

&lt;p&gt;If you've deployed this setup for testing or learning purposes, you may want to clean up the resources afterwards to avoid unnecessary costs or cluster clutter.&lt;/p&gt;

&lt;p&gt;Here are the steps to remove the deployed resources:&lt;/p&gt;

&lt;p&gt;Delete the Redis Exporter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   helm uninstall redis-exporter &lt;span class="nt"&gt;-n&lt;/span&gt; database-monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you deployed Redis as part of this guide:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   kubectl delete &lt;span class="nt"&gt;-f&lt;/span&gt; redis/ &lt;span class="nt"&gt;-n&lt;/span&gt; database-monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove the Grafana dashboard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   kubectl delete &lt;span class="nt"&gt;-f&lt;/span&gt; grafana &lt;span class="nt"&gt;-n&lt;/span&gt; monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you no longer need the Prometheus Community Helm repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   helm repo remove prometheus-community
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, delete the namespace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   kubectl delete namespace database-monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Kubernetes Training
&lt;/h2&gt;

&lt;p&gt;If you found this guide helpful, check out our &lt;a href="https://kubernetestraining.io/" rel="noopener noreferrer"&gt;Kubernetes Training course&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>redis</category>
      <category>kubernetes</category>
      <category>monitoring</category>
    </item>
    <item>
      <title>Monitoring Postgres with Prometheus Exporter and Grafana</title>
      <dc:creator>Rayan Slim</dc:creator>
      <pubDate>Thu, 17 Oct 2024 02:10:28 +0000</pubDate>
      <link>https://forem.com/rslim087a/deploying-prometheus-postgres-exporter-via-helm-chart-2bn6</link>
      <guid>https://forem.com/rslim087a/deploying-prometheus-postgres-exporter-via-helm-chart-2bn6</guid>
      <description>&lt;p&gt;A Prometheus exporter is a tool that collects metrics from a specific system and exposes them in a format that Prometheus can scrape. The PostgreSQL Prometheus Exporter specifically collects metrics from PostgreSQL databases.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqjy5b7firky6ulz6i6tn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqjy5b7firky6ulz6i6tn.png" alt="Postgres Exporter Providing Metrics to Prometheus" width="800" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, you will deploy PostgreSQL alongside the PostgreSQL Prometheus Exporter to scrape metrics from your database. You'll then visualize these metrics using a Grafana dashboard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Clone the Repository&lt;/li&gt;
&lt;li&gt;Deploy PostgreSQL Resources&lt;/li&gt;
&lt;li&gt;Install PostgreSQL Exporter&lt;/li&gt;
&lt;li&gt;Verify Metrics&lt;/li&gt;
&lt;li&gt;Deploy Grafana Dashboard&lt;/li&gt;
&lt;li&gt;Access Grafana&lt;/li&gt;
&lt;li&gt;Cleaning Up Resources&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;This guide assumes you have already installed Helm and set up Prometheus in your Kubernetes cluster. If you haven't done this yet, please check out &lt;a href="https://kubernetestraining.io/blog/deploying-the-kube-prometheus-stack-a-comprehensive-guide-to-kubernetes-monitoring" rel="noopener noreferrer"&gt;this article on setting up Prometheus with Kubernetes&lt;/a&gt; before continuing with this guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clone the Repository
&lt;/h2&gt;

&lt;p&gt;First, clone the repository containing the necessary PostgreSQL resources, exporter configuration, and dashboard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/rslim087a/postgres-prometheus-sample

&lt;span class="nb"&gt;cd &lt;/span&gt;postgres-prometheus-sample
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy PostgreSQL Resources
&lt;/h2&gt;

&lt;p&gt;Create the namespace &lt;code&gt;database-monitoring&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl create namespace database-monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deploy the PostgreSQL resources (Secret, Service, and StatefulSet) using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; postgres/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command applies all the Kubernetes manifests in the &lt;code&gt;postgres/&lt;/code&gt; directory, setting up your PostgreSQL instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install PostgreSQL Exporter
&lt;/h2&gt;

&lt;p&gt;Add the Prometheus Community Helm repository and update it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, install the PostgreSQL Exporter using the custom values file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;helm &lt;span class="nb"&gt;install &lt;/span&gt;postgres-exporter prometheus-community/prometheus-postgres-exporter &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-f&lt;/span&gt; postgres-exporter/postgresql-exporter-values.yaml &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-n&lt;/span&gt; database-monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's examine the custom values in &lt;code&gt;postgresql-exporter-values.yaml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# PostgreSQL Exporter Helm Values&lt;/span&gt;

&lt;span class="c1"&gt;# Image configuration&lt;/span&gt;
&lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;tag&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;v0.12.0"&lt;/span&gt;

&lt;span class="c1"&gt;# Datasource configuration&lt;/span&gt;
&lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;datasource&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;postgresql.database-monitoring.svc.cluster.local"&lt;/span&gt;
    &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;postgres"&lt;/span&gt;
    &lt;span class="na"&gt;pass&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;password123"&lt;/span&gt;
    &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;5432"&lt;/span&gt;
    &lt;span class="na"&gt;database&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;postgres"&lt;/span&gt;
    &lt;span class="na"&gt;sslmode&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;disable"&lt;/span&gt;

  &lt;span class="c1"&gt;# Metrics collectors configuration&lt;/span&gt;
  &lt;span class="na"&gt;exporter&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;default_metrics&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;enabled&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

&lt;span class="na"&gt;serviceMonitor&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;enabled&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;interval&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;30s&lt;/span&gt;
  &lt;span class="na"&gt;scrapeTimeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;10s&lt;/span&gt;
  &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;release&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prometheus&lt;/span&gt;

&lt;span class="c1"&gt;# Explicitly set the DATA_SOURCE_NAME environment variable&lt;/span&gt;
&lt;span class="na"&gt;extraEnvs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;DATA_SOURCE_NAME&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;postgresql://postgres:password123@postgresql.database-monitoring.svc.cluster.local:5432/postgres?sslmode=disable"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation of key fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;config.datasource&lt;/strong&gt;: Specifies the PostgreSQL connection details.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;host&lt;/code&gt;: The Kubernetes service name for PostgreSQL.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;user&lt;/code&gt; and &lt;code&gt;pass&lt;/code&gt;: Database credentials.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;port&lt;/code&gt;: Default PostgreSQL port.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;database&lt;/code&gt;: The database to connect to.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sslmode&lt;/code&gt;: SSL mode for the connection.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;serviceMonitor&lt;/strong&gt;: Configuration for Prometheus to automatically discover and scrape metrics from the PostgreSQL exporter.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;enabled: true&lt;/code&gt;: Activates the creation of a ServiceMonitor resource.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;interval: 30s&lt;/code&gt;: Sets how often Prometheus should scrape metrics.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;scrapeTimeout: 10s&lt;/code&gt;: Defines the maximum time Prometheus should wait for a response.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;labels&lt;/code&gt;: Ensures that the correct Prometheus instance picks up this ServiceMonitor.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;extraEnvs&lt;/strong&gt;: Explicitly sets the &lt;code&gt;DATA_SOURCE_NAME&lt;/code&gt; environment variable, which is used by the exporter to connect to PostgreSQL.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Verify Metrics
&lt;/h2&gt;

&lt;p&gt;Port-forward the PostgreSQL Exporter service and check the metrics:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl port-forward svc/postgres-exporter-prometheus-postgres-exporter 9187:80 &lt;span class="nt"&gt;-n&lt;/span&gt; database-monitoring &amp;amp;

curl http://localhost:9187/metrics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After verifying, stop the port-forward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;kill&lt;/span&gt; %1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy Grafana Dashboard
&lt;/h2&gt;

&lt;p&gt;Apply the Grafana dashboard ConfigMap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; grafana &lt;span class="nt"&gt;-n&lt;/span&gt; monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a ConfigMap with the &lt;code&gt;grafana_dashboard: "1"&lt;/code&gt; label, which Grafana will automatically detect and import.&lt;/p&gt;

&lt;h2&gt;
  
  
  Access Grafana
&lt;/h2&gt;

&lt;p&gt;Port-forward the Grafana service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl port-forward svc/prometheus-grafana 3000:80 &lt;span class="nt"&gt;-n&lt;/span&gt; monitoring &amp;amp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Access Grafana at &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; using the default credentials (usually admin/prom-operator).&lt;/p&gt;

&lt;p&gt;The PostgreSQL dashboard should now be available in your Grafana instance. To find it, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log into Grafana&lt;/li&gt;
&lt;li&gt;Click on the "Dashboards" icon in the left sidebar&lt;/li&gt;
&lt;li&gt;Select "Browse"&lt;/li&gt;
&lt;li&gt;Look for a dashboard named "PostgreSQL Dashboard" or similar&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxxbpm5trymj5cevx7aw3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxxbpm5trymj5cevx7aw3.png" alt="Grafana Dashboard" width="800" height="554"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This dashboard will provide detailed insights into your PostgreSQL performance and health, including metrics on connections, transactions, database sizes, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cleaning Up Resources
&lt;/h2&gt;

&lt;p&gt;If you've deployed this setup for testing or learning purposes, you may want to clean up the resources afterwards to avoid unnecessary costs or cluster clutter.&lt;/p&gt;

&lt;p&gt;Here are the steps to remove the deployed resources:&lt;/p&gt;

&lt;p&gt;Delete the PostgreSQL Exporter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   helm uninstall postgres-exporter &lt;span class="nt"&gt;-n&lt;/span&gt; database-monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you deployed PostgreSQL as part of this guide:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   kubectl delete &lt;span class="nt"&gt;-f&lt;/span&gt; postgres/ &lt;span class="nt"&gt;-n&lt;/span&gt; database-monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove the Grafana dashboard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   kubectl delete &lt;span class="nt"&gt;-f&lt;/span&gt; grafana &lt;span class="nt"&gt;-n&lt;/span&gt; monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you no longer need the Prometheus Community Helm repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   helm repo remove prometheus-community
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, delete the namespace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   kubectl delete namespace database-monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Kubernetes Training
&lt;/h2&gt;

&lt;p&gt;If you found this guide helpful, check out our &lt;a href="https://kubernetestraining.io/" rel="noopener noreferrer"&gt;Kubernetes Training course&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>prometheus</category>
      <category>postgres</category>
      <category>helm</category>
    </item>
  </channel>
</rss>
