Day 2: Setting Up Monitoring with Prometheus on EKS | Basics of Prometheus

Certainly! Here's an updated section with the prerequisites before setting up Prometheus on Windows.


Prerequisites for Installing Prometheus on Windows

Before setting up Prometheus on Windows, ensure that your environment is properly configured with the following prerequisites:

  1. Install Docker Desktop:

    • Docker is essential if you are using containerized applications or want to run Prometheus in a container. Download and install Docker Desktop from the official Docker website.

    • Ensure Docker is running and the necessary resources (CPU, RAM, etc.) are allocated in the Docker settings.

  2. Enable WSL (Windows Subsystem for Linux):

    • For an optimal experience, especially if you want to work with Kubernetes, you may need to enable WSL 2 and install a Linux distribution (like Ubuntu) from the Microsoft Store.

    • Steps to Enable WSL:

      1. Open PowerShell as an administrator and run:

         wsl --install
        
      2. Restart your computer once the installation is complete.

    • For more details on setting up WSL, visit the WSL documentation.

  3. Install kubectl:

    • kubectl is the command-line tool for interacting with Kubernetes clusters. Download and install it from the official Kubernetes website.

    • Add kubectl to your PATH: Ensure kubectl is available in your command line by adding its path to your system environment variables.

  4. Install Helm:

    • Helm is a package manager for Kubernetes, making it easy to manage applications like Prometheus. Download and install Helm from the Helm website.

    • Verify the installation:

        helm version
      
    • Add Helm to your PATH if needed.

  5. Enable Hyper-V (Optional):

    • If you are running virtualized environments, you may need to enable Hyper-V on your Windows machine. This can be done through the Windows Features settings.
  6. Set Up Kubernetes:

    • If you plan to work with a local Kubernetes cluster, consider using Minikube or a managed cloud solution like Amazon EKS. Follow the instructions specific to your choice:

      • Minikube: Download from Minikube’s site.

      • EKS Setup: Refer to AWS documentation for detailed guidance.

  7. Install Git (Optional):

    • If you plan to clone configuration files or version control your setup scripts, make sure Git is installed on your machine. Download it from Git's website.

These prerequisites will ensure a smooth installation and configuration process, whether you are running Prometheus directly on Windows or using containers in a Kubernetes environment. Once everything is set up, proceed with the installation and configuration steps.


Effective monitoring is a cornerstone of maintaining reliable and performant applications. Prometheus, an open-source systems monitoring and alerting toolkit, has become a favorite among DevOps engineers for its robust features and seamless integration with cloud-native environments like Kubernetes. In this article, we'll cover setting up Prometheus in an Amazon EKS (Elastic Kubernetes Service) cluster and integrating it with Grafana for visualization.

What is Prometheus?

Prometheus is designed for collecting and querying metrics data efficiently. It uses a time-series database, with each metric stored alongside timestamps and labels, which offer insights into performance and behavior. Here's a brief overview of the Prometheus architecture:

  1. Prometheus Server: The core component responsible for scraping and storing metrics from configured targets.

  2. Exporters: Components that expose metrics from services in a Prometheus-compatible format.

  3. Alertmanager: Manages alerts, deduplication, and routing.

  4. Data Storage: Prometheus uses a custom time-series database optimized for high performance.

Why Use Prometheus in Kubernetes?

Kubernetes is highly dynamic, with pods and services frequently changing states. Prometheus efficiently handles such environments through service discovery mechanisms, making it a natural fit for Kubernetes monitoring.


Step-by-Step Guide to Setting Up Prometheus in an EKS Cluster

Prerequisites

  • An active EKS cluster.

  • kubectl configured to access the cluster.

  • Helm package manager installed.


Step 1: Setup and Configuration of Prometheus in EKS

  1. Add the Helm Repository: First, add the kube-prometheus-stack Helm chart, which bundles Prometheus, Grafana, and Alertmanager for ease of setup:

     helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
     helm repo update
    
  2. Install kube-Prometheus-stack: Install the kube-prometheus-stack into the EKS cluster:

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

    This command deploys Prometheus, Grafana, and other monitoring components in the monitoring namespace.

  3. Verify the Installation: Ensure that the pods are running:

     kubectl get pods -n monitoring
    

    You should see all Prometheus, Grafana, and Alertmanager pods in a Running state.


Step 2: Accessing Grafana for Visualization

  1. Get the Grafana Admin Password: The default password is stored as a Kubernetes secret:

     kubectl get secret -n monitoring prometheus-stack-grafana -o jsonpath="{.data.admin-password}" | base64 --decode
    
  2. Port Forward to Access Grafana: To view Grafana in your browser, use:

     kubectl port-forward -n monitoring svc/prometheus-stack-grafana 3000:80
    

    Now, visit http://localhost:3000 and log in with admin as the username and the retrieved password.


Step 3: Basic Prometheus Queries for Monitoring

Prometheus uses its own query language called PromQL. Here are some basic queries to get you started:

  • Check Memory Usage:

      node_memory_Active_bytes
    
  • CPU Usage Across All Nodes:

      sum(rate(node_cpu_seconds_total{mode!="idle"}[5m]))
    
  • Number of Running Pods:

      count(kube_pod_info)
    

Integrating Prometheus with Grafana

  1. Add Prometheus as a Data Source in Grafana:

  2. Create Dashboards for Visualization:

    • Import pre-built dashboards or create custom ones to monitor the metrics relevant to your infrastructure.

Key Takeaways

  • You now have a functional Prometheus and Grafana setup in your EKS cluster.

  • You learned how to install and configure Prometheus on Kubernetes using Helm.

  • You explored basic PromQL queries to start monitoring critical metrics.

By mastering these steps, you'll gain insights into your applications' performance, helping you proactively address issues. In the next sessions, we'll dive deeper into customizing alerts and fine-tuning your monitoring setup.

0
Subscribe to my newsletter

Read articles from Ali Hassan Khan Yousafzai directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ali Hassan Khan Yousafzai
Ali Hassan Khan Yousafzai

As a DevOps Engineer at Polymer SaaS DLP, I orchestrate seamless deployments for optimal performance, leveraging cloud-native technologies and infrastructure as code (IaC) tools. I have implemented CI/CD pipelines, monitoring and logging solutions, and automated testing frameworks to streamline development and enhance scalability. I have also contributed to resolving complex issues, optimizing resource utilization, and ensuring security and compliance standards.