Containerized applications have become an important part of modern cloud development. Developers use containers to package applications and their dependencies, making them easier to build, test, deploy, and scale across different environments.
When an application grows, managing individual containers becomes more complicated. Teams need a platform to schedule containers, manage workloads, handle networking, and recover from failures.
Azure Kubernetes Service (AKS) provides a managed Kubernetes platform for running containerized applications on Azure.
Provisioning an AKS cluster traditionally involves writing Bicep or ARM templates, using Azure CLI commands, or managing infrastructure through other Infrastructure as Code tools. Developers who primarily work with C# may prefer defining infrastructure using familiar .NET classes instead of maintaining separate template files.
The Azure Provisioning library for .NET addresses this requirement. It allows developers to describe Azure infrastructure declaratively using C# and strongly typed resource models.
Microsoft provides the Azure.Provisioning.ContainerService package specifically for Azure Kubernetes Service and related container-service resources.
In this article, we will explore the Azure Provisioning library, install the ContainerService package, define an AKS cluster using C#, configure its system node pool and managed identity, understand the generated infrastructure model, and prepare the deployment workflow.
1. What Is Azure Kubernetes Service?
Azure Kubernetes Service is a managed Kubernetes service provided by Microsoft Azure.
Kubernetes is an open-source container orchestration platform. It manages containerized workloads across a group of machines called nodes.
Instead of manually starting and managing containers on individual servers, Kubernetes provides mechanisms for deploying, scheduling, scaling, and recovering application workloads.
AKS reduces the operational effort involved in managing Kubernetes infrastructure by handling important control-plane responsibilities.
Consider an application with several services:
- Customer API.
- Order processing service.
- Payment service.
- Notification service.
- Background worker.
Each service can run inside its own container.
An AKS cluster provides the environment in which these containers can run together.
Basic AKS Architecture
Users
|
v
Azure Load Balancer
|
v
Kubernetes Cluster
|
+-------+-------+
| | |
v v v
Node 1 Node 2 Node 3
| | |
v v v
API Orders Worker
Pod Pod Pod
A Kubernetes cluster contains a control plane and one or more node pools.
The control plane manages cluster operations, including scheduling and maintaining the desired state of workloads.
The worker nodes run application containers inside Kubernetes Pods.
In AKS, Microsoft manages the Kubernetes control plane, while customers configure and manage the worker-node infrastructure and workloads.
2. Why Use the .NET Provisioning Library?
Infrastructure provisioning means creating and configuring cloud resources required by an application.
For example, an AKS deployment may require:
- Azure Kubernetes Service cluster.
- System node pool.
- Managed identity.
- Virtual network.
- Container registry.
- Log Analytics workspace.
- Network configuration.
- Monitoring resources.
Traditionally, developers define these resources using Bicep or ARM templates.
A simplified Bicep resource definition might look like this:
resource aks 'Microsoft.ContainerService/managedClusters@2026-01-01' = {
name: 'production-aks'
location: 'eastus'
properties: {
dnsPrefix: 'production-aks'
agentPoolProfiles: [
{
name: 'agentpool'
count: 3
vmSize: 'standard_d2s_v3'
mode: 'System'
osType: 'Linux'
}
]
}
}
Bicep is a declarative language for describing Azure infrastructure.
The Azure Provisioning library provides another way to describe infrastructure through .NET types.
Instead of writing every resource definition in a separate Bicep file, developers can create strongly typed C# objects representing Azure resources.
The main benefits include:
- C#-based infrastructure definitions.
- Strongly typed resource properties.
- Reusable infrastructure components.
- Compile-time assistance from the development environment.
- Better integration with .NET application projects.
- Support for generating infrastructure definitions that can be deployed through supported Azure tooling.
The important distinction is that Azure.Provisioning is a declarative infrastructure-definition library. It is not an imperative SDK that immediately creates an AKS cluster when a C# object is instantiated.
3. Understand the Azure Provisioning SDK Packages
The Azure Provisioning ecosystem uses separate NuGet packages for different Azure services.
The core package provides the infrastructure-definition framework.
The service-specific packages provide resource models for particular Azure services.
For AKS, the relevant packages are:
| Package | Responsibility |
|---|
| Azure.Provisioning | Core infrastructure-definition framework |
| Azure.Provisioning.ContainerService | Azure Kubernetes Service resource models |
| Azure.Provisioning.Network | Azure networking resource models |
| Azure.Provisioning.Storage | Azure Storage resource models |
| Azure.Provisioning.ContainerRegistry | Azure Container Registry resource models |
The package used in this article is Azure.Provisioning.ContainerService.
It provides resource types such as:
- ContainerServiceManagedCluster.
- ManagedClusterAgentPoolProfile.
- ContainerServiceLinuxProfile.
- ManagedClusterIdentity.
- ContainerServiceSshPublicKey.
- ContainerServiceMaintenanceConfiguration.
These classes represent AKS configuration in strongly typed .NET objects.
Package Version
The stable version used in this article is:
Azure.Provisioning.ContainerService 1.0.0
It was released in October 2026.
The package supports .NET 8 and .NET 10, as well as .NET Standard 2.0.
4. Create a .NET Project and Install the Package
Start by creating a console application.
dotnet new console -n AKSProvisioningDemo
cd AKSProvisioningDemo
Install the ContainerService package:
dotnet add package Azure.Provisioning.ContainerService --version 1.0.0
The package depends on Azure.Provisioning and Azure.Core, so NuGet resolves the required dependencies automatically.
If your project uses Central Package Management, add the package version to Directory.Packages.props instead.
Your project can now reference the Azure provisioning resource models.
5. Understand the Infrastructure Class
The central concept in Azure.Provisioning is the Infrastructure class.
An Infrastructure instance represents the collection of Azure resources that make up a deployment.
For example, an infrastructure definition may contain:
Infrastructure
|
+-- AKS Cluster
|
+-- Virtual Network
|
+-- Container Registry
|
+-- Managed Identity
|
+-- Monitoring Resources
Each resource is represented by a provisionable resource object.
The developer creates the required resource objects, configures their properties, and adds them to the Infrastructure instance.
For example:
Infrastructure infra = new();
ContainerServiceManagedCluster aks =
new(nameof(aks));
infra.Add(aks);
The first statement creates the infrastructure definition.
The second creates a managed Kubernetes cluster resource model.
The final statement registers the resource with the infrastructure definition.
At this stage, no Azure cluster has been created. The code describes the desired infrastructure configuration.
6. Define Parameters for the AKS Cluster
A reusable infrastructure definition should not hardcode every deployment value.
Different environments may require different DNS prefixes, administrator usernames, and SSH public keys.
For example:
| Environment | DNS prefix | Node count |
|---|
| Development | dev-aks | 1 |
| Staging | staging-aks | 2 |
| Production | production-aks | 3 |
The Azure Provisioning library provides ProvisioningParameter for defining deployment-time inputs.
Let's create three parameters:
using Azure.Provisioning;
Infrastructure infra = new();
ProvisioningParameter dnsPrefix =
new(nameof(dnsPrefix), typeof(string));
infra.Add(dnsPrefix);
ProvisioningParameter linuxAdminUsername =
new(nameof(linuxAdminUsername), typeof(string));
infra.Add(linuxAdminUsername);
ProvisioningParameter sshRsaPublicKey =
new(nameof(sshRsaPublicKey), typeof(string));
infra.Add(sshRsaPublicKey);
These parameters allow the deployment process to supply values without embedding environment-specific information directly in the resource definition.
Why Use ProvisioningParameter?
A ProvisioningParameter represents an input to the infrastructure template.
For example, the DNS prefix can be supplied differently for each environment.
The same C# infrastructure definition can therefore be reused across development, staging, and production.
The SSH public key is also supplied as a parameter.
Remember that an SSH public key is not a private credential. Never place the corresponding private key in source control or deployment templates.
7. Create an AKS Cluster Using C#
Now let's define the actual Kubernetes cluster.
The ContainerServiceManagedCluster class represents the Azure Kubernetes Service managed cluster resource.
The following implementation is based on the official Azure Provisioning ContainerService example.
using Azure.Provisioning;
using Azure.Provisioning.ContainerService;
Infrastructure infra = new();
ProvisioningParameter dnsPrefix =
new(nameof(dnsPrefix), typeof(string));
infra.Add(dnsPrefix);
ProvisioningParameter linuxAdminUsername =
new(nameof(linuxAdminUsername), typeof(string));
infra.Add(linuxAdminUsername);
ProvisioningParameter sshRsaPublicKey =
new(nameof(sshRsaPublicKey), typeof(string));
infra.Add(sshRsaPublicKey);
ContainerServiceManagedCluster aks =
new(
nameof(aks),
ContainerServiceManagedCluster.ResourceVersions.V2026_01_01)
{
ClusterIdentity = new ManagedClusterIdentity
{
IdentityType =
ManagedServiceIdentityType.SystemAssigned
},
DnsPrefix = dnsPrefix,
LinuxProfile = new ContainerServiceLinuxProfile
{
AdminUsername = linuxAdminUsername,
SshPublicKeys =
{
new ContainerServiceSshPublicKey
{
KeyData = sshRsaPublicKey
}
}
},
AgentPoolProfiles =
{
new ManagedClusterAgentPoolProfile
{
Name = "agentpool",
VmSize = "standard_d2s_v3",
OSDiskSizeInGB = 0,
Count = 3,
OSType = ContainerServiceOSType.Linux,
Mode = AgentPoolMode.System
}
}
};
infra.Add(aks);
This code defines an AKS cluster using strongly typed .NET resource models.
Let's understand the important properties.
ContainerServiceManagedCluster
ContainerServiceManagedCluster represents the AKS resource.
It contains the configuration required to define the Kubernetes cluster, including identity, authentication, networking, node pools, and other supported properties.
The resource version specifies the Azure resource API version used when generating the deployment definition.
The example uses V2026_01_01.
ClusterIdentity
The ClusterIdentity property configures the cluster's managed identity.
The example uses:
IdentityType =
ManagedServiceIdentityType.SystemAssigned
A system-assigned managed identity is associated with the Azure resource itself.
AKS can use its identity to authenticate to other Azure services when the appropriate permissions are assigned.
This avoids storing service-principal credentials directly in the cluster configuration.
DnsPrefix
The DNS prefix identifies the cluster's API server endpoint naming configuration.
Instead of hardcoding the value, the example uses the dnsPrefix provisioning parameter.
This makes the infrastructure reusable across environments.
LinuxProfile
LinuxProfile contains the configuration for Linux-based cluster nodes.
The example defines:
- Administrator username.
- SSH public key.
The SSH public key allows administrators to authenticate to Linux nodes through the configured access method.
For production environments, follow your organization's AKS access and security policies.
AgentPoolProfiles
An agent pool is a group of Kubernetes worker nodes with a shared configuration.
The example creates one system node pool.
Its configuration includes:
| Property | Value | Purpose |
|---|
| Name | agentpool | Node pool name |
| VmSize | standard_d2s_v3 | Virtual machine size |
| Count | 3 | Number of nodes |
| OSType | Linux | Node operating system |
| Mode | System | System workload pool |
| OSDiskSizeInGB | 0 | Use the default disk size for the agent |
The system pool runs critical Kubernetes system workloads.
The cluster can also use additional user node pools for application workloads.
Add the Resource to Infrastructure
The final statement is:
infra.Add(aks);
This registers the AKS resource model with the infrastructure definition.
It is an important step. Creating the C# object alone does not add it to the infrastructure being described.
8. Understand System and User Node Pools
Node pools are an important part of AKS architecture.
A node pool represents a group of virtual machines that run Kubernetes workloads.
AKS supports two important node-pool modes.
System Node Pool
A system node pool is intended to run critical Kubernetes system Pods.
Examples include:
- CoreDNS.
- Metrics Server.
- Kubernetes networking components.
- Other cluster-level services.
A cluster must have at least one system node pool.
User Node Pool
A user node pool is intended for application workloads.
For example, a production application may use:
AKS Cluster
|
+-- System Pool
| |
| +-- Kubernetes system workloads
|
+-- User Pool
|
+-- Customer API
+-- Order Service
+-- Background Worker
Separating system and application workloads helps teams manage resource allocation and scaling more effectively.
A production cluster can use different VM sizes and scaling configurations for different workloads.
The appropriate node-pool configuration depends on CPU requirements, memory consumption, availability requirements, and workload characteristics.
9. Add a Separate User Node Pool
A production application may require a dedicated node pool for business workloads.
The following example extends the AKS resource definition with a second pool.
aks.AgentPoolProfiles.Add(
new ManagedClusterAgentPoolProfile
{
Name = "userpool",
VmSize = "standard_d4s_v3",
Count = 2,
OSType = ContainerServiceOSType.Linux,
Mode = AgentPoolMode.User
});
The user pool uses a different VM size and node count.
This configuration separates application workloads from Kubernetes system workloads.
For production deployments, consider configuring autoscaling instead of relying only on a fixed node count.
Also verify VM SKU availability and quota in the selected Azure region before deploying the cluster.
10. Configure Environment-Specific Values
One of the biggest advantages of declarative infrastructure is reuse.
You should not need to maintain separate copies of the entire AKS definition for development, staging, and production.
ProvisioningParameter allows the deployment workflow to provide different values.
For example:
Development
dnsPrefix = dev-aks
linuxAdminUsername = devadmin
nodeCount = 1
Staging
dnsPrefix = staging-aks
linuxAdminUsername = stageadmin
nodeCount = 2
Production
dnsPrefix = production-aks
linuxAdminUsername = prodadmin
nodeCount = 3
The infrastructure definition remains the same.
Only the parameter values change.
This makes it easier to maintain consistent infrastructure configurations across environments.
For production deployments, validate resource names, allowed locations, VM sizes, and network ranges before provisioning.
11. Understand How C# Infrastructure Definitions Become Azure Resources
Defining infrastructure in C# is not the same as deploying it.
The Azure Provisioning framework provides strongly typed models that describe the desired Azure resources.
These models participate in an infrastructure-definition workflow that can produce Bicep infrastructure definitions.
Bicep is then used as the Azure deployment representation.
The general workflow is:
C# Infrastructure Definition
|
v
Azure Provisioning Models
|
v
Bicep Infrastructure
|
v
Azure Developer CLI
|
v
Azure Resource Manager
|
v
AKS Cluster
This separation is important.
C# describes the infrastructure.
Bicep describes the Azure deployment.
Azure Resource Manager processes the deployment and creates or updates the resources.
The Provisioning package does not replace Azure Resource Manager or directly execute a cluster deployment simply because a resource object was created.
Why Use Bicep as the Deployment Layer?
Bicep provides Azure-native infrastructure deployment capabilities.
It supports:
- Resource dependencies.
- Parameters.
- Outputs.
- Resource declarations.
- Deployment scopes.
- Integration with Azure Resource Manager.
The Azure Provisioning library lets .NET developers define the resource model without manually writing every Bicep declaration.
This is especially useful for teams that prefer C# as their primary infrastructure-definition language.
12. Deploy Infrastructure Using Azure Developer CLI
Azure Developer CLI, commonly called azd, provides a workflow for provisioning and deploying application infrastructure.
It supports Azure infrastructure deployment through Infrastructure as Code providers.
For projects that use the Azure Provisioning workflow, ensure the C# infrastructure definition is connected to a supported generation and deployment pipeline.
The CLI does not automatically discover an arbitrary C# file and convert it into a deployable AKS template.
Step 1: Install Azure Developer CLI
Install azd using the official installation instructions for your operating system.
Verify the installation:
azd version
Step 2: Authenticate
Sign in to Azure:
azd auth login
Step 3: Initialize the Deployment Environment
Initialize an existing Azure Developer CLI project or template:
azd init
Create an environment:
azd env new development
Configure the required subscription and location through the selected azd environment.
Step 4: Provision Azure Resources
Once the infrastructure deployment files and provisioning integration are configured, run:
azd provision
The command provisions the resources defined by the project's supported infrastructure provider.
Step 5: Deploy Application Code
After the AKS infrastructure is available, deploy the application using the configured application deployment workflow.
For a project that supports the complete azd lifecycle, the convenience command is:
azd up
This combines provisioning, packaging, and deployment.
The important point is that infrastructure provisioning and application deployment are separate lifecycle stages.
An AKS cluster can be provisioned successfully even when no application workload has been deployed to it.
13. Understand How the .NET Provisioning Library Differs From Azure Management SDKs
Developers sometimes confuse Azure provisioning libraries with Azure management clients.
They are designed for different tasks.
The Azure.ResourceManager libraries are primarily used to manage existing Azure resources through management operations.
The Azure.Provisioning libraries are used to define infrastructure declaratively.
| Feature | Azure.ResourceManager | Azure.Provisioning |
|---|
| Main purpose | Manage Azure resources | Define Azure infrastructure |
| Programming approach | Management operations | Declarative resource models |
| Typical operations | Get, create, update, delete | Define resources and properties |
| Infrastructure representation | Resource objects and API operations | Strongly typed Bicep-oriented models |
| Deployment workflow | ARM management operations | Generated infrastructure deployment workflow |
| Typical use | Administration tools | Infrastructure as Code |
For example, an application that needs to list existing AKS clusters may use Azure.ResourceManager.ContainerService.
A deployment project that defines a new AKS cluster using C# resource models can use Azure.Provisioning.ContainerService.
The correct choice depends on whether you are managing existing infrastructure or defining the desired infrastructure for deployment.
14. Add Outputs to the Infrastructure Definition
Infrastructure outputs are useful when one resource needs to provide information to another deployment component.
For example, an AKS deployment may need to expose its resource ID for later use.
The Azure Provisioning framework supports ProvisioningOutput.
A basic example looks like this:
ProvisioningOutput clusterName =
new("aksClusterName", typeof(string))
{
Value = aks.Name
};
infra.Add(clusterName);
The output represents a value that can be exposed by the generated infrastructure deployment.
Outputs are useful for:
- Resource identifiers.
- Endpoint information.
- Managed identity details.
- Names of provisioned resources.
- Integration with subsequent deployment stages.
The value can reference a property from the resource model rather than duplicating a hardcoded value.
For more complex expressions, use the framework's Bicep expression support.
15. Troubleshoot Common AKS Provisioning Problems
Package Installation Fails
If NuGet cannot resolve the package, verify the package name and version.
Run:
dotnet restore
Also check whether your project targets a supported framework.
The stable ContainerService 1.0.0 package supports .NET 8 and .NET 10.
Azure Subscription Is Not Configured
The provisioning workflow needs an Azure subscription.
Check your active account:
az account show
If required, sign in again:
az login
AKS Resource Name Is Invalid
Azure resource names have specific naming requirements.
Validate the cluster name and DNS prefix before deployment.
Avoid using spaces or unsupported special characters.
VM SKU Is Unavailable
The selected virtual machine size may not be available in every Azure region.
Check the VM SKU availability and regional quota.
A cluster deployment can fail if the selected VM size is unavailable or the subscription does not have sufficient quota.
SSH Public Key Is Invalid
Verify that the supplied public key uses a supported SSH public-key format.
Do not pass a private key in the SSH public-key parameter.
Cluster Deployment Fails
Review the Azure Resource Manager deployment operation details.
Common causes include:
- Insufficient permissions.
- Invalid cluster configuration.
- Unsupported Kubernetes version.
- Regional capacity limitations.
- VM quota exhaustion.
- Networking configuration errors.
Use Azure deployment diagnostics to identify the failing resource and property.
16. Best Practices for Production AKS Provisioning
Use Managed Identity
Prefer managed identity over storing service-principal credentials in infrastructure configuration.
Assign only the permissions required by the cluster and its workloads.
Separate System and User Workloads
Use a system node pool for Kubernetes components and user node pools for application workloads.
This provides better workload separation.
Configure Networking Before Deployment
Plan the cluster network architecture before provisioning.
Consider:
- Pod address ranges.
- Service address ranges.
- Virtual network integration.
- Network policies.
- Private cluster requirements.
- Outbound connectivity.
Changing some networking settings after cluster creation can be difficult or unsupported.
Use Autoscaling
For workloads with changing demand, configure cluster autoscaling and appropriate node-pool limits.
Do not select node counts without considering expected CPU and memory usage.
Use Separate Environments
Maintain separate configurations for development, staging, and production.
Use parameters rather than duplicating the complete infrastructure definition.
Protect SSH and Other Credentials
Keep private keys and other secrets outside source control.
Use secure secret-management mechanisms for deployment credentials.
Validate Generated Infrastructure
Before deploying, inspect the generated infrastructure definition.
Verify resource names, locations, network settings, identity configuration, permissions, and estimated cost.
Monitor the Cluster
Configure Azure Monitor and appropriate Kubernetes monitoring.
Track:
- Node health.
- Pod restarts.
- CPU utilization.
- Memory utilization.
- Deployment failures.
- Network errors.
Provisioning a cluster is only the first step. Production operations require continuous monitoring and maintenance.
17. Advantages and Limitations
Advantages
- C# infrastructure definitions: Developers can define AKS resources using familiar .NET types.
- Strongly typed configuration: Resource properties are represented through typed classes instead of manually maintaining every template property.
- Reusable infrastructure: Parameters make it easier to reuse definitions across multiple environments.
- Azure service integration: The package works with the broader Azure Provisioning ecosystem.
- Better maintainability: Infrastructure definitions can be organized into reusable C# components.
- Bicep-oriented deployment: The framework fits into Azure's declarative infrastructure deployment model.
- Improved developer experience: Developers can use IDE features such as IntelliSense and compile-time checking when configuring supported properties.
Limitations
- Deployment tooling required: Defining C# resource objects does not automatically create Azure resources.
- Azure-specific: The library is designed for Azure infrastructure rather than providing a general multi-cloud provisioning abstraction.
- Resource-model coverage: The available strongly typed resource models depend on the package and API version.
- Infrastructure expertise required: Developers still need to understand Kubernetes, Azure networking, identity, security, and resource limits.
- Deployment complexity: A production AKS cluster requires more configuration than a basic cluster definition.
- Cost considerations: Node pools, networking, storage, and supporting Azure services can generate significant costs.
Conclusion
The Azure Provisioning library makes it possible to define Azure infrastructure using C# instead of manually maintaining every Bicep or ARM resource declaration.
With Azure.Provisioning.ContainerService, developers can describe AKS clusters through strongly typed classes such as ContainerServiceManagedCluster, ManagedClusterAgentPoolProfile, and ContainerServiceLinuxProfile.
The library supports a declarative infrastructure workflow that fits into Azure's Bicep and Azure Developer CLI deployment ecosystem.
For .NET teams, this provides a familiar way to define Kubernetes infrastructure while keeping configuration reusable across development, staging, and production environments.
However, creating the resource model is only one part of the process. Teams must also configure networking, identity, node pools, permissions, deployment tooling, and operational monitoring.
When used with a well-designed infrastructure workflow, Azure Provisioning can make AKS infrastructure definitions easier to maintain and integrate with modern .NET development projects.
Join the conversation! Your thoughts help the community grow.