Dapr + .NET Core实战(十-终篇)K8S运行Dapr

Dapr + .NET Core实战(十-终篇)K8S运行Dapr

为了实现在k8s上安装DaprDapr需要部署dapr-sidecar-injector、dapr-operator、dapr-placement和dapr-sentry服务。 

dapr-operator: 管理组件(state stores, pub/subs, etc.)

dapr-sidecar-injector: 将 Dapr 注入  pods,并添加环境变量 DAPR_HTTP_PORT 和 DAPR_GRPC_PORT,以使用户定义的应用程序能够轻松地与 Dapr Sidecar通信,而无需硬编码 Dapr 端口值。

dapr-placement: 将 actor 实例映射到 pods。

dapr-sentry: 管理服务之间的mTLS并作为证书颁发机构。 

2.安装K8s集群

通常使用以下方法本地安装的K8S集群

k8s-for-docker-desktop

kubeadm

我本地已经安装好了这两种,这次使用kubeadm 1.20版本演示dapr

Dapr + .NET Core实战(十-终篇)K8S运行Dapr

 3.将Frontend和Backend build成docker Image

vs中分别右击Frontend和Backend,添加Docker支持,即可生成对应的Dockerfile,修改暴露端口

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base WORKDIR /app EXPOSE 5001 FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build WORKDIR /src COPY ["FrontEnd/FrontEnd.csproj", "FrontEnd/"] RUN dotnet restore "FrontEnd/FrontEnd.csproj" COPY . . WORKDIR "/src/FrontEnd" RUN dotnet build "FrontEnd.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "FrontEnd.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "FrontEnd.dll"]

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwywdg.html