Top Banner
Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22
37

Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

May 25, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Kubernetes 導入 Prometheus

Kevin K Chang 張凱傑

2016 / 9 / 22

Page 2: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 2

Kubernetes

Page 3: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 3

Kubernetes

• Pod / Service / RC

• Resource Management

• Replica control

• Rolling update

Page 4: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 4

Dynamic Pod IP Dynamic Pod number

Metric retrieve

Page 5: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 5

Prometheus

Page 6: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 6

W hy Prometheus?

• All in one

• Rich metrics

• Powerful QL

• Easy to integrate

Page 7: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 7

All in One Solution

Storage

Service discovery

Metric collect Metric

Query

Alert

Page 8: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 8

Prometheus Workflow

Service

Discovery

Metrics

Pull

Alert

Dashboard

Alert

Dispatching

Page 9: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 9

Enhanced Workflow

Service

Discovery

Metrics

Pull

Alert

Dashboard

Alert

Dispatching

Auto Scale

Page 10: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 10

1. Service Discovery

Page 11: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 11

1. Service Discovery

• Support multiple Discovery method

– DNS / File / Consul / Azure / EC2 / Kubernetes /Marathon / nerve / serverset

• Easy to use and integrate

Page 12: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 13

Target Endpoints

Target Labels

Page 13: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 14

2. Metrics Pull

Page 14: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 15

Exporter

Exporter • Metric retrieval logic with HTTP API

Metric name label value

Page 15: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 16

Leverage Existed Exporters

Page 16: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 17

Kubernetes API server/ kubelet Supported

Page 17: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 18

Expose to Prometheus

Exporter

Page 18: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 19

3. Dashboard Alert

Page 19: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 20

Dashboard - Grafana

• Generate beautiful / human-readable metric dashboard

• Insight your metrics

• Recommended from Prometheus

Page 20: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 21

Before After

Page 21: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 22

Page 22: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 23

Page 23: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 24

Alert Format

ALERT <alert name>

IF <expression>

[ FOR <duration> ]

[ LABELS <label set> ]

[ ANNOTATIONS <label set> ]

Page 24: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 25

Create Alert rule for capacity ALERT NGINX_LOAD_HIGH

IF sum(rate(nginx_connections_processed_total{stage="handled"}[1m])) / ((count(nginx_connections_processed_total{stage="handled"})) * 100) > 1

FOR 30s

LABELS {pager="webhook", service="nginx", severity="critical", svc="nginx"}

ANNOTATIONS {

description="{

\"rc\":\"nginx-test-rc\",

\"ns\":\"default\",

\"min\":2,

\"max\":10,

\"scale\":\“out\"}",

summary="nginx load high"}

Page 25: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 26

4. Alert Dispatching

Page 26: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 27

Alert Dispatching

• Support routing by label

• Support Email / HipChat / Slack / PagerDuty / Pushover / OpenGenie / Webhook

Page 27: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 28

Setup Alert Routing

routes:

...

- match:

pager: webhook

receiver: webhook-k8s

receivers:

- name: "webhook-k8s"

webhook_configs:

- url: 'http://k8s-webhook-svc/webhooks/prom'

send_resolved: true

Page 28: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 29

5. Auto Scale

Page 29: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 30

Auto Scale Kubernetes

• Alert -> Webhook -> K8S

• Scale pod / minion

Page 30: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 31

Send to Custom Webhook

Let’s see demo video

Page 31: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 33

Conclusions

• Easy to integrate

• Great metrics system

Page 32: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 34

Tips sharing

Page 33: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 35

Separate ops / service minions

Ops minion / node service minion

Prometheus

Grafana

Alertmanager

Pushgateway API

Worker

MQ

Elasticsearch

Cassandra

MySQL

External node

Page 34: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 36

Group your metrics 1/2

node_cpu{alias="172.31.23.64",cpu="cpu1",instance="172.31.23.64:9100",job="node",mode="system“}

cassandra_cache_hitrate{alias="172.31.23.64",cache="RowCache",instance="172.31.23.64:7070",job="cassandra"}

node_cpu{cpu="cpu1",instance="172.31.23.64:9100",job="node",mode="system“}

cassandra_cache_hitrate{cache="RowCache",instance="172.31.23.64:7070",job="cassandra"}

Add useful label for filtering Ex: node=“cassandra” BUT DON’T OVER USE

Page 35: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 37

Group your metrics 2/2

apiVersion: v1

kind: Service

metadata:

annotations:

prometheus.io/scrape: "true"

prometheus.io/port: "9100"

prometheus.io/path: "/metrics"

name: prometheus-node-exporter

labels:

node: cassandra

Page 36: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 40

Thank you

Page 37: Kubernetes 導入 Prometheus - Apistek...Kubernetes 導入 Prometheus Kevin K Chang 張凱傑 2016 / 9 / 22 . 2 Copyright 2016 Trend Micro Inc. Kubernetes . 3 Copyright 2016 Trend

Copyright 2016 Trend Micro Inc. 41

References

• Prometheus Kubernetes configuration

– https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml

• Webhook for Kubernetes scale example

– https://github.com/kaija/k8s-scale-webhook