DevOpsDay
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 在K8s上實現全棧監控 - 賴政州 Steven {%hackmd @DevOpsDay/BJXaW1_k6 %} > 從這裡開始寫 package: https://toleadafulfillinglife.com/full-stack-monitoring-for-kubernetes/ - fluentbit傳送到Loki存放: 收集Pods跟Nodes的Log送給Loki - OpenTelemetry傳送到Tempo存放: 可以根據Trace ID追蹤上下游, Log會有Trace ID可以反查, 找到服務之間的關係 用sidecar去部署otc-containter 要先安裝Ingress Controller 讓我們可以設定外部訪問進入 K8s 集群的路由,在 Kubernetes 中是類型為 LoadBalancer 的 Service。 ## YAML Files 1. 使用prometheus-community/kube-prometheus-stack Helm分成Ingress、Valeus的檔案 這邊是設定各namespace可以收到metric ``` prometheus: prometheusSpec: serviceMonitorSelectorNilUsesHelmValues: false serviceMonitorNamespaceSelector: {} serviceMonitorSelector: {} ``` 這邊是告警規則 ``` additionalPrometheusRules: - name: custom-rules groups: - name: AllInstances rules: - alert: InstanceDown expr: up == 0 for: 1m annotations: title: 'Instance {{ $labels.instance }} down' description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 1 minute.' labels: severity: 'critical' ``` 2. open-telemetry 使用 open-telemetry/opentelemetry-operator 跟 grafana/tempo Open telemetry 會使用 webhook做驗證,所以要先安裝cert-manager 部署OpenTelemetryCollector 3. Loki 使用 grafana/loki-stack 若要看 fluent-bit 其它可以設定的 values 可以用此指令: helm show values fluent/fluent-bit > fluentbit-all-values.yaml ### Q&A: 1. AlertManager跟Grafana Alerts的差異是什麼? 2. 可以解釋一下[這邊](https://github.com/knowledge420/full-stack-monitoring-for-kubernetes-devopsdays2023/blob/main/fluentbit-configmap.yaml)的data session底下設定的意思嗎? #### 回覆問題1: * Grafana Alerts與Alert Manager都是針對metrics做告警的工具。 * Grafana Alerts可以在介面上設定Alert Rules及通知Channel。 * Alert Manager是為了Prometheus metrics告警而存在的工具,有預設的Alert Rules,且其通知Channel route規則可以做群組這樣比較複雜的設定。 * 所以結合兩者優點同時一起用是可以的。 * [Grafana Alerting vs AlertManager: A Comparison of Two Leading Monitoring Tools](https://alexandrev.medium.com/grafana-alerting-vs-alertmanager-a-comparison-of-two-leading-monitoring-tools-5e262446a5f9) #### 回覆問題2: 以下做了大概說明,有些英文字面上的意思就沒有再註釋了,若有疑問可以再來信,謝謝您的參與。 ``` data: custom_parsers.conf: | # 自定義的日誌解析Parser [PARSER] Name spring_pattern Format regex Regex ^(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}:\d{3}) \[(?<loglevel>\w+)\] \[(?<user>.+?)\] \[(?<thread>.+?)\] \[(?<traceId>.+?)\] \[(?<spanId>.+?)\] \[(?<trace_flags>.+?)\] (?<class>\w+).(?<method>\w+):(?<line>\d+): (?<message>.+)$ Time_Key time Time_Format %Y-%m-%d %H:%M:%S:%L fluent-bit.conf: | # 自定義的fluentbit設定檔 [SERVICE] # 定義fluentbit本身服務啟動的參數 Daemon Off Flush 1 Log_Level info Parsers_File custom_parsers.conf HTTP_Server On HTTP_Listen 0.0.0.0 HTTP_Port 2020 Health_Check On [INPUT] # 定義tail插件去哪裡抓取日誌 Name tail Path /var/log/pods/*/*/*.log multiline.parser docker, cri Tag var.* # 為日誌貼標方便做其它fluentbit功能,如FILTER Mem_Buf_Limit 5MB # 緩存上限5MB Skip_Long_Lines On # 日誌太長就跳過,確保fluentbit穩定性,日誌越長,緩存需求越高 # 下方開始有多種FILTER,是fluentbit提供的插件,Name是插件名稱 [FILTER] Name kubernetes # 收集Kubernetes日誌 Match kube.* # 應用於標籤為"kube.*"的日誌 Merge_Log On # 合併日誌 Keep_Log Off # 不保留原日誌 K8S-Logging.Parser On # 預設日誌解析 K8S-Logging.Exclude On # 預設排除特定日誌 [FILTER] Name nest # 對JSON日誌進行結構調整 Match kube.* Operation lift # JSON結構調整的一種操作名稱 Nested_under kubernetes Add_prefix kubernetes_ # 將被操作的Key加上前綴字 [FILTER] Name grep # 搜尋過濾日誌 Match kube.* Exclude kubernetes_container_name fluent-bit # 排除fluentbit自己的日誌 [FILTER] Name throttle # 日誌限流 Match * Rate 800 Window 3 Print_Status true Interval 30s [OUTPUT] # 這裡依照架構設計fluentbit後面接的Storage是Loki name loki match * host loki.tracing.svc port 3100 labels job=fluentbit # 日誌標籤加入job標籤,其值為fluentbit label_keys $trace_id # 將traceId作為標籤加入日誌標籤 auto_kubernetes_labels on # yaml定義的label加入日誌標籤 [OUTPUT] Name stdout # 將日誌也傳到stdout Match * ``` 另外再補充 [otel-collector-sidecar.yaml](https://github.com/knowledge420/full-stack-monitoring-for-kubernetes-devopsdays2023/blob/main/otel-collector-sidecar.yaml): ``` receivers: # 定義來源接收方式 otlp: # 使用OTLP協議 protocols: # 支持的傳輸協定 grpc: # 支持gRPC傳輸協定 http: # 支持HTTP傳輸協定 processors: # 定義traces處理方式 batch: # 批次處理 memory_limiter: # 記憶體限制 limit_mib: 400 # 記憶體最多可用400 MiB spike_limit_mib: 100 # 限制記憶體不應該突增超過100 MiB,否則捨棄 check_interval: 5s # 每5秒檢查一次 exporters: # 定義輸出方式 logging: # 日誌輸出 otlp: # 使用OTLP協議 endpoint: tempo.tracing.svc.cluster.local:4317 # 輸出端點,這裡依照架構設計Collector後面接的Storage是Tempo tls: # TLS協議 insecure: true # 允許不安全傳輸 sending_queue: # 消息隊列 num_consumers: 4 # 消費者數量 queue_size: 100 # 隊列大小 retry_on_failure: # 失敗是否重試 enabled: true service: # 定義上方所宣告的receivers, processors, exporters要使用哪些 pipelines: # 工作管道 traces: # 這邊只定義使用OpenTelemetry的traces功能,OpenTelemetry也有提供logs與metrics功能 receivers: [otlp] # 使用的receiver processors: [memory_limiter, batch] # 使用的processor exporters: [logging, otlp] # 使用的exporter ``` ### 留言板 Steven: ``` 祝大家中秋節快樂☺️ 活動當天因擔心影響工作坊進度, 若實作有問題於活動當時沒有為您解答的,或是有其他問題想提問都可以寄信到此: knowledge840420@gmail.com 我會為您解答,一同學習,推廣技術。 謝謝您的參與❤️ ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully