Slide 1

Slide 1 text

GKEͰ͸
 StackDriver Loggingʹ
 Ͳ͏΍ͬͯϩάΛૹ͍ͬͯΔ͔ 2017/08/08 Kubernetes Meetup Tokyo #6 
 takumi_yoshida_22 / @ytakky2014

Slide 2

Slide 2 text

ࣗݾ঺հ • ytakky2014 / ٢ా ୓࣮
 • github https://github.com/ytakky2014 • @y_takky2014 
 https://twitter.com/y_takky2014 • GCP / golang / PHP / CIɾCD / http://info.ytakky.tech/

Slide 3

Slide 3 text

agenda • GKE, StackDriver Loggingʹ͍ͭͯ • StackDriverʹϩάΛૹΔfluentdͷconfʹ͍ͭ ͯ • GKE্ͰfluentdͷΧελϚΠζʹ͍ͭͯ

Slide 4

Slide 4 text

GKE • GoogleCloudPlatform(GCP)ͷ
 KubernetesϑϧϚωʔδυαʔϏε • StackDriver Loggingͱ
 StackDriver MonitoringʹΑΔڧྗͳ؂ࢹ

Slide 5

Slide 5 text

StackDriverLogging • GCP্ͷϩάΛ֨ೲɾ෼ੳͰ͖ΔαʔϏε • agentΛೖΕΕ͹AWS΋ରԠ • BigQuery΁ͷΤΫεϙʔτ
 GCS΁ͷΞʔΧΠϒ 
 Cloud Pub/SUB΁ͷετϦʔϛϯά ͕ରԠ

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

GKE͸Ͳ͏΍ͬͯLogΛ StackDriverLoggingʹૹ͍ͬͯΔͷ͔ • A. fluentd Ͱૹ͍ͬͯΔ

Slide 8

Slide 8 text

࣮ࡍʹͲ͏΍ͬͯऩू͢Δ͔ • daemonsetsͰશϊʔυ΁഑ஔ͍ͯ͠Δ • https://github.com/kubernetes/kubernetes/blob/ master/cluster/addons/fluentd-gcp/fluentd-gcp- ds.yaml

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

fluentdͷઃఆΛ֬ೝͯ͠ΈΔ https://github.com/kubernetes/kubernetes/blob/ master/cluster/addons/fluentd-gcp/fluentd-gcp- configmap.yaml

Slide 11

Slide 11 text

ೖྗ type tail format json time_key time path /var/log/containers/*.log pos_file /var/log/gcp-containers.log.pos time_format %Y-%m-%dT%H:%M:%S.%N%Z tag reform.* read_from_head true

Slide 12

Slide 12 text

࣮ࡍ͸ͲͷϑΝΠϧΛऩूͯ͠ ͍Δ͔ • Nodeͷ /var/log/containers/*.logʹSTDOUTʹు͔Εͨϩά͕͋Δ • ࣮ࡍͷϑΝΠϧ໊͸
 [pod໊]_[namespace]_[containerID].log • frontend-3823415956-79vzs_default_php- redis-83772f44edd5ee75e921c063d45b710f5053d0a2c86a5c40c3212c b48922bb2c.log • ͜ΕʹreformΛprefixͱͯ͠෇͚Δ
 reform.frontend-3823415956-79vzs_default_php-redis- 83772f44edd5ee75e921c063d45b710f5053d0a2c86a5c40c3212cb489 22bb2c.log

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

type record_reformer enable_ruby true tag raw.kubernetes.${tag_suffix[4].split('-') [0..-2].join('-')}

Slide 15

Slide 15 text

• tag raw.kubernetes.${tag_suffix[4].split(‘-') [0..-2].join('-')} • reform.frontend-3823415956-79vzs_default_php- redis-83772f44edd5ee75e921c063d45b710f505 3d0a2c86a5c40c3212cb48922bb2c.log • raw.kubernetes.frontend-3823415956-79vzs_defa ult_php-redis • ʹͳΔ

Slide 16

Slide 16 text

@type detect_exceptions remove_tag_prefix raw message log stream stream multiline_flush_interval 5 max_bytes 500000 max_lines 1000

Slide 17

Slide 17 text

• https://github.com/GoogleCloudPlatform/fluent-plugin- detect-exceptions Λ࢖͍ͬͯΔ • ྫ֎ݕग़ϓϥάΠϯɻlogstreamΛεΩϟϯ • ಉ࣌ʹraw. Λ֎͍ͯ͠Δ • kubernets.frontend-3823415956-79vzs_default_php- redis

Slide 18

Slide 18 text

@type google_cloud # Collect metrics in Prometheus registry about plugin activity. enable_monitoring true monitoring_type prometheus # Set the buffer type to file to improve the reliability and reduce the memory consumption buffer_type file buffer_path /var/log/fluentd-buffers/ kubernetes.containers.buffer
 ....

Slide 19

Slide 19 text

• @type google_cloud
 https://github.com/GoogleCloudPlatform/fluent- plugin-google-cloud • StackDriver Logging APIʹϩάΛૹ৴͢Δϓϥά Πϯ • ͜ͷϓϥάΠϯͰStackDriverLoggingʹૹ৴ͯ͠ ͍Δ

Slide 20

Slide 20 text

fluentdͷઃఆΛม͍͑ͨ • fluentdͷpluginΛ௥Ճ͍ͨ͠ • fluentdͷconfigͷઃఆΛมߋ͍ͨ͠

Slide 21

Slide 21 text

લ४උ • GKEͷ৔߹ Ϋϥελʔ࡞੒࣌ʹ StackDriverLoggingΛOffʹ͢Δඞཁ͕͋Δ • https://kubernetes.io/docs/tasks/debug- application-cluster/logging-stackdriver/ GKE >= 1.6Ҏ্͕ඞཁ ※gcloud container clustersͱ͔ίϚϯυͰมߋ΋Ͱ͖ͳ͍...

Slide 22

Slide 22 text

fluentd-pluginΛ௥Ճ͍ͨ͠ • https://github.com/GoogleCloudPlatform/k8s- stackdriver/tree/master/fluentd-gcp-image • GemfileʹඞཁͳpluginΛ௥Ճͯ͠
 docker build / docker push • fluentd-gcp-ds.yamlͷimageΛpushͨ͠image ʹมߋͯ͠σϓϩΠ

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

fluentdͷconfigΛมߋ͢Δ • fluentd-gcp-configmap.yamlΛฤू͢Ε͹OK • 1ϑΝΠϧʹͳ͍ͬͯΔͷͰΘΓͱฤू͕ͭΒ ͍

Slide 25

Slide 25 text

ઃఆมߋޙͷσϓϩΠ • fluentd-gcp-configmap.yamlͱfluentd-gcp- ds.yamlΛ೚ҙͷnamespace΁σϓϩΠ • kubectl create -f fluentd-gcp- configmap.yaml • kubectl create -f fluentd-gcp-ds.yaml

Slide 26

Slide 26 text

·ͱΊ • STDOUTʹϩάΛམͱ͓͚ͯ͠͹ɺ
 GKEͳΒ͹ࣗಈͰStackDriverLogging΁సૹ • fluentd-pluginͷ௥Ճ΍fluentd confͷมߋʹͳΔͱखؒʹ ͳΔ • StackDriverLogging͸Exportग़དྷΔͷͰfluentdͷઃఆͰͲ ͏ʹ͔͍ͨ͠Θ͚Ͱ͸ແ͚Ε͹ͦͪΒΛ࢖ͬͨ΄͏͕ྑ͍
 gSlack: Integrating Google Cloud Platform with Slack
 https://blog.doit-intl.com/gslack-9391be7c191a