1. Answers
  2. Configuring Virtual Nodes in AKS Using an Agent Pool

How do I configure virtual nodes in AKS using an agent pool?

In this guide, we will configure virtual nodes in Azure Kubernetes Service (AKS) using an agent pool. Virtual nodes allow you to elastically burst your Kubernetes workloads into Azure Container Instances (ACI) when your cluster runs out of capacity. We will use Pulumi to define and deploy the necessary resources.

We will perform the following steps:

  1. Create an AKS cluster.
  2. Add an agent pool to the AKS cluster.
  3. Enable virtual nodes for the agent pool.
import * as pulumi from "@pulumi/pulumi";
import * as azureNative from "@pulumi/azure-native";

// Define the resource group
const resourceGroup = new azureNative.resources.ResourceGroup("resourceGroup", {
    location: "East US",
});

// Create the AKS cluster
const aksCluster = new azureNative.containerservice.ManagedCluster("aksCluster", {
    resourceGroupName: resourceGroup.name,
    location: resourceGroup.location,
    dnsPrefix: "aksdns",
    agentPoolProfiles: [{
        name: "agentpool",
        count: 1,
        vmSize: "Standard_DS2_v2",
        osType: "Linux",
        mode: "System",
    }],
    identity: {
        type: "SystemAssigned",
    },
    networkProfile: {
        networkPlugin: "azure",
    },
    enableRBAC: true,
});

// Create an agent pool for virtual nodes
const virtualNodeAgentPool = new azureNative.containerservice.AgentPool("virtualNodeAgentPool", {
    resourceGroupName: resourceGroup.name,
    resourceName: aksCluster.name,
    agentPoolName: "virtualnodepool",
    count: 1,
    vmSize: "Standard_DS2_v2",
    osType: "Linux",
    mode: "User",
    vnetSubnetID: "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Network/virtualNetworks/<vnet-name>/subnets/<subnet-name>",
    enableAutoScaling: true,
    minCount: 1,
    maxCount: 3,
    nodeTaints: ["virtual-kubelet.io/provider=azure:NoSchedule"],
    nodeLabels: {
        "beta.kubernetes.io/os": "linux",
        "kubernetes.io/role": "agent",
    },
});

// Export the kubeconfig
export const kubeconfig = pulumi.all([aksCluster.name, resourceGroup.name]).apply(([clusterName, rgName]) => {
    return pulumi.output(azureNative.containerservice.listManagedClusterUserCredentials({
        resourceGroupName: rgName,
        resourceName: clusterName,
    })).kubeconfigs[0].value.apply(kubeconfig => Buffer.from(kubeconfig, "base64").toString("utf-8"));
});

Key Points

  • Resource Group: A logical container for Azure resources.
  • AKS Cluster: The main Kubernetes cluster managed by Azure.
  • Agent Pool: A set of virtual machines running Kubernetes nodes.
  • Virtual Nodes: Allow AKS to burst workloads into Azure Container Instances.

Summary

We configured an AKS cluster with an additional agent pool specifically for virtual nodes. This enables the cluster to scale out additional workloads to Azure Container Instances when needed. The nodeTaints and nodeLabels ensure that the virtual nodes are properly recognized by Kubernetes.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up