0
0
Kubernetesdevops~10 mins

Prometheus for metrics collection in Kubernetes - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to expose metrics endpoint in a Kubernetes pod manifest.

Kubernetes
containers:
- name: app
  image: myapp:latest
  ports:
  - containerPort: [1]
Drag options to blanks, or click blank then click option'
A8080
B443
C80
D9090
Attempts:
3 left
💡 Hint
Common Mistakes
Using HTTP port 80 instead of Prometheus metrics port 9090.
Confusing HTTPS port 443 with metrics port.
2fill in blank
medium

Complete the Prometheus scrape config to target Kubernetes pods with label 'app=web'.

Kubernetes
- job_name: 'kubernetes-pods'
  kubernetes_sd_configs:
  - role: pod
  relabel_configs:
  - source_labels: [__meta_kubernetes_pod_label_app]
    action: keep
    regex: [1]
Drag options to blanks, or click blank then click option'
Adatabase
Bweb
Ccache
Dapi
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong label value in regex causing no pods to be scraped.
Confusing label keys with label values.
3fill in blank
hard

Fix the error in the Prometheus service monitor selector to match label 'release=prometheus'.

Kubernetes
selector:
  matchLabels:
    release: [1]
Drag options to blanks, or click blank then click option'
Amonitoring
Bkube-prometheus
Cprometheus
Ddefault
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect release name causing selector to fail.
Typos in label values.
4fill in blank
hard

Fill both blanks to create a Prometheus alert rule that fires when CPU usage is above 80%.

Kubernetes
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"
Drag options to blanks, or click blank then click option'
Anamespace="default"
Bnamespace="kube-system"
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong namespace filter causing no data.
Using '<' instead of '>' causing alert to never fire.
5fill in blank
hard

Fill all three blanks to create a Prometheus scrape config for a Kubernetes service with port 'metrics' and path '/metrics'.

Kubernetes
- 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]
Drag options to blanks, or click blank then click option'
Awebapp
B/metrics
Chttp
Dhttps
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong label value causing no targets.
Wrong metrics path or scheme causing scrape failures.