0
0
Kubernetesdevops~30 mins

Prometheus for metrics collection in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Prometheus for Metrics Collection in Kubernetes
📖 Scenario: You are managing a Kubernetes cluster and want to monitor the health and performance of your applications. Prometheus is a popular tool that collects metrics from your cluster and applications to help you understand their behavior.In this project, you will set up a basic Prometheus configuration to scrape metrics from a sample application running in your Kubernetes cluster.
🎯 Goal: Build a simple Prometheus setup that collects metrics from a Kubernetes pod running a sample application. You will create the necessary Kubernetes resources and Prometheus configuration to enable metrics scraping.
📋 What You'll Learn
Create a Kubernetes ConfigMap with Prometheus scrape configuration
Deploy a sample application pod exposing metrics on port 8080
Create a Prometheus Pod that uses the ConfigMap to scrape metrics
Verify Prometheus successfully scrapes metrics from the sample application
💡 Why This Matters
🌍 Real World
Prometheus is widely used in real Kubernetes environments to monitor applications and infrastructure by collecting metrics automatically.
💼 Career
Understanding how to configure Prometheus in Kubernetes is a key skill for DevOps engineers and site reliability engineers to ensure system health and performance.
Progress0 / 4 steps
1
Create a sample application pod exposing metrics
Write a Kubernetes Pod manifest named sample-app-pod.yaml that creates a pod called sample-app in the default namespace. The pod should run the image prom/prometheus-example-app and expose container port 8080.
Kubernetes
Need a hint?

Use kind: Pod, set metadata.name to sample-app, and specify the container image prom/prometheus-example-app. Expose port 8080 in containerPort.

2
Create a Prometheus scrape configuration ConfigMap
Create a Kubernetes ConfigMap manifest named prometheus-config.yaml with the name prometheus-config in the default namespace. The ConfigMap should contain a key prometheus.yml with the following scrape config YAML content exactly:
scrape_configs:
  - job_name: 'sample-app'
    static_configs:
      - targets: ['sample-app:8080']
Kubernetes
Need a hint?

Use kind: ConfigMap with metadata.name: prometheus-config. The key prometheus.yml should contain the scrape_configs YAML exactly as shown.

3
Deploy a Prometheus pod using the ConfigMap
Add a Kubernetes Pod manifest named prometheus-pod.yaml to your existing YAML that creates a pod called prometheus in the default namespace. The pod should run the image prom/prometheus and mount the ConfigMap prometheus-config at /etc/prometheus/ as a volume. The container should use the command --config.file=/etc/prometheus/prometheus.yml to load the config.
Kubernetes
Need a hint?

Create a pod named prometheus using image prom/prometheus. Mount the ConfigMap prometheus-config at /etc/prometheus/ and pass --config.file=/etc/prometheus/prometheus.yml as an argument.

4
Verify Prometheus scrapes metrics from sample app
Run the command kubectl logs prometheus to check the Prometheus pod logs. Confirm that the logs contain the text Scrape succeeded indicating metrics were collected from sample-app. Write a print statement in Python that outputs exactly Scrape succeeded to simulate this verification.
Kubernetes
Need a hint?

Use print("Scrape succeeded") exactly to simulate checking Prometheus logs.