一鍵製作鏡像並發布到k8s
- 2020 年 3 月 8 日
- 筆記
Antdeploy是我開發的一款開源一鍵部署工具,支援將.net應用(支援netcore)一鍵部署到遠程伺服器,並支援以下3種部署方案
- 支援docker一鍵部署(支援netcore)
- 支援iis一鍵部署(支援netcore和framework)
- 支援windows服務一鍵部署(支援netcore和framework)
- (支援增量發布)(支援一鍵回滾)(支援點火)(支援選擇特定文件發布)(支援查看發布記錄)
- 支援脫離Visual Studio獨立使用(跨平台支援windows系統和mac系統)
最近我在研究k8s,最近新增了關於k8s的功能目的是將AntDeploy應用到k8s的應用一鍵部署上面
配合k8s的新需求點
- 如何將本地應用一鍵打包成docker鏡像並上傳到鏡像倉庫
- 有了鏡像後如何在k8s進行快速部署
- 如何利用AntDeploy一鍵完成上面2步驟!
本篇介紹 如何一鍵打包成docker鏡像並上傳到鏡像倉庫
本篇演示環境:
- vs2019 並且安裝了 AntDeploy插件
- 本地有一個虛擬機centos7 並且 安裝了docker
本篇應用目標:
- 創建一個 netcore web應用
- 一鍵部署鏡像並上傳到阿里雲的鏡像倉庫
- 在k8s的dashbord上deploy應用
創建一個netcore web應用
項目名稱取名: testimage
選擇模板: Web應用程式
創建完成 如下圖:
安裝了AntDeploy插件後 點擊右鍵 找到 AntDeploy
點擊 AntDeploy 出現
配置AntDeploy【只需要首次配置】
點擊發布配置
AntDeploy的配置說明:一個環境對應多台伺服器
創建1個環境 取名叫 test 點擊 添加環境按鈕
然後在 test 環境下 添加linux伺服器
選擇 Docker發布, 選擇我們剛剛創建的環境 test
選擇 配置鏡像上傳 填寫阿里雲容器鏡像服務的參數
因為我們是測試,沒有在項目裡面添加Dockerfile 那麼AntDeploy會創建默認的Dockfile 默認的Dockefile內容會在 發布日誌裡面進行展示
點擊 發布進行一鍵製作 docker image 並且上傳到阿里鏡像倉庫
完成進度展示:
發布日誌非常詳細:
11:54:11|INFO|The Porject ENTRYPOINT name:testimage.dll,DotNetSDK.Version:2.2 11:54:11|INFO|-----------------Start publish[Ver:7.10]----------------- 11:54:11|INFO|Visual Studio Version : 16.0 11:54:11|INFO|CurrentProjectFolder: file://C:UsersAdministratorsourcerepostestimagetestimage#link4 11:54:11|INFO|current project Path:C:UsersAdministratorsourcerepostestimagetestimagetestimage.csproj 11:54:11|INFO|dotnet publish "C:UsersAdministratorsourcerepostestimagetestimagetestimage.csproj" -c Release -o "C:UsersAdministratorsourcerepostestimagetestimagebinReleasedeploy_dockertest" 11:54:12|INFO|版權所有(C) Microsoft Corporation。保留所有權利。 11:54:12|INFO| C:UsersAdministratorsourcerepostestimagetestimagetestimage.csproj 的還原在 44.05 ms 內完成。 11:54:12|INFO| C:UsersAdministratorsourcerepostestimagetestimagetestimage.csproj 的還原在 44.05 ms 內完成。 11:54:15|INFO| testimage -> C:UsersAdministratorsourcerepostestimagetestimagebinReleasenetcoreapp2.2testimage.dll 11:54:15|INFO| testimage -> C:UsersAdministratorsourcerepostestimagetestimagebinReleasenetcoreapp2.2testimage.Views.dll 11:54:15|INFO| testimage -> C:UsersAdministratorsourcerepostestimagetestimagebinReleasenetcoreapp2.2testimage.Views.dll 11:54:15|INFO| testimage -> C:UsersAdministratorsourcerepostestimagetestimagebinReleasedeploy_dockertest 11:54:16|INFO| testimage -> C:UsersAdministratorsourcerepostestimagetestimagebinReleasedeploy_dockertest 11:54:16|INFO|publish success ==> file://C:UsersAdministratorsourcerepostestimagetestimagebinReleasedeploy_dockertest#link15 11:54:16|INFO|-----------------Start package----------------- 11:54:16|INFO|package ignoreList Count:0 11:54:16|INFO|package success,package size:<1M 11:54:16|INFO|-----------------Deploy Start----------------- 11:54:16|INFO|【Server】ssh connecting 192.168.159.135... 11:54:26|INFO|【Server】Connected to [email protected]:22 via SSH 11:54:26|INFO|【Server】Changed directory to antdeploy/testimage/20200308115416/ 11:54:26|INFO|【Server】uploaded 100 % 11:54:27|INFO|【Server】unzip -o -q antdeploy/testimage/20200308115416/publish.zip -d publish/ 11:54:27|INFO|【Server】unzip success: antdeploy/testimage/20200308115416/publish/ 11:54:27|INFO|【Server】dockerFile not found in: [antdeploy/testimage/20200308115416/publish/Dockerfile],will create default Dockerfile! 11:54:27|INFO|【Server】create docker file: antdeploy/testimage/20200308115416/publish/Dockerfile 11:54:27|INFO|【Server】FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 11:54:27|INFO|【Server】COPY . /publish 11:54:27|INFO|【Server】WORKDIR /publish 11:54:27|INFO|【Server】ENV ASPNETCORE_URLS=http://*:5000 11:54:27|INFO|【Server】EXPOSE 5000 11:54:27|INFO|【Server】ENTRYPOINT ["dotnet", "testimage.dll"] 11:54:27|INFO|【Server】create docker file success: antdeploy/testimage/20200308115416/publish/Dockerfile 11:54:27|INFO|【Server】Start Copy Files From [antdeploy/testimage/20200308115416/publish/] To [antdeploy/testimage/deploy/] 11:54:27|INFO|【Server】Success Copy Files From [antdeploy/testimage/20200308115416/publish/] To [antdeploy/testimage/deploy/] 11:54:27|INFO|【Server】Changed directory to antdeploy/testimage/deploy/ 11:54:27|INFO|【Server】docker build --no-cache --rm -t testimage:20200308115416 -f antdeploy/testimage/deploy/Dockerfile antdeploy/testimage/deploy/ 11:54:27|INFO|【Server】Sending build context to Docker daemon 4.688MB 11:54:27|INFO|【Server】Step 1/6 : FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 11:54:27|INFO|【Server】 ---> e7e3b238011c 11:54:27|INFO|【Server】Step 2/6 : COPY . /publish 11:54:27|INFO|【Server】 ---> 77f1a71e747e 11:54:27|INFO|【Server】Step 3/6 : WORKDIR /publish 11:54:27|INFO|【Server】 ---> Running in 0488ac2f9d34 11:54:27|INFO|【Server】Removing intermediate container 0488ac2f9d34 11:54:27|INFO|【Server】 ---> 52cace207336 11:54:27|INFO|【Server】Step 4/6 : ENV ASPNETCORE_URLS=http://*:5000 11:54:27|INFO|【Server】 ---> Running in 6002963328d2 11:54:28|INFO|【Server】Removing intermediate container 6002963328d2 11:54:28|INFO|【Server】 ---> 30ef31b36b85 11:54:28|INFO|【Server】Step 5/6 : EXPOSE 5000 11:54:28|INFO|【Server】 ---> Running in 76a1ba895e97 11:54:28|INFO|【Server】Removing intermediate container 76a1ba895e97 11:54:28|INFO|【Server】 ---> a0be298ccf70 11:54:28|INFO|【Server】Step 6/6 : ENTRYPOINT ["dotnet", "testimage.dll"] 11:54:28|INFO|【Server】 ---> Running in c81d0ec0a693 11:54:28|INFO|【Server】Removing intermediate container c81d0ec0a693 11:54:28|INFO|【Server】 ---> 1c1fa6c51b6e 11:54:28|INFO|【Server】Successfully built 1c1fa6c51b6e 11:54:28|INFO|【Server】Successfully tagged testimage:20200308115416 11:54:28|WARN|【Server】ignore docker run 11:54:28|WARN|【Server】[upload image] - Login Succeeded 11:54:28|WARN|【Server】[upload image] - The push refers to repository [registry.cn-hangzhou.aliyuncs.com/lito/testimage] 11:54:28|WARN|【Server】[upload image] - a3dea8cda1bb: Preparing 11:54:28|WARN|【Server】[upload image] - 579a8f1d6a12: Preparing 11:54:28|WARN|【Server】[upload image] - 15e45d99c926: Preparing 11:54:28|WARN|【Server】[upload image] - 0cf75cb98eb2: Preparing 11:54:28|WARN|【Server】[upload image] - 814c70fdae62: Preparing 11:54:31|WARN|【Server】[upload image] - 0cf75cb98eb2: Mounted from lito/spa 11:54:31|WARN|【Server】[upload image] - 814c70fdae62: Mounted from lito/spa 11:54:31|WARN|【Server】[upload image] - 15e45d99c926: Mounted from lito/spa 11:54:31|WARN|【Server】[upload image] - 579a8f1d6a12: Mounted from lito/spa 11:54:32|WARN|【Server】[upload image] - a3dea8cda1bb: Pushed 11:54:34|WARN|【Server】[upload image] - 20200308115416: digest: sha256:892c1994a969fcc613d300590754bb8ddee0fb8f75e9614a097a7f482fa5d38e size: 1374 11:54:34|INFO|【Server】[upload image] - Success 11:54:34|INFO|publish Host: 192.168.159.135【centos】 End 11:54:34|INFO|Deploy Version:20200308115416 11:54:34|INFO|local publish folder ==> file://C:UsersAdministratorsourcerepostestimagetestimagebinReleasedeploy_dockertest#link79 11:54:34|INFO|-----------------Deploy End,[Total]:1,[Fail]:0----------------- 11:54:34|INFO|【Deploy log】 ==> file://C:UsersAdministratorsourcerepostestimagetestimagebinReleasedeploy_dockertest_deploy_logs20200308115416.log#link81
從日誌裡面可以看到,docker image被成功的上傳了
在阿里雲鏡像倉庫可以查到
下篇介紹會繼續介紹
- 鏡像上傳到倉庫後如何手動在k8s進行快速部署
- 有了鏡像後如何在k8s進行快速部署