ASP.Net core 容器开发docker kubernetes部署
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
一、系统环境
windows10
Visual Studio 2019
.ASP.Net core 3.1
Docker Desktop
二、步骤
1、创建ASP.NET core新项目,Visual Studio 2019->创建新项目->ASP.NET Core Web 应用程序->选中 启用Docker支持 ->创建
启用Docker支持后,可以选择目标平台是Linux或windows,决定生成docker镜像的基本内核。
创建方案后,可以看到包含了dockerfile文件,其内容如下,描述创建镜像过程
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["MvcMovie.csproj", ""]
RUN dotnet restore "./MvcMovie.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "MvcMovie.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MvcMovie.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MvcMovie.dll"]
2、创建镜像
编码测试完成后,可以选择 Docker 运行
Visual Studio 2019会自动生成目标镜并在本地docker中运行
3、将docker 镜像发布至hub.docker.com
在解决方案上右键->发布,根据提示输入hub.docker.com上注册的用户名和密码,设置tag标签默认为latest,然后按发布,Visual Studio会自动将镜像上传至hub.docker.com
4、使用
在Docker中使用,直接pull 就可以使用
在Kubernetes中使用需先编辑.yaml文件
一个Web MvcMovie的.yam示例l文件如下
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: hrsoft-web
name: web-mvcmovie
annotations:
k8s.eip.work/workload: web-mvcmovie
k8s.eip.work/displayName: web-mvcmovie
k8s.eip.work/service: ClusterIP
k8s.eip.work/ingress: 'true'
labels:
k8s.eip.work/layer: web
k8s.eip.work/name: web-mvcmovie
spec:
selector:
matchLabels:
k8s.eip.work/layer: web
k8s.eip.work/name: web-mvcmovie
template:
metadata:
labels:
k8s.eip.work/layer: web
k8s.eip.work/name: web-mvcmovie
spec:
imagePullSecrets:
- {}
initContainers: []
containers:
- image: 'zhoujy2hrsoft/mvcmovie'
imagePullPolicy: Always
name: web-mvcmovie
volumeMounts: []
resources: {}
env: []
volumes: []
replicas: 1
---
apiVersion: v1
kind: Service
metadata:
namespace: hrsoft-web
name: web-mvcmovie
annotations:
k8s.eip.work/workload: web-mvcmovie
k8s.eip.work/displayName: web-mvcmovie
labels:
k8s.eip.work/layer: web
k8s.eip.work/name: web-mvcmovie
spec:
selector:
k8s.eip.work/layer: web
k8s.eip.work/name: web-mvcmovie
type: ClusterIP
ports:
- port: 80
targetPort: 80
protocol: TCP
name: mawfrp
nodePort: 0
其在Kubernetes中的运行情况如下
参考文档:
https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/docker/?view=aspnetcore-3.1
GitHub 加速计划 / li / linux-dash
6
1
下载
A beautiful web dashboard for Linux
最近提交(Master分支:3 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献2条内容
所有评论(0)