添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

GitOps 介紹

GitOps 是一種 DevOps 的解決方式,方法是以 Git 為中心,將應用程式、部屬檔案(如 Helm Chart )、基礎架構即代碼(如 Terraform ) 等所有所需資源全部都放入 Git 的 Repository 中進行管理,使用者只需要在 Git Repo 進行操作 (如 Push 、 Merge Requests ),部屬環境就會根據 Git 的變動進行更新,透過 GitOps 會有以下好處

  • 開發者只需要通過 Merge Requests 就能完成應用的部屬
  • 每一次的更新都會存在 Git Repo 裡,可以查看各次的差別
  • 使用 Git 作為信任源,達到一致性和標準化
  • 想了解更多的話,在 GitLab 的 What is GitOps? 文章中有更詳細的介紹。

    下圖是一個 GitOps 流程的示範,開發者與維運人員只需操作 Git Repo ,就可以完成在 Kubernetes 的交付。

    建立 App 及 Manifest 的 GitLab Repository

    要建置 GitOps 環境的話, Git 的使用是少不了的,今天的任務很簡單,就是建立好 GitLab 的 Repository 並將 App 以及 Manifest 檔案上傳,需要先準備好 GitLab 帳號。

    這裡的 App 指的是開發的應用程式,Manifest 則是指宣告 Kubernetes 元件的檔案。

    進入 GitLab 網站。

    點擊 New project 建立專案

    Manifest 的 Repository 也建立成功了。

    上傳 App 及 Manifest 檔案到 GitLab Repository

    App 會使用在 Day08 創建的 NodeJS Web App,Manifest 則是使用在 Day15 建置的 Helm Chart,還沒準備的可以回去複習一下,準備好的就來把檔案上傳到 GitLab 上。

    進入 Cloud Shell 網站,點擊終端機輸入指令。

    設定 Git Config

    git config --global user.name "user"
    git config --global user.email "[email protected]"
    
  • 首先上傳 WebApp 資料,cd 到 WebApp 的目錄。
  • cd ~/project
    

    (輸出結果)

    app.js  dockerfile  node_modules  package.json  package-lock.json
    

    裡面有如 node_modules 不須進入版本控制的檔案,所以建立.gitignore 來避免傳到 Repo 裡。

  • 建立 .gitignore 檔案
  • cat > .gitignore <<EOF
    node_modules
    npm-debug.log
    
  • 建立 Local Repo
  • git init
    git add .
    git commit -m "init"
    
  • 到 webapp 的 GitLab Repo,點擊 Clone-> Clone with HTTPS 複製地址
  • 回到 Terminal,推送檔案到 GitLab 上,將 <your webapp repo> 修改成剛剛複製的地址
  • git remote add origin <your webapp repo>
    git push origin master
    
  • 輸入 GitLab 帳號密碼後按Enter
    Username for 'https://gitlab.com': 
    Password for 'https://[email protected]':
    

    在 webapp 的 GitLab Repo 網站重新整理,就可以看到檔案上傳成功。

    接著使用同樣方法,把 Manifest 資料也上傳到 GitLab。

  • 移動到 Manifest 資料夾
  • cd ~/webapp
    

    (輸出結果)

    charts  Chart.yaml  templates  values.yaml
    
  • 建立 Local Repo
  • git init
    git add .
    git commit -m "init"
    
  • 到 webApp-manifest 的 GitLab Repo,點擊 Clone-> Clone with HTTPS 複製地址
  • 回到 Terminal,推送檔案到 GitLab 上,將<your webapp-manifest repo>修改成剛剛複製的地址
  • git remote add origin <your webapp-manifest repo>
    git push origin master
    
  • 輸入 GitLab 帳號密碼後按Enter
    Username for 'https://gitlab.com': 
    Password for 'https://[email protected]':
    

    在 webapp-manifest 的 GitLab Repo 網站重新整理,就可以看到檔案上傳成功。

    今天了建立 GitLab Repo ,為之後的教學做準備,在後幾天的文章就會學習到如何使用 GitLab CI 來實現 GitOps 技術。

  •