iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 19
1
Everything on Azure

玩轉 Azure 於指尖隨心所欲系列 第 19

搭上容器服務熱潮,來試試 Azure Container Instances (ACI) 吧!

上篇雖然是以WebApps形式呈現但骨子裡是用Docker來做部署,除了直接抓取Docker Hub上images來作為網站服務外也同時來試試放在Azure自家的azure container registry(ACR),單純把外部的image丟到ACR內那為私用後再再讓WebApps來取用.

今天就來玩玩無OS的Container Instances服務吧!

一樣新增資源的地方昨天是ACR...今天是住在樓上的ACI
https://ithelp.ithome.com.tw/upload/images/20181019/20025481cg5Zm3q5s1.png

不免俗先入門簡單部署不能傷害失敗幼小心靈...不過我做了小小改變(本來是預設微軟的HelloWorld改成Ubuntu)
https://ithelp.ithome.com.tw/upload/images/20181019/20025481nFj24Qo1C5.png

Ubuntu image示範來源在此
https://ithelp.ithome.com.tw/upload/images/20181019/20025481WWfXxWDmWg.png

這些細項都是需求服務規格,不多贅述直接預設就好
https://ithelp.ithome.com.tw/upload/images/20181019/20025481A2OmyMYqEy.png

驗證設定是否OK,沒問題就直接部署吧!
https://ithelp.ithome.com.tw/upload/images/20181019/20025481crhgelazIR.png

部署作業中
https://ithelp.ithome.com.tw/upload/images/20181019/20025481jK10utgWBm.png

部署完成了,到剛剛的資源群組內開啟garyaci
https://ithelp.ithome.com.tw/upload/images/20181019/20025481tICKD9cKKp.png

直接來開此URL......ㄎㄠˋ/images/emoticon/emoticon02.gif
https://ithelp.ithome.com.tw/upload/images/20181019/20025481l4Kdh2Refh.png

檢視一下事件動作最後的時間點一直在嘗試重啟....多次
https://ithelp.ithome.com.tw/upload/images/20181019/20025481IAamAInE4M.png

把此garyaci容器給割除...(我不相信...怎麼可能只能用預設image的才能正常)
https://ithelp.ithome.com.tw/upload/images/20181019/20025481fseKGNKmHv.png

重新再部署一次,但是Images改成Nginx(雖然還是滿常用的...但至少不是ACI預設映像範例)
https://ithelp.ithome.com.tw/upload/images/20181019/20025481yMIk5bvgxi.png

看一下新建成功的容器從事件上顯示的跟前次不同,可以很有信心的來測試
https://ithelp.ithome.com.tw/upload/images/20181019/20025481MxzNrfDjx7.png

確認一下這ACI的前端連線URL
https://ithelp.ithome.com.tw/upload/images/20181019/20025481pBaYI3QdOn.png

沒有問題了!正常顯示Nginx示範網頁
https://ithelp.ithome.com.tw/upload/images/20181019/20025481Qt4Xk5nfHU.png

不過只有這樣怎麼行呢!!這次來點新嘗試自建一個image丟到ACR再透過ACI來部署ACR上此image你說好不好啊!/images/emoticon/emoticon07.gif

不過畢竟我自身的Mac環境在安裝Azure CLI真的是問題多多...直接來運用雲端的優勢繞道而行直接用Ubuntu上裝好的Docker,到時候再安裝Azure CLI不就得了
https://ithelp.ithome.com.tw/upload/images/20181019/20025481aIBCpeMiTq.png

規格測試而已不用太好...但也別太差,不想等到天涯海角,測試環境自己決定吧!
https://ithelp.ithome.com.tw/upload/images/20181019/20025481B7A0PpCg2n.png

看了一下虛擬網路部份看起來並沒法選擇既有的只能新建而已,就預設嘍!
https://ithelp.ithome.com.tw/upload/images/20181019/20025481EyqaHK2u1H.png

執行個體IP就是外部IP要開啟,不然我怎麼連....
https://ithelp.ithome.com.tw/upload/images/20181019/20025481X9DoF4x8G1.png

沒有預建儲存體也無法改名,就預設好了,反正測試而已
https://ithelp.ithome.com.tw/upload/images/20181019/20025481mtvSvFC1yh.png

對外端點開放連接埠SSH TCP22,先這樣之後需要再開
https://ithelp.ithome.com.tw/upload/images/20181019/20025481Tx5tTjhZ8c.png

Docker延伸模組預設也安裝
https://ithelp.ithome.com.tw/upload/images/20181019/20025481zeBeb4Lq4n.png

總算設定完了就確定吧!
https://ithelp.ithome.com.tw/upload/images/20181019/20025481wDGlxaiqDT.png

安裝好了透過上面的Public IP來SSH連線並登入成功
https://ithelp.ithome.com.tw/upload/images/20181019/20025481Dd9JaypKn6.png

因為等等需要做事..用剛剛自建的帳戶權限不足,透過此指令sudo su - 直接變更成root身份來執行,一定要來一下Docker指令看一下版本也ping外部IP確認一下環境是否正常
https://ithelp.ithome.com.tw/upload/images/20181019/20025481vOkViWLjj0.png

