iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 2
2
DevOps

其實我真的沒想過要利用夾縫中求生存的 30 天K8s可以怎麼用系列 第 2

Oh My Logs ! 談談如何在K8s中收集logs - 2

  • 目錄
    • Introduce and analysis
    • @ Cluster level ELK @
    • Sidecar mode
    • Integrate log collecting component into an app

今天要來談談什麼是Cluster level ELK
Cluster 的基本工作單位是Node, 所以我今天會試著將Fluentd裝在每台Node上面

上一篇文章中有提到, DaemonSet 是一種K8s在Node上運行daemon的一種機制,
要在Node上起一個DaemonSet就必須要撰寫一個yaml file, 我這邊偷懶拿官方範例來跑

直接GG, 後來查看Issue List發現根本沒有v2.5.1
好吧只好來看看哪邊才抓的到image

最後直接在這邊找到了

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd-elasticsearch
  namespace: kube-system
  labels:
    k8s-app: fluentd-logging
spec:
  selector:
    matchLabels:
      name: fluentd-elasticsearch
  template:
    metadata:
      labels:
        name: fluentd-elasticsearch
    spec:
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      containers:
      - name: fluentd-elasticsearch
        image: gcr.io/fluentd-elasticsearch/fluentd:v2.4.0
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers

跑起來後要怎麼驗證Fluentd有收集到Node的Log?
我們在上面的DaemonSet有設定volumeMounts

可以看到fluentd這個Daemon收集了其他Pods的log

進入其中一台Node之後可以看到確實有個container起了個fluentd的Daemon在幫我們收集log

明天會講如何以SideCar的形式來收集log

Reference

小信豬的原始部落:
https://godleon.github.io/blog/Kubernetes/k8s-StatefulSets-Overview/
官方#DaemonSet:
https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/#writing-a-daemonset-spec


上一篇
Oh My Logs ! 談談如何在K8s中收集logs - 1
下一篇
Oh My Logs ! 談談如何在K8s中收集logs - 3
系列文
其實我真的沒想過要利用夾縫中求生存的 30 天K8s可以怎麼用12
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言