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
Lab 1 – Start Kubernetes Environment
1. Start Minikube
minikube start --driver=docker
Verify cluster:
kubectl get nodes
2. Create Namespace
kubectl create namespace monitoring
Set default namespace:
kubectl config set-context --current --namespace=monitoring
Verify:
kubectl get ns
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
Apply:
kubectl apply -f apache-deployment.yaml
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
Apply:
kubectl apply -f apache-service.yaml
Verify:
kubectl get pods
kubectl get svc
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
Apply:
kubectl apply -f apache-exporter.yaml
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
Apply:
kubectl apply -f apache-exporter-service.yaml
Verify:
kubectl get pods
kubectl get svc
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']
Apply:
kubectl apply -f prometheus-config.yaml
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
Apply:
kubectl apply -f prometheus-deployment.yaml
3. Expose Prometheus
kubectl expose deployment prometheus --type=NodePort --port=9090
Check service:
kubectl get svc
Lab 5 – Verify Exporter Metrics
1. Port Forward Exporter
kubectl port-forward svc/apache-exporter-service 9117:9117
Test metrics:
curl http://localhost:9117/metrics
You should see metrics such as:
apache_up
apache_workers
apache_scoreboard
Lab 6 – Access Prometheus UI
1. Get Prometheus URL
minikube service prometheus
Or port-forward:
kubectl port-forward svc/prometheus 9090:9090
Open browser:
http://localhost:9090
2. Verify Target
In Prometheus UI:
Status → Targets
Ensure:
apache-exporter = UP
3. Query Metrics
Try:
apache_up
Or:
apache_workers
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)/
Or port-forward Apache:
kubectl port-forward svc/apache-service 8080:80
Then:
ab -n 1000 -c 50 http://localhost:8080/
Observe Metrics in Prometheus
Watch:
apache_workers
apache_scoreboard
apache_cpu_load
You should see real-time metric changes.
Lab 8 – Troubleshooting
Check pod logs:
kubectl logs deployment/apache-exporter
kubectl logs deployment/prometheus
Verify endpoints:
kubectl get endpoints
Check configuration:
kubectl describe configmap prometheus-config
Lab 9 – Cleanup Environment
Delete namespace:
kubectl delete namespace monitoring
Stop Minikube:
minikube stop
Optional full cleanup:
minikube delete
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)