接下來就是一連串生硬的動作:

  • 用 Git 複製範例應用程式的存放庫
    git clone https://github.com/Azure-Samples/aci-helloworld.git

  • 用 docker build 命令來建立容器映像,並標記成 aci-tutorial-app
    docker build ./aci-helloworld -t aci-tutorial-app

  • 用 docker images 命令查看已建置的映像
    docker images
    https://ithelp.ithome.com.tw/upload/images/20181019/20025481P10YMXpypl.png

  • 容器部署至 Azure Container Instances 前,先用 docker run 在本機執行確認是否可行
    docker run -d -p 8080:80 aci-tutorial-app (Liunx curl測試)
    https://ithelp.ithome.com.tw/upload/images/20181019/20025481SvI9TAox8q.png

瀏覽器中瀏覽至 http://localhost:8080 ,以確認容器正在執行(因為都是CLI命令列沒法瀏覽器呈現,來順便對外一下,這是一台ASM舊型VM....所以沒有NSG而是透過端點來限制,新增http走8080一筆規則做允許)
https://ithelp.ithome.com.tw/upload/images/20181019/20025481gDlKjercm2.png

規則設定完成
https://ithelp.ithome.com.tw/upload/images/20181019/200254815vlzuCDeY6.png

這是透過外部連線他的URL走8080已經OK無誤
https://ithelp.ithome.com.tw/upload/images/20181019/20025481HDVkwAjwSr.png

登入到目前的ACR
https://ithelp.ithome.com.tw/upload/images/20181019/20025481vbafdsb8Ek.png

檢查一下裡面的Images...因為範本都大同小異..等等名稱可能怕重複
https://ithelp.ithome.com.tw/upload/images/20181019/20025481lZdBYET3Iu.png

因為有一筆Docker網頁服務還在Run,直接全部把程序Kill掉
docker rm $(docker ps -all -q)
https://ithelp.ithome.com.tw/upload/images/20181019/20025481bHZO3HpcwV.png

來一次給它移除全部images...一勞永逸@@下面兩筆有v1的還是Lock
docker rmi $(docker image ls -q)
https://ithelp.ithome.com.tw/upload/images/20181019/20025481VDPBbpiBIz.png

沒關係暫時不解它..推送前需先對在ubuntu上建立好的image打上Tag並指定為v3版本藉此方便區分
https://ithelp.ithome.com.tw/upload/images/20181019/20025481eIg9BofKdv.png

接下來就是用Azure AZ指令才能做事,目前Ubuntu還沒有安裝CLI
Ubuntu是透過apt來安裝Azure CLI

  1. 修改來源清單
    AZ_REPO=$(lsb_release -cs)
    echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" |
    sudo tee /etc/apt/sources.list.d/azure-cli.list
  2. 取得 Microsoft 簽署金鑰
    curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  3. 安裝 CLI
    sudo apt-get update
    sudo apt-get install apt-transport-https azure-cli
    https://ithelp.ithome.com.tw/upload/images/20181019/20025481HGUhZPaBDW.png

Azure AZ登入,CLI需要認證碼再到提示的指定網站驗證
https://ithelp.ithome.com.tw/upload/images/20181019/20025481yxyMJg2Y17.png

把驗證碼貼上後確認
https://ithelp.ithome.com.tw/upload/images/20181019/200254817pu9IHrI3C.png

已登入CLI成功提示,可以關閉此網頁
https://ithelp.ithome.com.tw/upload/images/20181019/20025481BCPLLinF70.png

因為我自己的Azure帳號綁太多訂閱...請指定剛剛ACR的訂閱環境確認好租用戶ID在登入一次
https://ithelp.ithome.com.tw/upload/images/20181019/20025481xPe2YZqdf1.png

登入成功並到進到ACR
https://ithelp.ithome.com.tw/upload/images/20181019/20025481zqYEInuKMo.png

執行推送從ubuntu做的image到ACR肚子內
docker push /aci-tutorial-app:v3
https://ithelp.ithome.com.tw/upload/images/20181019/20025481TSTgV1Sw1B.png

推送完成並從ACR上來看容器已經有此份v3的映像檔
https://ithelp.ithome.com.tw/upload/images/20181019/20025481aIk9bxXXQr.png

終於要在透過ACI建立私有的image來部署了...上述的登入資訊在ACR的金鑰上
https://ithelp.ithome.com.tw/upload/images/20181019/20025481mjHszDwxnQ.png

設置驗證完成就部署吧!
https://ithelp.ithome.com.tw/upload/images/20181019/20025481TC53XGoTn8.png

蝦毀...部署失敗...這我已經試了兩三次確定資訊無誤啊
https://ithelp.ithome.com.tw/upload/images/20181019/20025481hb3qMVOyUy.png

沒關係來用昨天的WebApps在容器服務指定ACR選取剛剛推送上去的Image並存檔
https://ithelp.ithome.com.tw/upload/images/20181019/20025481ItOe9MYr3G.png

網頁顯示正常就是這Image!
https://ithelp.ithome.com.tw/upload/images/20181019/20025481c81RBbQ3Af.png

改試試剛剛錯誤部署可以按下重新部署改為自訂欄位來呈現,其實也沒有啥好改的..
https://ithelp.ithome.com.tw/upload/images/20181019/20025481IQPHc4g2Lp.png

好吧!狀況錯誤相同...可能還是有哪個精細的環節沒做好,流程大致如此,先這樣了
https://ithelp.ithome.com.tw/upload/images/20181019/20025481NSogXLON4X.png

可惡就差一步....先這樣,再來查查是哪裡的問題找到再來更新,81


上一篇
容器式網站不求人,Azure WebApps for containers 實驗給你看
下一篇
Azure WebApps 玩轉技巧首篇-OAuth Google驗證,網站程式雲端硬碟同步,記得備份阿
系列文
玩轉 Azure 於指尖隨心所欲32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言