Complete the code to expose metrics endpoint in a Kubernetes pod manifest.
containers:
- name: app
image: myapp:latest
ports:
- containerPort: [1]The default port for Prometheus metrics endpoint is 9090, so the container should expose port 9090.
Complete the Prometheus scrape config to target Kubernetes pods with label 'app=web'.
- job_name: 'kubernetes-pods' kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_label_app] action: keep regex: [1]
The regex should match the label value 'web' to scrape pods labeled with app=web.
Fix the error in the Prometheus service monitor selector to match label 'release=prometheus'.
selector:
matchLabels:
release: [1]The selector must match the label 'release=prometheus' to find the correct service monitor.
Fill both blanks to create a Prometheus alert rule that fires when CPU usage is above 80%.
groups:
- name: cpu_alerts
rules:
- alert: HighCPUUsage
expr: sum(rate(container_cpu_usage_seconds_total[1][5m])) by (pod) [2] 0.8
for: 2m
labels:
severity: warning
annotations:
summary: "CPU usage is high"The expression filters metrics for the default namespace and triggers alert when usage is greater than 0.8 (80%).
Fill all three blanks to create a Prometheus scrape config for a Kubernetes service with port 'metrics' and path '/metrics'.
- job_name: 'kubernetes-service' kubernetes_sd_configs: - role: service relabel_configs: - source_labels: [__meta_kubernetes_service_label_app] action: keep regex: [1] metrics_path: [2] scheme: [3]
The job scrapes services labeled 'webapp' on the '/metrics' path using HTTP scheme.