Skip to main content

ASP.NET Core on CloudFlow

Learn how to run a sample ASP.NET Core app at the edge for low latency and high availability. You can use our repo as a template, or perform the steps yourself using the Kubernetes dashboard or kubectl commands.

Step by Step

Following are step-by-step instructions to deploy a ASP.NET Core sample application to the edge on CloudFlow. We'll Dockerize it, and deploy it on CloudFlow.

Prerequisites

  • You need Docker installed so that you can build a docker image.

Create the ASP.NET Core App

Create a new directory for your app.

mkdir my-aspnetcore-app
cd my-aspnetcore-app

Download or clone the Microsoft ASP.NET Core dotnet/dotnet-docker repository from GitHub.

Then place the contents of the aspnetapp directory in your my-aspnetcore-app directory.

Dockerize It

Let's build the container image that we'll deploy to CloudFlow. First make a Dockerfile in your directory with the following content.

Dockerfile
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY aspnetapp/*.csproj .
RUN dotnet restore --use-current-runtime

# copy everything else and build app
COPY aspnetapp/. .
RUN dotnet publish -c Release -o /app --use-current-runtime --self-contained false --no-restore

# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build /app .
EXPOSE 80
ENTRYPOINT ["dotnet", "aspnetapp.dll"]

Build and tag it.

docker build . -t ghcr.io/YOUR_GITHUB_USERNAME/my-aspcorenet-app:prod

Launch it locally to test it.

docker run -p 8000:80 ghcr.io/YOUR_GITHUB_USERNAME/my-aspcorenet-app:prod
curl http://localhost:8000

Push It

Push it to GitHub Packages. This makes it available to CloudFlow.

docker push ghcr.io/YOUR_GITHUB_USERNAME/my-aspcorenet-app:prod

Be sure to make it public. To see your packages and make this change, visit https://github.com/YOUR_GITHUB_USERNAME?tab=packages

Deploy It

Next, use the Create Project command in the CloudFlow Console in order to deploy your new container. Use the image name ghcr.io/YOUR_GITHUB_USERNAME/my-aspnetcore-app:prod with port 8000.

See the pods running on CloudFlow's network with either the Kubernetes dashboard or kubectl get pods -o wide. The -o wide switch shows where your app is running according to the default AEE location optimization strategy. Your app will be optimally deployed according to traffic. In lieu of significant traffic, your deployment will be made to default locations.

Try kubectl logs POD to see the log message reporting that the server is listening on port 8000:

info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:80
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app

Finally, follow the instructions that configure DNS and TLS.

See What You've Built

See the sample app you've built by visiting the https://YOUR.DOMAIN.COM, substituting YOUR.DOMAIN.COM according to your DNS and HTTPS configuration.