一键制作镜像并发布到k8s


Antdeploy是我开发的一款开源一键部署工具,支持将.net应用(支持netcore)一键部署到远程服务器,并支持以下3种部署方案

  • 支持docker一键部署(支持netcore)
  • 支持iis一键部署(支持netcore和framework)
  • 支持windows服务一键部署(支持netcore和framework)
  • (支持增量发布)(支持一键回滚)(支持点火)(支持选择特定文件发布)(支持查看发布记录)
  • 支持脱离Visual Studio独立使用(跨平台支持windows系统和mac系统)
github开源源代码地址
插件下载地址
最近我在研究k8s,最近新增了关于k8s的功能目的是将AntDeploy应用到k8s的应用一键部署上面
配合k8s的新需求点
  1. 如何将本地应用一键打包成docker镜像并上传到镜像仓库
  2. 有了镜像后如何在k8s进行快速部署
  3. 如何利用AntDeploy一键完成上面2步骤!
本篇介绍 如何一键打包成docker镜像并上传到镜像仓库 本篇演示环境:
  1. vs2019 并且安装了 AntDeploy插件
  2. 本地有一个虚拟机centos7 并且 安装了docker
本篇应用目标:
  1. 创建一个 netcore web应用
  2. 一键部署镜像并上传到阿里云的镜像仓库
  3. 在k8s的dashbord上deploy应用
创建一个netcore web应用
一键制作镜像并发布到k8s
文章图片

项目名称取名: testimage
一键制作镜像并发布到k8s
文章图片

选择模板: Web应用程序
一键制作镜像并发布到k8s
文章图片

创建完成 如下图:
一键制作镜像并发布到k8s
文章图片

安装了AntDeploy插件后 点击右键 找到 AntDeploy
一键制作镜像并发布到k8s
文章图片

点击 AntDeploy 出现
一键制作镜像并发布到k8s
文章图片

配置AntDeploy【只需要首次配置】
点击发布配置
一键制作镜像并发布到k8s
文章图片

AntDeploy的配置说明:一个环境对应多台服务器
创建1个环境 取名叫 test 点击 添加环境按钮
一键制作镜像并发布到k8s
文章图片

然后在 test 环境下 添加linux服务器
一键制作镜像并发布到k8s
文章图片

选择 Docker发布, 选择我们刚刚创建的环境 test
一键制作镜像并发布到k8s
文章图片

一键制作镜像并发布到k8s
文章图片

选择 配置镜像上传 填写阿里云容器镜像服务的参数
一键制作镜像并发布到k8s
文章图片

一键制作镜像并发布到k8s
文章图片

因为我们是测试,没有在项目里面添加Dockerfile 那么AntDeploy会创建默认的Dockfile 默认的Dockefile内容会在 发布日志里面进行展示
点击 发布进行一键制作 docker image 并且上传到阿里镜像仓库
一键制作镜像并发布到k8s
文章图片

完成进度展示:
一键制作镜像并发布到k8s
文章图片

发布日志非常详细:
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:\Users\Administrator\source\repos\testimage\testimage#link4 11:54:11|INFO|current project Path:C:\Users\Administrator\source\repos\testimage\testimage\testimage.csproj 11:54:11|INFO|dotnet publish "C:\Users\Administrator\source\repos\testimage\testimage\testimage.csproj" -c Release -o "C:\Users\Administrator\source\repos\testimage\testimage\bin\Release\deploy_docker\test\" 11:54:12|INFO|版权所有(C) Microsoft Corporation。保留所有权利。 11:54:12|INFO|C:\Users\Administrator\source\repos\testimage\testimage\testimage.csproj 的还原在 44.05 ms 内完成。 11:54:12|INFO|C:\Users\Administrator\source\repos\testimage\testimage\testimage.csproj 的还原在 44.05 ms 内完成。 11:54:15|INFO|testimage -> C:\Users\Administrator\source\repos\testimage\testimage\bin\Release\netcoreapp2.2\testimage.dll 11:54:15|INFO|testimage -> C:\Users\Administrator\source\repos\testimage\testimage\bin\Release\netcoreapp2.2\testimage.Views.dll 11:54:15|INFO|testimage -> C:\Users\Administrator\source\repos\testimage\testimage\bin\Release\netcoreapp2.2\testimage.Views.dll 11:54:15|INFO|testimage -> C:\Users\Administrator\source\repos\testimage\testimage\bin\Release\deploy_docker\test\ 11:54:16|INFO|testimage -> C:\Users\Administrator\source\repos\testimage\testimage\bin\Release\deploy_docker\test\ 11:54:16|INFO|publish success==>file://C:\Users\Administrator\source\repos\testimage\testimage\bin\Release\deploy_docker\test#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 root@192.168.159.135: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 daemon4.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:\Users\Administrator\source\repos\testimage\testimage\bin\Release\deploy_docker\test#link79 11:54:34|INFO|-----------------Deploy End,[Total]:1,[Fail]:0----------------- 11:54:34|INFO|【Deploy log】 ==>file://C:\Users\Administrator\source\repos\testimage\testimage\bin\Release\deploy_docker\test_deploy_logs\20200308115416.log#link81

从日志里面可以看到,docker image被成功的上传了
一键制作镜像并发布到k8s
文章图片

在阿里云镜像仓库可以查到
【一键制作镜像并发布到k8s】一键制作镜像并发布到k8s
文章图片

下篇介绍会继续介绍
  • 镜像上传到仓库后如何手动在k8s进行快速部署
  • 有了镜像后如何在k8s进行快速部署

    推荐阅读