COSCUP
      • 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
    • 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
    • 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 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
  • 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
    如何以 GitOps 方式管理 Kubernetes 集群 - Dick Tang === ###### tags: `COSCUP2020` `入門` `TR412-2` {%hackmd 7CD4pdKQTa2p6Y3VqH3VrQ %} ## 簡介 https://coscup.org/2020/zh-TW/agenda/RH99NK --- > 請從這裡開始 ## 背景 隨著 微服務 與 容器技術 的興起。 管理 與 SRE 面臨一些挑戰。 ## 議程 - 什麼是 Container 與 K8s? - 什麼是 GitOps - Kubernetes 爲什麼要 GitOps? - 什麼是 fluxCD - 演練時間 ## 什麼是 容器(Container)? - 一種內核輕量級的操作系統層虛擬化技術 - 代表: Docker - 啟動時間短很多 ## 什麼是 Kubernetes(K8S) - K8s 是 ~~fancy~~ 容器編排平台(container orchestration plaform) - 簡單來說 讓容器跑在多台服務器上 (集群) 處理集群上以及一些生產環境的問題,例如: - 容器之間的溝通 - 容器部屬在那台服務器上 - 如果服務器掛掉如何 container 如何重新佈署 - Kubernetes 最小的調度單位是 pod 不是 container - Kubernetes 有許多調度的 object,像是 Deployment, StatefulSet, DaemonSet etc. - Kubernetes 有豐富的生態圈,像是 Helm (類似 Ubuntu 的 apt 或是 CentOS 的 yum) - 有打包好的 k8s 服務環境 helm,並且有 helm hub(類似應用商店) 可以下載已經打包好的 k8s 服務 - https://hub.helm.sh/ ## 什麼是 GitOps GitOps - 用 git flow 來管理 K8s 的環境,部署到 K8s 的環境 GitOps 一樣是 DevOps 的概念,適用於 CICD,不過更 focus 在 `CD` 的部分。 ![](https://i.imgur.com/gVIIRM7.png) - 聲明式 (declaratively) 的描述整個系統 - 所需 (Kubernetes) 系統狀態儲存在 Git - 已批准的更動可以自動部署系統 - 實際狀態與所需的狀態有偏差時做出警告 ### 聲明式(declaratively)描述整個系統 - Kubernetes 是一個以 "聲明性" 配置的現代雲原生工具 - 聲明式意味著配置是由一組事實 (fact) 而不是一組指令來組成的 - 工具根本 聲明式 配置下的事實,按需要對系統做出修改 - 過程不重要,事實 (fact) 才重要。 ### 所需 (Kubernetes) 系統狀態儲存在 Git - 在 Git 中對應程序的聲明進行版本控制後,您就有了單一事實來源(Single source of turth) - 這使得回滾(roll back) 變得微不足道,因為所有東西都存在 git 裡面 - 應用程式可以輕鬆部署並且在 Kubernetes 之間回滾 (Rollback) - 您可以在其中使用 "git 恢復" 功能返回到先前的應用程序狀態 - 更重要的是,當在難來襲時,集群的基礎架構也可以可靠而快速地進行複製 - 借助 Git 出色的安全性保證,您可以使用 GPG key 來簽署提交 ### 已批准的變更可以自動部屬自系統 - 變更可以用 PR 的形式來做出批准 - 一旦聲明的狀態保存在 git 中,立刻機更改應用到集群中,並且完全自動化不需要人手介入 新來的系統工程師不用太多的教學,只要從 Git 做更改即可,減少溝通成本。 ### 實際狀態與所需的狀態有偏差時做出警告 - 聲明系統狀態並保持版本控制後,只要實際狀態不符合期望時做出通知 ### K8S 上為什麼要 GitOps? - 為什麼不只是 kubctl? - Kubectl is the new ssh. - Limit access and only use it for deployments when better tooling is not avaliable - Git 作為聲明性基礎架構的單一事實來源 - 穩定性,可靠性 - 對新手來說,容易上手 - Treat Your K8s Clusters Like Cattle, Not Pets - 像對待牛 (牲畜) 而不是寵物 (貓貓) 一樣對待 k8s 集群 - k8s 版本升級(通常都是重建新版本後移動pods,不直接升級),災難修復 ### fluxCD: The GitOps K8s operator - fluxCD 是在 k8s 實踐 gitops 工具之一 - 還有 ArgoCD, Jenkins X - 他是最簡單的一種 - 最初是由 Weaveworks 開發的 - 現在是 Apache 2.0 許可的開元專案 - 也是 CNCF 沙盒項目 - k8s 也是 CNCF ![](https://i.imgur.com/h99A0d1.png) - 定期同步 git 內容,不直接 `kubectl apply` HelmRelease (CRD) 使用 Helm 來包 services 可以考慮。 ~~kubectl 實際唸法是 "cube 咖抖" cube cuttle [How do you REALLY pronounce kubectl?](https://medium.com/diary-of-an-sre/how-do-you-really-pronounce-kubectl-4f58f76090e5)~~ ### 這次沒有談及的 - 在 fluxcd 中怎麼使用 HelmRelease - 在 fluxcd/GitOps中存 密碼 或是 憑證 - 如何在 fluxcd 中實踐 CI/CD - 如何發現及警告,在所需 - 如何發現及警告在所需的系統狀態讓實際系統的差異 ( 演練步驟 - http://bit.ly/30I8XF0

    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