iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 29
1
Kubernetes

15 分鐘學習系列 - 第一次學 Kubernetes 就上手系列 第 29

Day 29 - 整合 AKS 使用 VSTS 建立 CI/CD pipeline

前兩篇介紹 Jenkins 來建立 CI/CD pipeline. 本篇筆記將根據 https://github.com/heoelri/container-bootcamp/blob/master/labs/day2-labs/cicd-vsts.md Lab 練習來使用 VSTS 整合 AKS 來建立 CI/CD pipeline.

整合 AKS 使用 VSTS 建立 CI/CD pipeline

Lab 準備:

  1. Visual Studio Marketplace 安裝 Kubernetes extension 到 VSTS
    (1) 進入 Market place
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871a4AKLCp0Nx.png
    (2) 登入 Azure account 後, 進行安裝 Extension
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871cydvrZZVK0.png
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871wjN8Zsdcoy.png
  2. 建立一個 Azure SQL Database
    登入 Azure portal 建立 Azure SQL Database (資料庫名稱: mhcdb)
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871XAe8E9MtcP.png

設定 VSTS Team Project

  1. 進入 AZURE DEVOPS DEMO GENERATOR Sign In
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871UboCgdDDRQ.png
    (2) 選取 Organization, 建立一個新專案 (15maksdevopsdemo)
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871vN3Rq0RRWH.png
    (3) 建立完成產生 Project Url (https://dev.azure.com/unclesam/15maksdevopsdemo)
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871fgZWlvjoYr.png

建立 ARM 與 AKS 服務端點

  1. 建立 Azure Resource Manager (ARM) 端點
    (1) 在 VSTS 專案中選取新增服務連線
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871Gm27HqbadW.png
    (2) 新增 ARM 端點
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871YISb9pSGQJ.png
  2. 建立 AKS 服務端點
    (1) 登入 Azure Portal, 選取 AKS, 取得 API Server Address
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871idwLTLClPG.png
    (2) 開啟 AKS 配置檔 (C:\Users\username.kube\config)
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871hOFUAllepE.png
    (3) 新增 AKS 服務端點連線, 將 AKS config 配置檔內容複製到連線設定中
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871lEGjhQYHm6.png

配置建置與發行定義

  1. Pipeline 中選取 Builds, 將 Azure SubscriptionAzure Container Registry 資訊依序填入 Run/Build/Push/Lock/Publish Artifact
    https://ithelp.ithome.com.tw/upload/images/20181107/2011187155eisoI25y.png
  2. Pipeline >> Release 中, 選取 MyHealth-AKS.Release 定義 >> Tasks
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871Xn67buexh4.png
  3. 在 Dev deployment process 中, DB deployment 選取 Execute Azure SQL : Dacpac Task, 填入 Azure Subscription
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871EoScIqAbGw.png
  4. 在 AKS deployment 選取 Create Deployments & Service in AKS, 選取 Kubernetes service connection, 以及 Azure SubscriptionAzure Container Registry
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871H0JcxeU46T.png
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871NmV3PYRcUO.png
  5. 選取 Variables >> Pipeline variables, 填入 ACR, DatabaseName, Password, SQLadmin 以及 SQLServer 變數
    https://ithelp.ithome.com.tw/upload/images/20181107/201118712lT9FodBlu.png

更新 manifest 檔案設定

  1. Files 開啟 appsettings.json, 將 DefaultConnection 內容更新為你的 Azure SQL Server connection string.
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871Ru2dVxQQxb.png
  2. 修改 mhc-aks.yaml 檔案, 調整 Container 資訊
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871CMUmgdvL1k.png

建置觸發與部署應用程式

  1. 進入 Builds, 選取 MyHealth-Kubernetes-Build >> Queue new build
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871XbagNjOIT9.png
  2. 觀察建置是否成功
    https://ithelp.ithome.com.tw/upload/images/20181107/20111871K63ee6pgJL.png

以上便完成了 VSTS 整合 AKS 建立 CI/CD pipeline 的練習了!


參考資料:


上一篇
Day 28 - 整合 AKS 使用 Jenkins 建立 CI/CD pipeline
下一篇
Day 30 - 使用 SSH 連線至 AKS 叢集進行維護
系列文
15 分鐘學習系列 - 第一次學 Kubernetes 就上手30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言