Tsung-Jung Tsai (TJ_Tsai)
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    [plugin][CNI] CNI plugin === ###### tags: `K8s / plugin` ###### tags: `Kubernetes`, `k8s`, `plugin`, `CNI plugin`, `Flannel`, `Calico`, `Cilium`, `Weave`, `Canal` <br> [TOC] <br> ## 🌐 什麼是 CNI? > by gpt-4o (2025/06/05) **CNI 全名為 Container Network Interface (容器網路介面),是 Kubernetes 中讓 Pod 有網路的關鍵組件。** --- ### 🔧 CNI 的功能是什麼? 當一個 Pod 被建立時,CNI plugin 負責: 1. 🪄 **建立網路介面給 Pod** 2. 🌍 **給 Pod 分配 IP 位址** 3. 📶 **設定路由與 DNS** 4. 🔌 **連接 Pod 到主機網路,讓它能跟其他 Pod/外部通訊** 你可以把 CNI 想像成幫 Pod 插上網路線的那個人。 --- ### 🧩 CNI 是 Plugin 架構 Kubernetes 本身**不內建網路功能**,而是透過 CNI plugin 提供。 常見的 CNI Plugin 有: | 名稱 | 特點 | |------------|------------------------------------| | **Flannel** | 最簡單的網路,適合入門 | | **Calico** | 支援網路策略與 BGP,性能好 | | **Cilium** | 使用 eBPF 技術,支援高安全與可觀察性 | | **Weave** | 適合小型叢集 | | **Canal** | Flannel + Calico 混合方案 | - Flannel [ˋflæn!] 法蘭絨;棉絨 - Calico [ˋkælə͵ko] 【美】印花棉布[U];【英】白棉布 - Cilium [ˋsɪlɪəm] 【植】纖毛, 【動】纖毛 - Weave [wiv] 織物 - Canal [kəˋnæl] 運河;河渠,水道 --- ### 🚦 CNI 的運作流程(建立 Pod 時) 1. Kubernetes 要建立一個 Pod 2. kubelet 呼叫 CNI plugin 3. CNI plugin: - 建立 veth 虛擬網路裝置 - 把一端放進 Pod,另一端接到主機的橋接裝置(例如 `cni0`) - 分配 IP - 設定路由 4. Pod 就能上網、跟其他 Pod 溝通了! --- ### 🔍 為什麼你需要了解 CNI? - Pod 無法連線?80% 是 CNI 出問題 - 換 CNI(例如從 Flannel → Cilium)能帶來更好的安全與效能 - 了解 CNI 有助於排除 `DNS失效、Pod卡住、網路不通` 等問題 --- ### ✅ 小結 | 問題 | 是否由 CNI 控管 | |-------------------------------|-----------------| | Pod 能否拿到 IP? | ✅ 是 | | Pod 能不能 ping 其他 Pod? | ✅ 是 | | DNS 能不能解析? | ✅ 通常是 | | Service 負載平衡? | ❌ kube-proxy 或 Cilium 處理 | | eBPF、網路策略、安全控制? | ✅ 較進階的 CNI 才支援 | --- 如果你想了解更進階的像是: - CNI plugin 是怎麼「掛進 K8s」的? - eBPF 與 Cilium 的關係? - 如何自己寫一個簡單 CNI plugin? 我也可以幫你拆解說明!需要嗎? <br> <hr> <br> ## 通用 Kubernetes CNI 環境中,排查 Pod DNS 問題的完整流程 > by gpt-4o (2025/06/06) 以下為在任何 CNI(例如 Flannel、Cilium、Calico 等)環境中,依序檢查 DNS 是否正常的通用流程: - ### ✅ 步驟 1:在 **Host(節點)中測試 DNS 是否正常** 確認主機層的網路與 DNS 沒有問題(排除本機錯誤): ``` nslookup archive.ubuntu.com ``` 如果這裡就無法解析,請檢查 host 的 `/etc/resolv.conf` 或本地 DNS 代理(如 `systemd-resolved`)。 - ### ✅ 步驟 2:在 **Pod 中確認 DNS 能否解析** 進入 Pod 中執行測試: ``` nslookup archive.ubuntu.com ``` 若失敗,表示 Pod 網路或 DNS 有問題。 - ### ✅ 步驟 3:在 Pod 中查看 `/etc/resolv.conf` 確認 Pod 內部的 DNS 設定是否指向正確的 kube-dns Service IP: ``` cat /etc/resolv.conf ``` 應包含如下內容(以 Service CIDR 為準): ``` nameserver 10.96.0.10 search default.svc.cluster.local svc.cluster.local cluster.local options ndots:5 ``` - ### ✅ 步驟 4:查詢 kube-dns Service IP,與 Pod 中設定比對 確定 kube-dns service 存在,並取得正確 IP: ``` kubectl get svc -n kube-system kube-dns ``` 比對 Pod 中 `/etc/resolv.conf` 的 `nameserver` 是否與此 IP 一致。 - #### ✅ 步驟 5:確認 kube-dns(通常是 CoreDNS)Pod 是否正常運作 ``` kubectl get pods -n kube-system -l k8s-app=kube-dns ``` 確認狀態為 `Running` 且 `READY` 為 1/1 或 2/2。 - #### ✅ 步驟 6:查看 CoreDNS(或其他 DNS pod)日誌 檢查是否有解析失敗、錯誤訊息: ``` kubectl logs -n kube-system -l k8s-app=kube-dns ``` 重點觀察是否出現: - `SERVFAIL` - `NXDOMAIN` - `connection refused` - `timeout` - ### ✅ 步驟 7:建立一個獨立測試 Pod 測試 DNS 是否正常 使用 busybox 建立短暫 Pod,執行解析測試: ``` kubectl run dns-check --rm -it --image=busybox --restart=Never -- nslookup archive.ubuntu.com ``` 這可以協助確認: - 若測試 Pod 成功 → 表示系統正常,原 Pod 有問題。 - 若測試 Pod 也失敗 → 表示整體 DNS 系統有問題(CNI、kube-dns、iptables 等)。 - ### 📌 備註 - 預設 `kube-dns` ClusterIP 為 `10.96.0.10`(可依你安裝 Kubernetes 時的 `--service-cidr` 調整)。 - DNS 問題常見於: - CNI 安裝未正確配置網路 - kube-dns / CoreDNS 未啟動或 crash - iptables / eBPF 未正確導流 DNS 封包 - Pod 未經由正確的 CNI 初始化 - 確保 Pod 建立後有透過正確的 CNI 執行,DNS 通常就會正常。 <br> {%hackmd vaaMgNRPS4KGJDSFG0ZE0w %}

    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