kubernetes and prometheus

29
Prometheus & Kubernetes Lessons Learnt Tom Wilkie, Weaveworks 8th July 2016

Upload: weaveworks

Post on 12-Jan-2017

1.729 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Kubernetes and Prometheus

Prometheus & Kubernetes

Lessons Learnt

Tom Wilkie, Weaveworks 8th July 2016

Page 2: Kubernetes and Prometheus

Deploying on Kubernetes

Service-oriented monitoring

Alerting on differences

Page 3: Kubernetes and Prometheus

Deploying on Kubernetes

Page 4: Kubernetes and Prometheus

Not a new topic!

“Monitoring Kubernetes with Prometheus” - Brian Brazil

“Prometheus and Kubernetes up and running” - Fabian Reinartz

Even example config upstream

Page 5: Kubernetes and Prometheus

Kubernetes concepts

Pod

Container

Container

Container

Pod

Container

Container

Container

Pod

Container

Container

Container

Replication Controller / DeploymentService

Page 6: Kubernetes and Prometheus

Monitoring Pod

Promtheus Container

AlertManager Container

Grafana Container

Page 7: Kubernetes and Prometheus

Monitoring Pod

Prometheus Container

AlertManager Container

Grafana Pod

Grafana Container

Prometheus ConfigMap

Grafana ConfigMap

Page 8: Kubernetes and Prometheus

Grafana Pod

Grafana Container

Grafana ConfigMap

Page 9: Kubernetes and Prometheus

Grafana Pod

Grafana Container

SOCKS Proxy

SOCKS Proxy

Page 10: Kubernetes and Prometheus

Grafana Pod

Grafana Container

AuthFE

AuthFE Container

Page 11: Kubernetes and Prometheus

Demo

Page 12: Kubernetes and Prometheus

Deploying on Kubernetes

Page 13: Kubernetes and Prometheus

Service-oriented monitoring

Page 14: Kubernetes and Prometheus

When configuring Prometheus: • map Kubernetes Services to Prometheus Jobs • map Kubernetes Pods to Prometheus Instances

Using relabelling:

relabel_configs:

- source_labels: [__meta_kubernetes_service_namespace]

action: replace

regex: ^(.+)$

target_label: namespace

replacement: $1

- source_labels: [__meta_kubernetes_service_name]

regex: ^(.+)$

target_label: job

replacement: $1

Page 15: Kubernetes and Prometheus
Page 16: Kubernetes and Prometheus

If you get this

- source_labels: [__meta_kubernetes_role]

action: keep

regex: endpoint

Page 17: Kubernetes and Prometheus

But not all my services export metrics!

- source_labels:[__meta_kubernetes_service_annotation_prometheus_io_scrape]

action: drop

regex: false

And add this to your service definition:

apiVersion: v1

kind: Service

metadata:

annotations:

prometheus.io.scrape: "false"

Page 18: Kubernetes and Prometheus

What about exporters?

Memcached Pod

memcached Container

memcached-exporter Container

Page 19: Kubernetes and Prometheus

What about exporters?

- source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]

action: replace

target_label: __address__

regex: ^(.+)(?::\d+);(\d+)$

replacement: $1:$2

And add this to your service definition:

apiVersion: v1

kind: Service

metadata:

annotations:

prometheus.io.port: "9150"

Page 20: Kubernetes and Prometheus

Service-oriented monitoring

Page 21: Kubernetes and Prometheus

Alerting on differences

Page 22: Kubernetes and Prometheus

What I really came here to talk about…

Page 23: Kubernetes and Prometheus

Kubernetes best-practice is to version control your

config.

Whats running vs whats checked in with drift unless we monitor it.

Page 24: Kubernetes and Prometheus

$ ./kubediff Usage: kubediff [options] <dir/file>...

Compare yaml files in <dir> to running state in kubernetes and print the differences. This is useful to ensure you have applied all your changes to the appropriate environment.

https://github.com/weaveworks/kubediff

Page 25: Kubernetes and Prometheus

Run it as a service:

This will export the exit code as a Prometheus metric

Page 26: Kubernetes and Prometheus

Get alerts from it:

https://github.com/weaveworks/kubediff

ALERT Kubediff IF max(command_exit_code{job="kubediff"}) != 0 FOR 2h

Page 27: Kubernetes and Prometheus

Alerting on differences

Page 28: Kubernetes and Prometheus

Deploying on Kubernetes

Service-oriented monitoring

Alerting on differences

Page 29: Kubernetes and Prometheus

Thanks! Questions? @tom_wilkie