Configuring Apache Exporter with Prometheus in Kubernetes (Minikube)
Source: Dev.to
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 --versionLab 1 – Start Kubernetes Environment
1. Start Minikube
minikube start --driver=dockerVerify the cluster:
kubectl get nodes2. Create Namespace
kubectl create namespace monitoringSet the default namespace:
kubectl config set-context --current --namespace=monitoringVerify:
kubectl get nsLab 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: 80Apply the manifest:
kubectl apply -f apache-deployment.yaml2. Expose Apache Service
Create file apache-service.yaml:
apiVersion: v1
kind: Service
metadata:
name: apache-service
spec:
selector:
app: apache
ports:
- port: 80
targetPort: 80Apply the manifest:
kubectl apply -f apache-service.yamlVerify:
kubectl get pods
kubectl get svcLab 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: 9117Apply the manifest:
kubectl apply -f apache-exporter.yaml2. 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: 9117Apply the manifest:
kubectl apply -f apache-exporter-service.yamlVerify:
kubectl get pods
kubectl get svcLab 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']Apply the manifest:
kubectl apply -f prometheus-config.yaml2. 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-configApply the manifest:
kubectl apply -f prometheus-deployment.yaml3. Expose Prometheus
kubectl expose deployment prometheus --type=NodePort --port=9090Check the service:
kubectl get svcLab 5 – Verify Exporter Metrics
1. Port‑Forward Exporter
kubectl port-forward svc/apache-exporter-service 9117:91172. Test Metrics
In another terminal:
curl http://localhost:9117/metricsYou should see metrics such as:
apache_up
apache_workers
apache_scoreboardLab 6 – Access Prometheus UI
1. Get Prometheus URL
minikube service prometheusOpen the displayed URL in a browser and explore the metrics scraped from the Apache Exporter.
2. Port‑Forward Prometheus
kubectl port-forward svc/prometheus 9090:9090Open the browser:
http://localhost:90903. Verify Target
In the Prometheus UI go to Status → Targets and ensure:
apache-exporter = UP4. Query Metrics
Try the following queries:
apache_upor
apache_workersLab 7 – Generate Load (Apache Benchmark)
Use Apache Benchmark (ab) to simulate traffic.
If ab is installed locally
ab -n 1000 -c 50 http://$(minikube service apache-service --url)/Or port‑forward Apache
kubectl port-forward svc/apache-service 8080:80Then run:
ab -n 1000 -c 50 http://localhost:8080/Observe Metrics in Prometheus
Watch the following metrics while the load test runs:
apache_workers
apache_scoreboard
apache_cpu_loadYou should see real‑time metric changes.
Lab 8 – Troubleshooting
Check pod logs
kubectl logs deployment/apache-exporter
kubectl logs deployment/prometheusVerify endpoints
kubectl get endpointsCheck Prometheus configuration
kubectl describe configmap prometheus-configLab 9 – Cleanup Environment
Delete the monitoring namespace
kubectl delete namespace monitoringStop Minikube
minikube stop(Optional) Full cleanup
minikube deleteLab 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