一键制作镜像并发布到k8s

2019/04/10 10:10
阅读数 20

 

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应用

image

项目名称取名: testimage

image

选择模板: Web应用程序

image

创建完成 如下图:

image

安装了AntDeploy插件后 点击右键 找到 AntDeploy

image

点击 AntDeploy 出现

image

配置AntDeploy【只需要首次配置】

点击发布配置

image

AntDeploy的配置说明:一个环境对应多台服务器

创建1个环境 取名叫 test 点击 添加环境按钮

image

然后在 test 环境下 添加linux服务器

image

选择 Docker发布, 选择我们刚刚创建的环境 test

image

image

选择 配置镜像上传 填写阿里云容器镜像服务的参数

image

image

因为我们是测试,没有在项目里面添加Dockerfile 那么AntDeploy会创建默认的Dockfile 默认的Dockefile内容会在 发布日志里面进行展示

点击 发布进行一键制作 docker image 并且上传到阿里镜像仓库

image

完成进度展示:

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:\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|Serverssh connecting 192.168.159.135...   
11:54:26|INFO|ServerConnected to root@192.168.159.135:22 via SSH  
11:54:26|INFO|ServerChanged directory to antdeploy/testimage/20200308115416/  
11:54:26|INFO|Serveruploaded 100 %  
11:54:27|INFO|Serverunzip -o -q antdeploy/testimage/20200308115416/publish.zip -d publish/  
11:54:27|INFO|Serverunzip success: antdeploy/testimage/20200308115416/publish/  
11:54:27|INFO|ServerdockerFile not found in: [antdeploy/testimage/20200308115416/publish/Dockerfile],will create default Dockerfile!  
11:54:27|INFO|Servercreate docker file: antdeploy/testimage/20200308115416/publish/Dockerfile  
11:54:27|INFO|ServerFROM mcr.microsoft.com/dotnet/core/aspnet:2.2  
11:54:27|INFO|ServerCOPY . /publish  
11:54:27|INFO|ServerWORKDIR /publish  
11:54:27|INFO|ServerENV ASPNETCORE_URLS=http://*:5000  
11:54:27|INFO|ServerEXPOSE 5000  
11:54:27|INFO|ServerENTRYPOINT ["dotnet", "testimage.dll"]  
11:54:27|INFO|Servercreate docker file success: antdeploy/testimage/20200308115416/publish/Dockerfile  
11:54:27|INFO|ServerStart Copy Files From [antdeploy/testimage/20200308115416/publish/] To [antdeploy/testimage/deploy/]  
11:54:27|INFO|ServerSuccess Copy Files From [antdeploy/testimage/20200308115416/publish/] To [antdeploy/testimage/deploy/]  
11:54:27|INFO|ServerChanged directory to antdeploy/testimage/deploy/  
11:54:27|INFO|Serverdocker build --no-cache --rm -t testimage:20200308115416 -f antdeploy/testimage/deploy/Dockerfile antdeploy/testimage/deploy/   
11:54:27|INFO|ServerSending build context to Docker daemon  4.688MB  
11:54:27|INFO|ServerStep 1/6 : FROM mcr.microsoft.com/dotnet/core/aspnet:2.2  
11:54:27|INFO|Server ---> e7e3b238011c  
11:54:27|INFO|ServerStep 2/6 : COPY . /publish  
11:54:27|INFO|Server ---> 77f1a71e747e  
11:54:27|INFO|ServerStep 3/6 : WORKDIR /publish  
11:54:27|INFO|Server ---> Running in 0488ac2f9d34  
11:54:27|INFO|ServerRemoving intermediate container 0488ac2f9d34  
11:54:27|INFO|Server ---> 52cace207336  
11:54:27|INFO|ServerStep 4/6 : ENV ASPNETCORE_URLS=http://*:5000  
11:54:27|INFO|Server ---> Running in 6002963328d2  
11:54:28|INFO|ServerRemoving intermediate container 6002963328d2  
11:54:28|INFO|Server ---> 30ef31b36b85  
11:54:28|INFO|ServerStep 5/6 : EXPOSE 5000  
11:54:28|INFO|Server ---> Running in 76a1ba895e97  
11:54:28|INFO|ServerRemoving intermediate container 76a1ba895e97  
11:54:28|INFO|Server ---> a0be298ccf70  
11:54:28|INFO|ServerStep 6/6 : ENTRYPOINT ["dotnet", "testimage.dll"]  
11:54:28|INFO|Server ---> Running in c81d0ec0a693  
11:54:28|INFO|ServerRemoving intermediate container c81d0ec0a693  
11:54:28|INFO|Server ---> 1c1fa6c51b6e  
11:54:28|INFO|ServerSuccessfully built 1c1fa6c51b6e  
11:54:28|INFO|ServerSuccessfully tagged testimage:20200308115416  
11:54:28|WARN|Serverignore 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.135centos End  
11:54:34|INFO|Deploy Version20200308115416  
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被成功的上传了

image

在阿里云镜像仓库可以查到

image

下篇介绍会继续介绍

  • 镜像上传到仓库后如何手动在k8s进行快速部署
  • 有了镜像后如何在k8s进行快速部署

原文出处:https://www.cnblogs.com/yudongdong/p/12441855.html

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部