Deploy a C# & .NET Core Website to Kubernetes in 5 Minutes with Jetpack.io
In this tutorial, we'll build an ASP.NET Core website in C#, configure it for Jetpack.io, and deploy it to Kubernetes – all in 5 minutes.
.NET is required to scaffold the website.
If you don't have it already, download dotnet sdk from Microsoft.
Docker is required to package your backend as a container before deploying to the cloud.
If you don't already have Docker installed as part of your development environment, follow one of the guides below before returning to this quickstart:
kubectl, while not required, is a useful tool for inspecting and managing your deployments in Kubernetes. We recommend following the installation directions for your platform:
Building a C# and .NET App
In this example we'll quickly scaffold an ASP.NET Core MVC application. You could swap out these steps with use an existing ASP.NET Core web site, or scaffold a site using Razor Pages, Web API, or Minimal APIs.
Open Visual Studio
If the new project dialog doesn't open automatically, choose File -> New Project.
Choose ASP.NET (Model, View, Controller) and click next.
Choose a good name for this project, and save to a convenient directory.
In the Additional Information section, check Enable Docker then click Create.
You must have Docker Desktop installed for this function to work correctly.
Now we have a regular ASP.NET website. Feel free to customize this site to meet your needs.
Configure the App for Jetpack.io
Jetpack.io assumes your web server is running on port
8080, but the default project in ASP.NET runs on port
80. In this section we'll change the Dockerfile to run the web site on port
In the Solution Explorer, open Dockerfile.
Remove the 2
EXPOSElines and add a new
- EXPOSE 80
- EXPOSE 443
+ EXPOSE 8080
Just under the
EXPOSEline, add the environment variable telling ASP.NET Core to run on port
ENV ASPNETCORE_URLS http://+:8080
+tells ASP.NET to listen on all interfaces rather than just localhost.
Save and close the Dockerfile.
In Windows Explorer, move the Dockerfile from the project directory up 1 level to the Solution directory.
Jetpack.io assumes the Dockerfile is in your root directory.
Initialize the project with Jetpack.io
Jetpack.io needs some initial configuration to understand the ASP.NET web server. We need only do this once per website.
To install the Jetpack CLI, open a terminal and run
curl https://get.jetpack.io -fsSL | bash
Jetpack CLI works on Linux, macOS, and on Windows via WSL2.
Login to Jetpack CLI:
jetpack auth login
Logging into Jetpack allows you to deploy to the Jetpack.io Kubernetes cluster. You can also run on your own cluster in your Azure, AWS, GCP, or private cloud account.
Initialize the project for Jetpack:
This wizard interviews you and configures the Jetpack deployment strategy to match your application.
Answer that Yes, this is a web server. This tells Jetpack that we want to accept inbound traffic.
If we were building a scheduled cron job or a function that drained a queue, we could answer no.
- Finish the wizard, and Jetpack CLI automatically generates an appropriate
jetconfig.yamlfile. You should commit this to source control.
Deploy to Kubernetes using Jetpack.io
Now that the project is configured for Jetpack, deploying is really easy.
Open a terminal in the directory with the Dockerfile and jetconfig.yaml file.
Deploy to Kubernetes:
Now Jetpack makes the deployment really simple. Automatically it will:
- Build the Docker image
- Push the image to a private registry
- Schedule the necessary Kubernetes resources
- Create a publicly routable URL to test the website
- Setup port-forwarding from your local machine
- Stream application logs back to the terminal
Test the website:
In the console output will be the publicly routable URL. Click this URL to view the web page.
Jetpack also sets up port-forwarding, so you can also browse to http://localhost:8080/ to view the page.
It's easy to deploy an ASP.NET app built with C# to Kubernetes with Jetpack.io. In this tutorial we scaffolded a website, configured it for Jetpack.io, and used Jetpack.io to deploy to Kubernetes. Jetpack.io is a great zero-DevOps solution for deploying to Kubernetes. Visit https://jetpack.io/docs/ to learn more and to start deploying your content to Kubernetes with ease.