Skip to main content

Deploy Containerized Web Applications using the native Azure Provider, .NET 5, and C# 9

An example of deploying web apps to App Service and AKS with C# 9 and .NET 5

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set azure-cs-net5-aks-webapp
cd pulumi-examples/azure-cs-net5-aks-webapp

The example demonstrate several Pulumi features:

  • Azure-Native provider
  • Running on .NET 5
  • Using C# 9 constructs like top-level statements, implicit constuctors, and records
  • Defining and using components with Pulumi

Adjust the code#

This example can cover several deployments architectures that are listed below.

Public Docker Image to Azure App Service#

You can deploy any public Docker image that contains a web application listening to port 80 to an Azure App Service. Modify the constructor of MyStack class in Program.cs file to

public MyStack()
{
var app = new WebApplication("hello", new()
{
DockerImage = "strm/helloworld-http"
});
this.Endpoint = app.Endpoint;
}

Custom Application to Azure App Service#

Builds a Docker container from the files in app folder, push it to Azure Container Registry, and deploy it to an Azure App Service. Modify the constructor of MyStack class in Program.cs file to

public MyStack()
{
var app = new WebApplication("hello", new()
{
AppFolder = "./app"
});
this.Endpoint = app.Endpoint;
}

Public Docker Image to Azure Kubernetes Service#

You can deploy any public Docker image that contains a web application listening to port 80 to a new AKS cluster. Modify the constructor of MyStack class in Program.cs file to

public MyStack()
{
var cluster = new AksCluster("demoaks");
var app = new WebApplication("hello", new()
{
Cluster = cluster,
DockerImage = "strm/helloworld-http"
});
this.Endpoint = app.Endpoint;
}

Custom Application to Azure Kubernetes Service#

Builds a Docker container from the files in app folder, push it to Azure Container Registry, and deploy it to a new AKS cluster. Modify the constructor of MyStack class in Program.cs file to

public MyStack()
{
var cluster = new AksCluster("demoaks");
var app = new WebApplication("hello", new()
{
Cluster = cluster,
AppFolder = "./app"
});
this.Endpoint = app.Endpoint;
}

Deploying the App#

To deploy your infrastructure, follow the below steps.

Prerequisites#

  1. Install Pulumi
  2. Configure Azure Credentials

Steps#

After cloning this repo and making adjustments as described above, from this working directory, run these commands:

  1. Create a new stack, which is an isolated deployment target for this example:

    Terminal window
    pulumi stack init dev
  2. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step):

    $ az login
  3. Set the Azure region location to use:

    $ pulumi config set azure-native:location westus2
  4. Stand up the application by invoking pulumi

    Terminal window
    pulumi up
  5. Once you’ve finished experimenting, tear down your stack’s resources by destroying and removing it:

    Terminal window
    pulumi destroy --yes
    pulumi stack rm --yes

Related

The infrastructure as code platform for any cloud.