iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 13
1

今天的筆記要來介紹應用程式升級, 以下的簡單幾個步驟可以完成應用程式的升級與部署.

Kubernetes 中的應用程式升級

  1. 使用命令 code C:\k8s\dotnet-docker\samples\aspnetapp\aspnetapp\Views\Home\About.cshtml, 修改 About page 原始碼 (加入第 6 行)
<div><h1 class="display-4">@Environment.MachineName</h1></div>

https://ithelp.ithome.com.tw/upload/images/20181024/201118710ngVZObeCK.png
2. 使用命令 docker build . -t 15maksacr.azurecr.io/aspnetapp:v2 重新編譯 image, 並且指派 tag: aspnetapp:v2

PS C:\k8s\dotnet-docker\samples\aspnetapp>  docker build . -t 15maksacr.azurecr.io/a
spnetapp:v2
Sending build context to Docker daemon  2.469MB
Step 1/12 : FROM microsoft/dotnet:2.1-sdk AS build
 ---> efa6f1f55357
Step 2/12 : WORKDIR /app
 ---> Using cache
 ---> 4e06e9e16269
Step 3/12 : COPY *.sln .
 ---> Using cache
 ---> 57ed7afde34f
Step 4/12 : COPY aspnetapp/*.csproj ./aspnetapp/
 ---> Using cache
 ---> 1039eace2122
Step 5/12 : RUN dotnet restore
 ---> Using cache
 ---> 842f61672f26
Step 6/12 : COPY aspnetapp/. ./aspnetapp/
 ---> 8c6255f8258f
Step 7/12 : WORKDIR /app/aspnetapp
 ---> Running in 52aa12001d28
Removing intermediate container 52aa12001d28
 ---> b89bd8fecabe
Step 8/12 : RUN dotnet publish -c Release -o out
 ---> Running in 6c478e1f2970
Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 452 ms for /app/aspnetapp/aspnetapp.csproj.
  aspnetapp -> /app/aspnetapp/bin/Release/netcoreapp2.1/aspnetapp.dll
  aspnetapp -> /app/aspnetapp/bin/Release/netcoreapp2.1/aspnetapp.Views.dll
  aspnetapp -> /app/aspnetapp/out/
Removing intermediate container 6c478e1f2970
 ---> 2fd74610e0f5
Step 9/12 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime
 ---> 70c1124a9a02
Step 10/12 : WORKDIR /app
 ---> Using cache
 ---> 2d237448f63a
Step 11/12 : COPY --from=build /app/aspnetapp/out ./
 ---> 834717d46153
Step 12/12 : ENTRYPOINT ["dotnet", "aspnetapp.dll"]
 ---> Running in f71260af785d
Removing intermediate container f71260af785d
 ---> d9b92c011931
Successfully built d9b92c011931
Successfully tagged 15maksacr.azurecr.io/aspnetapp:v2
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
  1. 使用命令 docker images 確認 aspnetapp v2 有建立成功
PS C:\k8s\dotnet-docker\samples\aspnetapp> docker images
REPOSITORY                                 TAG                      IMAGE ID            CREATED             SIZE
15maksacr.azurecr.io/aspnetapp             v2                       d9b92c011931        49 seconds ago      257MB
<略…>
  1. 使用命令 az acr login -n 15maksacr 登入 Azure Container Registry (ACR)
PS C:\k8s\dotnet-docker\samples\aspnetapp> az acr login -n 15maksacr
Login Succeeded
  1. 使用命令 docker push 15maksacr.azurecr.io/aspnetapp:v2 將 image 推送到 ACR 中
PS C:\k8s\dotnet-docker\samples\aspnetapp> docker push 15maksacr.azurecr.io/aspnetapp:v2
The push refers to repository [15maksacr.azurecr.io/aspnetapp]
41ed3afe8148: Pushed
cd1be85f4c90: Layer already exists
d00d2c8144b6: Layer already exists
108fa49df6c1: Layer already exists
ddd4c04722d5: Layer already exists
8b15606a9e3e: Layer already exists
v2: digest: sha256:67486f49131a12b5c554a157fc80dc20ba1a89d17bdb99b9b0195c200783539e size: 1580
  1. 使用 VS Code 修改 deployment yaml 檔案 code .\aspnetapp-deployment.yml
    https://ithelp.ithome.com.tw/upload/images/20181024/201118710u9F75N69H.png
  2. 使用命令 kubectl apply -f .\aspnetapp-deployment.yml 部署 image 到 Azure Kubernetes Service (AKS) 上
PS C:\k8s\dotnet-docker\samples\aspnetapp> kubectl apply -f .\aspnetapp-deployment.y
ml
deployment.apps "aspnetapp-deployment" created
service "aspnetapp-service" created
  1. 使用命令 kubectl get svc 確認 Public IP
    https://ithelp.ithome.com.tw/upload/images/20181024/20111871gfuYdHMO0M.png
  2. 開啟 Browser 連線到 http://104.215.179.189/Home/About 測試結果
    https://ithelp.ithome.com.tw/upload/images/20181024/20111871eBi3neAePQ.png

以上便完成了更新應用程式囉!


上一篇
Day 12 - 升級 Azure Kubernetes Service (AKS) 叢集
下一篇
Day 14 - 使用 Kubernetes Dashboard
系列文
15 分鐘學習系列 - 第一次學 Kubernetes 就上手30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言