SlideShare a Scribd company logo
David Chang
DevOps@mithril
ELK 監測 Kubernetes 應用
第一次ELK就上手
https://github.com/chechiachang/elk-kubernetes
What is ELK Stack?
3 open source projects
● Kibana
分析和可視化平台
● Elasticsearch
分布式全文搜索引擎
● Logstash
數據收集和日誌解析引擎
● Beats
lightweight data shippers
Elk for applications on k8s
Why ELK
為何要收 Log / Metrics?放DB 不好嗎?
Why Collect log
● Why log exists?
● Debug with your log
● Debug ahead of your error
ML?
System logs
● System logs
SSH access, events, stress…
● Access log (Nginx)
Logs
Diary of your application
Metrics
● System Metrics
CPU / Memory / storage / IO
● App Metrics
resource usage /
performance
Metrics
How well your apps are
Kubernetes
Things always get a little complicated on Kubernetes ;)
Kubernetes logging
● https://kubernetes.io/docs/co
ncepts/cluster-administration
/logging
● Log of container runtime
● Cluster-level logging
● Make sure your k8s store log
One Pod, kubectl logs :)
● App generates log
● Container runtime strout
● Log file visible on Node
● Apply a collector
● Mount log
1000 pods, have fun :P
● Hard to locate error pod / log
● Terminated pod don’t log
● microservices, components
● Third party services, nginx,
kafka, redis…
● Multi-clusters
Alternatives(?) to ELK
● Datadog
● Stackdriver for GCP
● Prometheus / Grafana
● Fluentd
● 弄清楚你的需求
第一次ELK就上手
雷都踩過了...
● Have a Elasticsearch + Kibana
● Config / Deploy beats to your
apps / nodes
● Create index pattern on
kibana
● Add visualization
Quick Start ELK
Have a Elasticsearch + Kibana
● Elastic Cloud (Saas)
No deployment,
configuration, or cluster
maitainance
● Self-hosted open source ELK
no authentication
Create Deployment
Elastic Cloud
Elasticsearch cluster + kibana node
Get id and auth
Deploy beats
Elk for applications on k8s
Beats config
● Elasticsearch authentication
● Where’s log
● Use module:
system, nginx, docker
● beat-side data digestion
Logstash pipeline (for nginx)
● How to parse nginx log
● pattern match
● Reduce raw data
● Normalize log to basic type
● Minimize index size
● Tidying up your log
35.185.145.221 - [35.185.145.221] - - [26/Dec/2018:10:44:22
+0000] "GET
/modules/actions/api?timestamp=1545821062&hash=e63ffc17319baa
5524a7ad10dbb3c4be822c4e519d88efdae511116498d6c9e2 HTTP/1.1"
200 3 "-" "python-requests/2.18.4" 416 0.013
[default-app-server-80] 10.24.10.14:8080 3 0.014 200
67ce5290d19e39b2a6b614a617a1cd98
beat logstash Elasticsearch
Kinana
Chart Data Source Info
ELKB for complex data
Logstash pipeline:
inputs → filters → outputs
https://raw.githubusercontent.com/chechiachang/elk-kubernetes/master/logstash/
pipelines-configmap.yaml
input {
beats {
# The lisening port of logstash
port => 5044
host => "0.0.0.0"
}
}
filter {
# Nginx-ingress controller example
if [kubernetes][container][name] == "nginx-ingress-controller" {
……
}
} # filter
output {
elasticsearch {
hosts => ["https://${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}"]
user => "${ELASTICSEARCH_USERNAME}"
password => "${ELASTICSEARCH_PASSWORD}"
index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
manage_template => false
}
}
filter { # Nginx-ingress controller example
if [kubernetes][container][name] == "nginx-ingress-controller" {
# Parse message with grok
grok {
match => { "message" => “...” }
#remove_field => "message"}
mutate {
add_field => { "read_timestamp" => "%{@timestamp}" }}
date {
match => [ "[nginx][access][time]", "dd/MMM/YYYY:H:m:s Z" ]
remove_field => "[nginx][access][time]"
}
kv {
source => "[nginx][access][url_params]"
field_split => "&"
}
useragent {
source => "[nginx][access][agent]"
target => "[nginx][access][user_agent]"
remove_field => "[nginx][access][agent]"
}
geoip {
source => "[nginx][access][remote_ip]"
target => "[nginx][access][geoip]"
#fields => ["country_name","city_name","real_region_name","latitude","longitude","ip","location"]
}
35.185.145.221 - [35.185.145.221] - - [26/Dec/2018:10:44:22 +0000] "GET
/modules/actions/api?timestamp=1545821062&hash=e63ffc17319baa5524a7ad10dbb3c4b
e822c4e519d88efdae511116498d6c9e2 HTTP/1.1" 200 3 "-" "python-requests/2.18.4"
416 0.013 [default-app-server-80] 10.24.10.14:8080 3 0.014 200
67ce5290d19e39b2a6b614a617a1cd98
%{IPORHOST:[ nginx][access][remote_ip]} - [%{IPORHOST:[nginx ][access][remote_ip_list ]}] -
%{DATA:[nginx][access][user_name]} [%{HTTPDATE:[nginx ][access][time_local]}]
"%{WORD:[nginx][access][method]} %{DATA:[ nginx][access][url]}
HTTP/%{NUMBER:[ nginx][access][http_version ]}" %{NUMBER:[ nginx][access][response_code ]}
%{NUMBER:[nginx][access][body_sent][bytes]} "%{DATA:[ nginx][access][referrer]}"
"%{DATA:[nginx][access][user_agent_original ]}" %{NUMBER:[ nginx][access][request_length ]}
%{NUMBER:[nginx][access][request_time ]} [%{DATA:[nginx ][access][proxy_upstream_name ]}]
%{DATA:[nginx][access][upstream_addr ]} %{NUMBER:[ nginx][access][upstream_response_length ]}
%{NUMBER:[nginx][access][upstream_response_time ]} %{NUMBER:[ nginx][access][upstream_status ]}
%{DATA:[nginx][access][req_id]}
Elk for applications on k8s
Real Use Cases
System Metrics
System Metric Dashboard
Kibana Nginx Dashboard
Log 放 DB 不好嗎?
● 資料讀取的方便性
● Data Define Language
● 分析工具
● Elastic Data Storage
● full-text search
● visualization
導入ELK心路歷程
● Datadog, Stackdriver,...
● 訂立需求
● 收集所有資料
● 釐清需求 <-> 整理資料
● 穩定需求與pipeline
● 產生視覺化報表
● 提供資料 / 告警給團隊
ELK pros & cons
● lightweight collector
● powerful data pipeline
● elastic data write
● complex search and query
● Analysis tools & Visulization
● Storage consuming
● Not for permanant
Q&A

More Related Content

PDF
How to Prepare for CKA Exam
PDF
CNTUG x SDN Meetup #33 Talk 1: 從 Cilium 認識 cgroup ebpf - Ruian
PDF
Load Balancing 101
PDF
Introduction of eBPF - 時下最夯的Linux Technology
PDF
K8s storage-glusterfs-20180210
PDF
Improving Network Application Performance using Load Aware Libeventdev
PDF
Kubernetes on the Edge / 在邊緣的K8S
PPTX
DCUS17 : Docker networking deep dive
How to Prepare for CKA Exam
CNTUG x SDN Meetup #33 Talk 1: 從 Cilium 認識 cgroup ebpf - Ruian
Load Balancing 101
Introduction of eBPF - 時下最夯的Linux Technology
K8s storage-glusterfs-20180210
Improving Network Application Performance using Load Aware Libeventdev
Kubernetes on the Edge / 在邊緣的K8S
DCUS17 : Docker networking deep dive

What's hot (20)

PPTX
Service mesh from linkerd to conduit (cloud native taiwan meetup)
PDF
IP Virtual Server(IPVS) 101
PDF
Network plugins for kubernetes
PDF
Running Legacy Applications with Containers
PDF
Scale Kubernetes to support 50000 services
PDF
Testing kubernetes and_open_shift_at_scale_20170209
PDF
Kubernetes 架構與虛擬化之差異
PPTX
High performace network of Cloud Native Taiwan User Group
PDF
Load Balancing in the Cloud using Nginx & Kubernetes
PDF
Opensource approach to design and deployment of Microservices based VNF
PPTX
How OpenStack is Built - Anton Weiss - OpenStack Day Israel 2016
PDF
Kubernetes Ingress 101
PDF
OSDC 2018 | Monitoring Kubernetes at Scale by Monica Sarbu
PDF
Deploying OpenDaylight and OpenStack at Ease
PDF
Leveraging the Power of containerd Events - Evan Hazlett
PPTX
How to Achieve Canary Deployment on Kubernetes
PPTX
Integrate Kubernetes into CORD(Central Office Re-architected as a Datacenter)
PDF
Scaling docker with kubernetes
PPTX
[20200720]cloud native develoment - Nelson Lin
PDF
Unikernels: the rise of the library hypervisor in MirageOS
Service mesh from linkerd to conduit (cloud native taiwan meetup)
IP Virtual Server(IPVS) 101
Network plugins for kubernetes
Running Legacy Applications with Containers
Scale Kubernetes to support 50000 services
Testing kubernetes and_open_shift_at_scale_20170209
Kubernetes 架構與虛擬化之差異
High performace network of Cloud Native Taiwan User Group
Load Balancing in the Cloud using Nginx & Kubernetes
Opensource approach to design and deployment of Microservices based VNF
How OpenStack is Built - Anton Weiss - OpenStack Day Israel 2016
Kubernetes Ingress 101
OSDC 2018 | Monitoring Kubernetes at Scale by Monica Sarbu
Deploying OpenDaylight and OpenStack at Ease
Leveraging the Power of containerd Events - Evan Hazlett
How to Achieve Canary Deployment on Kubernetes
Integrate Kubernetes into CORD(Central Office Re-architected as a Datacenter)
Scaling docker with kubernetes
[20200720]cloud native develoment - Nelson Lin
Unikernels: the rise of the library hypervisor in MirageOS
Ad

Similar to Elk for applications on k8s (20)

PDF
K8s monitoring with elk
PPTX
ELK Ruminating on Logs (Zendcon 2016)
PDF
elk_stack_alexander_szalonnas
PPTX
Introduction to ELK
PDF
ELK stack introduction
PDF
2015 03-16-elk at-bsides
PPTX
Elk ruminating on logs
PDF
Application Logging With The ELK Stack
PDF
"How about no grep and zabbix?". ELK based alerts and metrics.
PDF
DIY Netflow Data Analytic with ELK Stack by CL Lee
PPTX
MySQL Audit using Percona audit plugin and ELK
PPT
Learn ELK in docker
PDF
ELK: a log management framework
PDF
The elastic stack on docker
PDF
How to improve ELK log pipeline performance
PDF
Javantura v3 - ELK – Big Data for DevOps – Maarten Mulders
PDF
Elks for analysing performance test results - Helsinki QA meetup
PPTX
Mulesoft with ELK (Elastic Search, Log stash, Kibana)
PPTX
CKA_1st.pptx
PDF
Log analysis with the elk stack
K8s monitoring with elk
ELK Ruminating on Logs (Zendcon 2016)
elk_stack_alexander_szalonnas
Introduction to ELK
ELK stack introduction
2015 03-16-elk at-bsides
Elk ruminating on logs
Application Logging With The ELK Stack
"How about no grep and zabbix?". ELK based alerts and metrics.
DIY Netflow Data Analytic with ELK Stack by CL Lee
MySQL Audit using Percona audit plugin and ELK
Learn ELK in docker
ELK: a log management framework
The elastic stack on docker
How to improve ELK log pipeline performance
Javantura v3 - ELK – Big Data for DevOps – Maarten Mulders
Elks for analysing performance test results - Helsinki QA meetup
Mulesoft with ELK (Elastic Search, Log stash, Kibana)
CKA_1st.pptx
Log analysis with the elk stack
Ad

More from Che-Chia Chang (7)

PDF
COSCUP Scouter: Face recognizer retrieves your Github contribution
PPTX
Intro to go web assembly
PDF
Gdg devfest-2018
PDF
CRI, OCI, and CRI-O
PPTX
Kubernetes networks
PPTX
Automated container-deployment-on-kubernetes
PPTX
Deploy High Availability Kubernetes with Kubespray
COSCUP Scouter: Face recognizer retrieves your Github contribution
Intro to go web assembly
Gdg devfest-2018
CRI, OCI, and CRI-O
Kubernetes networks
Automated container-deployment-on-kubernetes
Deploy High Availability Kubernetes with Kubespray

Recently uploaded (20)

PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
history of c programming in notes for students .pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
System and Network Administration Chapter 2
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Digital Strategies for Manufacturing Companies
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
How to Choose the Right IT Partner for Your Business in Malaysia
history of c programming in notes for students .pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Navsoft: AI-Powered Business Solutions & Custom Software Development
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Odoo POS Development Services by CandidRoot Solutions
ISO 45001 Occupational Health and Safety Management System
How to Migrate SBCGlobal Email to Yahoo Easily
System and Network Administration Chapter 2
ManageIQ - Sprint 268 Review - Slide Deck
Internet Downloader Manager (IDM) Crack 6.42 Build 41
How Creative Agencies Leverage Project Management Software.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PTS Company Brochure 2025 (1).pdf.......
Upgrade and Innovation Strategies for SAP ERP Customers
Digital Strategies for Manufacturing Companies
Design an Analysis of Algorithms II-SECS-1021-03
2025 Textile ERP Trends: SAP, Odoo & Oracle

Elk for applications on k8s

  • 3. What is ELK Stack?
  • 4. 3 open source projects ● Kibana 分析和可視化平台 ● Elasticsearch 分布式全文搜索引擎 ● Logstash 數據收集和日誌解析引擎 ● Beats lightweight data shippers
  • 6. Why ELK 為何要收 Log / Metrics?放DB 不好嗎?
  • 7. Why Collect log ● Why log exists? ● Debug with your log ● Debug ahead of your error ML?
  • 8. System logs ● System logs SSH access, events, stress… ● Access log (Nginx)
  • 9. Logs Diary of your application
  • 10. Metrics ● System Metrics CPU / Memory / storage / IO ● App Metrics resource usage / performance
  • 12. Kubernetes Things always get a little complicated on Kubernetes ;)
  • 13. Kubernetes logging ● https://kubernetes.io/docs/co ncepts/cluster-administration /logging ● Log of container runtime ● Cluster-level logging ● Make sure your k8s store log
  • 14. One Pod, kubectl logs :) ● App generates log ● Container runtime strout ● Log file visible on Node ● Apply a collector ● Mount log
  • 15. 1000 pods, have fun :P ● Hard to locate error pod / log ● Terminated pod don’t log ● microservices, components ● Third party services, nginx, kafka, redis… ● Multi-clusters
  • 16. Alternatives(?) to ELK ● Datadog ● Stackdriver for GCP ● Prometheus / Grafana ● Fluentd ● 弄清楚你的需求
  • 18. ● Have a Elasticsearch + Kibana ● Config / Deploy beats to your apps / nodes ● Create index pattern on kibana ● Add visualization Quick Start ELK
  • 19. Have a Elasticsearch + Kibana ● Elastic Cloud (Saas) No deployment, configuration, or cluster maitainance ● Self-hosted open source ELK no authentication
  • 22. Get id and auth
  • 25. Beats config ● Elasticsearch authentication ● Where’s log ● Use module: system, nginx, docker ● beat-side data digestion
  • 26. Logstash pipeline (for nginx) ● How to parse nginx log ● pattern match ● Reduce raw data ● Normalize log to basic type ● Minimize index size ● Tidying up your log
  • 27. 35.185.145.221 - [35.185.145.221] - - [26/Dec/2018:10:44:22 +0000] "GET /modules/actions/api?timestamp=1545821062&hash=e63ffc17319baa 5524a7ad10dbb3c4be822c4e519d88efdae511116498d6c9e2 HTTP/1.1" 200 3 "-" "python-requests/2.18.4" 416 0.013 [default-app-server-80] 10.24.10.14:8080 3 0.014 200 67ce5290d19e39b2a6b614a617a1cd98
  • 28. beat logstash Elasticsearch Kinana Chart Data Source Info ELKB for complex data Logstash pipeline: inputs → filters → outputs
  • 29. https://raw.githubusercontent.com/chechiachang/elk-kubernetes/master/logstash/ pipelines-configmap.yaml input { beats { # The lisening port of logstash port => 5044 host => "0.0.0.0" } } filter { # Nginx-ingress controller example if [kubernetes][container][name] == "nginx-ingress-controller" { …… } } # filter output { elasticsearch { hosts => ["https://${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}"] user => "${ELASTICSEARCH_USERNAME}" password => "${ELASTICSEARCH_PASSWORD}" index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}" manage_template => false } }
  • 30. filter { # Nginx-ingress controller example if [kubernetes][container][name] == "nginx-ingress-controller" { # Parse message with grok grok { match => { "message" => “...” } #remove_field => "message"} mutate { add_field => { "read_timestamp" => "%{@timestamp}" }} date { match => [ "[nginx][access][time]", "dd/MMM/YYYY:H:m:s Z" ] remove_field => "[nginx][access][time]" } kv { source => "[nginx][access][url_params]" field_split => "&" } useragent { source => "[nginx][access][agent]" target => "[nginx][access][user_agent]" remove_field => "[nginx][access][agent]" } geoip { source => "[nginx][access][remote_ip]" target => "[nginx][access][geoip]" #fields => ["country_name","city_name","real_region_name","latitude","longitude","ip","location"] }
  • 31. 35.185.145.221 - [35.185.145.221] - - [26/Dec/2018:10:44:22 +0000] "GET /modules/actions/api?timestamp=1545821062&hash=e63ffc17319baa5524a7ad10dbb3c4b e822c4e519d88efdae511116498d6c9e2 HTTP/1.1" 200 3 "-" "python-requests/2.18.4" 416 0.013 [default-app-server-80] 10.24.10.14:8080 3 0.014 200 67ce5290d19e39b2a6b614a617a1cd98 %{IPORHOST:[ nginx][access][remote_ip]} - [%{IPORHOST:[nginx ][access][remote_ip_list ]}] - %{DATA:[nginx][access][user_name]} [%{HTTPDATE:[nginx ][access][time_local]}] "%{WORD:[nginx][access][method]} %{DATA:[ nginx][access][url]} HTTP/%{NUMBER:[ nginx][access][http_version ]}" %{NUMBER:[ nginx][access][response_code ]} %{NUMBER:[nginx][access][body_sent][bytes]} "%{DATA:[ nginx][access][referrer]}" "%{DATA:[nginx][access][user_agent_original ]}" %{NUMBER:[ nginx][access][request_length ]} %{NUMBER:[nginx][access][request_time ]} [%{DATA:[nginx ][access][proxy_upstream_name ]}] %{DATA:[nginx][access][upstream_addr ]} %{NUMBER:[ nginx][access][upstream_response_length ]} %{NUMBER:[nginx][access][upstream_response_time ]} %{NUMBER:[ nginx][access][upstream_status ]} %{DATA:[nginx][access][req_id]}
  • 37. Log 放 DB 不好嗎? ● 資料讀取的方便性 ● Data Define Language ● 分析工具 ● Elastic Data Storage ● full-text search ● visualization
  • 38. 導入ELK心路歷程 ● Datadog, Stackdriver,... ● 訂立需求 ● 收集所有資料 ● 釐清需求 <-> 整理資料 ● 穩定需求與pipeline ● 產生視覺化報表 ● 提供資料 / 告警給團隊
  • 39. ELK pros & cons ● lightweight collector ● powerful data pipeline ● elastic data write ● complex search and query ● Analysis tools & Visulization ● Storage consuming ● Not for permanant
  • 40. Q&A