Skip to content

Reduce the amount of boilerplate required to do an end-to-end app deployment via AddAzureKubernetes that exposes an endpoint with TLS. #17712

Description

@mitchdenny

This is the current minimum:

var builder = DistributedApplication.CreateBuilder(args);

// Parameters for deployment configuration
var acmeEmail = builder.AddParameter("acmeEmail");

// Networking: VNet with subnets for AKS nodes and AGC load balancer
var vnet = builder.AddAzureVirtualNetwork("vnet", "10.1.0.0/16");
var aksSubnet = vnet.AddSubnet("akssubnet", "10.1.0.0/22");
var albSubnet = vnet.AddSubnet("albsubnet", "10.1.4.0/24");

// Azure Kubernetes environment (auto-provisions AKS + ACR + managed identity)
var aks = builder.AddAzureKubernetesEnvironment("aks")
    .WithSubnet(aksSubnet)
    .WithSystemNodePool("Standard_D4as_v5", minCount: 1, maxCount: 5);

var userPool = aks.AddNodePool("userpool", "Standard_D4as_v5", minCount: 1, maxCount: 5);

// Application Gateway for Containers load balancer
var lb = aks.AddLoadBalancer("lb", albSubnet);

// cert-manager with Let's Encrypt HTTP-01
var certManager = aks.AddCertManager("cert-manager");
var issuer = certManager.AddIssuer("letsencrypt")
    .WithLetsEncryptProduction(acmeEmail)
    .WithHttp01Solver();

// Application resources
var cache = builder.AddRedis("cache");

var apiService = builder.AddProject<Projects.test1_ApiService>("apiservice")
    .WithHttpHealthCheck("/health");

var frontend = builder.AddProject<Projects.test1_Web>("webfrontend")
    .WithExternalHttpEndpoints()
    .WithHttpHealthCheck("/health")
    .WithReference(cache)
    .WaitFor(cache)
    .WithReference(apiService)
    .WaitFor(apiService);

// Gateway with TLS via AGC load balancer (uses auto-assigned FQDN)
aks.AddGateway("ingress")
    .WithLoadBalancer(lb)
    .WithRoute("/", frontend.GetEndpoint("http"))
    .WithTls(issuer);

builder.Build().Run();

Compare this with ACA and it is very verbose. Part of that is due to K8S being ultimately flexible and being able to make less assumptions - but is there a way that we can improve this.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions