DEV Community

iapilgrim
iapilgrim

Posted on

Configuring Apache Exporter with Prometheus in Kubernetes (Minikube)

Lab Objectives

By completing this lab, you will:

  • Deploy Apache in Kubernetes
  • Deploy Apache Exporter
  • Deploy Prometheus
  • Configure Prometheus to scrape Apache metrics
  • Generate load and observe real-time metrics
  • Clean up the environment

Lab Prerequisites

Ensure the following are installed:

  • Docker
  • kubectl
  • Minikube
  • Git
  • curl

Verify installation:

kubectl version --client
minikube version
docker --version
Enter fullscreen mode Exit fullscreen mode

Lab 1 – Start Kubernetes Environment

1. Start Minikube

minikube start --driver=docker
Enter fullscreen mode Exit fullscreen mode

Verify cluster:

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

2. Create Namespace

kubectl create namespace monitoring
Enter fullscreen mode Exit fullscreen mode

Set default namespace:

kubectl config set-context --current --namespace=monitoring
Enter fullscreen mode Exit fullscreen mode

Verify:

kubectl get ns
Enter fullscreen mode Exit fullscreen mode

Lab 2 – Deploy Apache Web Server

1. Create Apache Deployment

Create file: apache-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: apache
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apache
  template:
    metadata:
      labels:
        app: apache
    spec:
      containers:
      - name: apache
        image: httpd:2.4
        ports:
        - containerPort: 80
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f apache-deployment.yaml
Enter fullscreen mode Exit fullscreen mode

2. Expose Apache Service

Create file: apache-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: apache-service
spec:
  selector:
    app: apache
  ports:
    - port: 80
      targetPort: 80
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f apache-service.yaml
Enter fullscreen mode Exit fullscreen mode

Verify:

kubectl get pods
kubectl get svc
Enter fullscreen mode Exit fullscreen mode

Lab 3 – Deploy Apache Exporter

We will use the official Apache Exporter image:

quay.io/prometheuscommunity/apache-exporter


1. Create Exporter Deployment

Create file: apache-exporter.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: apache-exporter
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apache-exporter
  template:
    metadata:
      labels:
        app: apache-exporter
    spec:
      containers:
      - name: apache-exporter
        image: quay.io/prometheuscommunity/apache-exporter
        args:
          - --scrape_uri=http://apache-service/server-status?auto
        ports:
        - containerPort: 9117
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f apache-exporter.yaml
Enter fullscreen mode Exit fullscreen mode

2. Create Exporter Service

Create file: apache-exporter-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: apache-exporter-service
spec:
  selector:
    app: apache-exporter
  ports:
    - port: 9117
      targetPort: 9117
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f apache-exporter-service.yaml
Enter fullscreen mode Exit fullscreen mode

Verify:

kubectl get pods
kubectl get svc
Enter fullscreen mode Exit fullscreen mode

Lab 4 – Deploy Prometheus


1. Create Prometheus ConfigMap

Create file: prometheus-config.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-config
data:
  prometheus.yml: |
    global:
      scrape_interval: 5s

    scrape_configs:
      - job_name: 'apache-exporter'
        static_configs:
          - targets: ['apache-exporter-service:9117']
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f prometheus-config.yaml
Enter fullscreen mode Exit fullscreen mode

2. Create Prometheus Deployment

Create file: prometheus-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus
  template:
    metadata:
      labels:
        app: prometheus
    spec:
      containers:
      - name: prometheus
        image: prom/prometheus
        ports:
        - containerPort: 9090
        volumeMounts:
        - name: config-volume
          mountPath: /etc/prometheus/
      volumes:
      - name: config-volume
        configMap:
          name: prometheus-config
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f prometheus-deployment.yaml
Enter fullscreen mode Exit fullscreen mode

3. Expose Prometheus

kubectl expose deployment prometheus --type=NodePort --port=9090
Enter fullscreen mode Exit fullscreen mode

Check service:

kubectl get svc
Enter fullscreen mode Exit fullscreen mode

Lab 5 – Verify Exporter Metrics


1. Port Forward Exporter

kubectl port-forward svc/apache-exporter-service 9117:9117
Enter fullscreen mode Exit fullscreen mode

Test metrics:

curl http://localhost:9117/metrics
Enter fullscreen mode Exit fullscreen mode

You should see metrics such as:

apache_up
apache_workers
apache_scoreboard
Enter fullscreen mode Exit fullscreen mode

Lab 6 – Access Prometheus UI


1. Get Prometheus URL

minikube service prometheus
Enter fullscreen mode Exit fullscreen mode

Or port-forward:

kubectl port-forward svc/prometheus 9090:9090
Enter fullscreen mode Exit fullscreen mode

Open browser:

http://localhost:9090
Enter fullscreen mode Exit fullscreen mode

2. Verify Target

In Prometheus UI:

Status → Targets

Ensure:

apache-exporter = UP
Enter fullscreen mode Exit fullscreen mode

3. Query Metrics

Try:

apache_up
Enter fullscreen mode Exit fullscreen mode

Or:

apache_workers
Enter fullscreen mode Exit fullscreen mode

Lab 7 – Generate Load (Apache Benchmark)

Use Apache Benchmark (ab) to simulate traffic.

If installed locally:

ab -n 1000 -c 50 http://$(minikube service apache-service --url)/
Enter fullscreen mode Exit fullscreen mode

Or port-forward Apache:

kubectl port-forward svc/apache-service 8080:80
Enter fullscreen mode Exit fullscreen mode

Then:

ab -n 1000 -c 50 http://localhost:8080/
Enter fullscreen mode Exit fullscreen mode

Observe Metrics in Prometheus

Watch:

apache_workers
apache_scoreboard
apache_cpu_load
Enter fullscreen mode Exit fullscreen mode

You should see real-time metric changes.


Lab 8 – Troubleshooting

Check pod logs:

kubectl logs deployment/apache-exporter
kubectl logs deployment/prometheus
Enter fullscreen mode Exit fullscreen mode

Verify endpoints:

kubectl get endpoints
Enter fullscreen mode Exit fullscreen mode

Check configuration:

kubectl describe configmap prometheus-config
Enter fullscreen mode Exit fullscreen mode

Lab 9 – Cleanup Environment

Delete namespace:

kubectl delete namespace monitoring
Enter fullscreen mode Exit fullscreen mode

Stop Minikube:

minikube stop
Enter fullscreen mode Exit fullscreen mode

Optional full cleanup:

minikube delete
Enter fullscreen mode Exit fullscreen mode

Lab Summary

You have successfully:

  • Deployed Apache in Kubernetes
  • Deployed Apache Exporter
  • Configured Prometheus
  • Verified metric scraping
  • Generated load and observed real-time metrics
  • Cleaned up the environment

Top comments (0)