Kubernetes Cluster on Azure
The Azure Kubernetes Cluster template scaffolds a Pulumi project that provisions a managed Azure Kubernetes Service (AKS) cluster inside a new Azure Virtual Network with three subnets. Worker nodes are deployed with private IP addresses for improved security and spread across multiple availability zones for resilience. The HCL version is simpler: it creates only a resource group and the cluster, which uses AKS’s default networking and doesn’t spread nodes across availability zones.
Before you begin#
For this walkthrough, you'll need:
- The Pulumi CLI
- The Azure CLI (optional, but recommended and used in this guide)
- Permission to manage AKS and virtual networks
- The kubectl CLI
- kubelogin installed
For this walkthrough, you'll need:
- The Pulumi CLI
- The Azure CLI (optional, but recommended and used in this guide)
- Permission to manage AKS and virtual networks
- The kubectl CLI
- kubelogin installed
For this walkthrough, you'll need:
- The Pulumi CLI
- The Azure CLI (optional, but recommended and used in this guide)
- Permission to manage AKS and virtual networks
- A current version of Go installed locally
- The kubectl CLI
- kubelogin installed
For this walkthrough, you'll need:
- The Pulumi CLI
- The Azure CLI (optional, but recommended and used in this guide)
- Permission to manage AKS and virtual networks
- A current version of .NET installed locally
- The kubectl CLI
- kubelogin installed
For this walkthrough, you'll need:
- The Pulumi CLI
- The Azure CLI (optional, but recommended and used in this guide)
- Permission to manage AKS and virtual networks
- The kubectl CLI
- kubelogin installed
For this walkthrough, you'll need:
- A current version of the Pulumi CLI (Pulumi HCL requires no additional runtime)
- The Azure CLI (optional, but recommended and used in this guide)
- Permission to manage AKS and virtual networks
- The kubectl CLI
- kubelogin installed
Create a new project#
Create a new project from the template:
mkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-typescriptmkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-typescriptmkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-pythonmkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-pythonmkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-gomkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-gomkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-csharpmkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-csharpmkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-yamlmkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-yamlmkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-hclmkdir my-k8s-cluster; cd my-k8s-clusterpulumi new kubernetes-azure-hclThe pulumi new command walks you through creating and configuring the new project and stack. A stack is an instance of a project, and you can have many of them (dev, staging, prod), each with its own configuration settings. Depending on the language, you may also be asked for your preferred package manager or toolchain.
This template’s settings include:
| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure location (region) in which to create the cluster | westus2 |
| numWorkerNodes | Number of worker nodes in the cluster | 3 |
| prefixForDns | DNS prefix for the cluster | pulumi |
| kubernetesVersion | Kubernetes version to deploy in the cluster | 1.37 |
| nodeVmSize | VM size to use for worker nodes in the cluster | Standard_DS2_v2 |
| mgmtGroupId | The object ID (from az ad group list) of a group to make cluster admins | — |
| sshPubKey | Contents of the public key for SSH access to cluster nodes | — |
pulumi config set
:
pulumi config set azure-native:location <value>pulumi config set numWorkerNodes <value>pulumi config set prefixForDns <value>pulumi config set kubernetesVersion <value>pulumi config set nodeVmSize <value>pulumi config set mgmtGroupId <value>pulumi config set sshPubKey <value>pulumi config set azure-native:location "<value>"pulumi config set numWorkerNodes "<value>"pulumi config set prefixForDns "<value>"pulumi config set kubernetesVersion "<value>"pulumi config set nodeVmSize "<value>"pulumi config set mgmtGroupId "<value>"pulumi config set sshPubKey "<value>"| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure location (region) in which to create the cluster | westus2 |
| numWorkerNodes | Number of worker nodes in the cluster | 3 |
| prefixForDns | DNS prefix for the cluster | pulumi |
| kubernetesVersion | Kubernetes version to deploy in the cluster | 1.37 |
| nodeVmSize | VM size to use for worker nodes in the cluster | Standard_DS2_v2 |
| mgmtGroupId | The object ID (from az ad group list) of a group to make cluster admins | — |
| sshPubKey | Contents of the public key for SSH access to cluster nodes | — |
pulumi config set
:
pulumi config set azure-native:location <value>pulumi config set numWorkerNodes <value>pulumi config set prefixForDns <value>pulumi config set kubernetesVersion <value>pulumi config set nodeVmSize <value>pulumi config set mgmtGroupId <value>pulumi config set sshPubKey <value>pulumi config set azure-native:location "<value>"pulumi config set numWorkerNodes "<value>"pulumi config set prefixForDns "<value>"pulumi config set kubernetesVersion "<value>"pulumi config set nodeVmSize "<value>"pulumi config set mgmtGroupId "<value>"pulumi config set sshPubKey "<value>"| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure location (region) in which to create the cluster | westus2 |
| numWorkerNodes | Number of worker nodes in the cluster | 3 |
| prefixForDns | DNS prefix for the cluster | pulumi |
| kubernetesVersion | Kubernetes version to deploy in the cluster | 1.37 |
| nodeVmSize | VM size to use for worker nodes in the cluster | Standard_DS2_v2 |
| mgmtGroupId | The object ID (from az ad group list) of a group to make cluster admins | — |
| sshPubKey | Contents of the public key for SSH access to cluster nodes | — |
pulumi config set
:
pulumi config set azure-native:location <value>pulumi config set numWorkerNodes <value>pulumi config set prefixForDns <value>pulumi config set kubernetesVersion <value>pulumi config set nodeVmSize <value>pulumi config set mgmtGroupId <value>pulumi config set sshPubKey <value>pulumi config set azure-native:location "<value>"pulumi config set numWorkerNodes "<value>"pulumi config set prefixForDns "<value>"pulumi config set kubernetesVersion "<value>"pulumi config set nodeVmSize "<value>"pulumi config set mgmtGroupId "<value>"pulumi config set sshPubKey "<value>"| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure location (region) in which to create the cluster | westus2 |
| numWorkerNodes | Number of worker nodes in the cluster | 3 |
| prefixForDns | DNS prefix for the cluster | pulumi |
| kubernetesVersion | Kubernetes version to deploy in the cluster | 1.37 |
| nodeVmSize | VM size to use for worker nodes in the cluster | Standard_DS2_v2 |
| mgmtGroupId | The object ID (from az ad group list) of a group to make cluster admins | — |
| sshPubKey | Contents of the public key for SSH access to cluster nodes | — |
pulumi config set
:
pulumi config set azure-native:location <value>pulumi config set numWorkerNodes <value>pulumi config set prefixForDns <value>pulumi config set kubernetesVersion <value>pulumi config set nodeVmSize <value>pulumi config set mgmtGroupId <value>pulumi config set sshPubKey <value>pulumi config set azure-native:location "<value>"pulumi config set numWorkerNodes "<value>"pulumi config set prefixForDns "<value>"pulumi config set kubernetesVersion "<value>"pulumi config set nodeVmSize "<value>"pulumi config set mgmtGroupId "<value>"pulumi config set sshPubKey "<value>"| Key | Description | Default |
|---|---|---|
| azure-native:location | — | |
| numWorkerNodes | Number of worker nodes in the cluster | 3 |
| prefixForDns | DNS prefix for the cluster | pulumi |
| kubernetesVersion | Kubernetes version to deploy in the cluster | 1.37 |
| nodeVmSize | VM size to use for worker nodes in the cluster | Standard_DS2_v2 |
| mgmtGroupId | The object ID (from az ad group list) of a group to make cluster admins | — |
| sshPubKey | Contents of the public key for SSH access to cluster nodes | — |
pulumi config set
:
pulumi config set azure-native:location <value>pulumi config set numWorkerNodes <value>pulumi config set prefixForDns <value>pulumi config set kubernetesVersion <value>pulumi config set nodeVmSize <value>pulumi config set mgmtGroupId <value>pulumi config set sshPubKey <value>pulumi config set azure-native:location "<value>"pulumi config set numWorkerNodes "<value>"pulumi config set prefixForDns "<value>"pulumi config set kubernetesVersion "<value>"pulumi config set nodeVmSize "<value>"pulumi config set mgmtGroupId "<value>"pulumi config set sshPubKey "<value>"| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure region to deploy into | westus2 |
| node_count | The number of worker nodes in the cluster | 3 |
| dns_prefix | The DNS prefix to use for the cluster | pulumi |
| node_vm_size | The VM size to use for worker nodes | Standard_DS2_v2 |
pulumi config set
:
pulumi config set azure-native:location <value>pulumi config set node_count <value>pulumi config set dns_prefix <value>pulumi config set node_vm_size <value>pulumi config set azure-native:location "<value>"pulumi config set node_count "<value>"pulumi config set dns_prefix "<value>"pulumi config set node_vm_size "<value>"For mgmtGroupId, pick a group you belong to, or kubectl won’t let you in later. This lists your groups with their IDs:
az ad user get-member-groups --id $(az ad signed-in-user show --query id --output tsv) --query "[].{Name:displayName, ObjectId:id}" --output tableaz ad user get-member-groups --id $(az ad signed-in-user show --query id --output tsv) --query "[].{Name:displayName, ObjectId:id}" --output tableFor sshPubKey, paste your public key, such as the output of cat ~/.ssh/id_ed25519.pub or cat ~/.ssh/id_rsa.pub.
For mgmtGroupId, pick a group you belong to, or kubectl won’t let you in later. This lists your groups with their IDs:
az ad user get-member-groups --id $(az ad signed-in-user show --query id --output tsv) --query "[].{Name:displayName, ObjectId:id}" --output tableaz ad user get-member-groups --id $(az ad signed-in-user show --query id --output tsv) --query "[].{Name:displayName, ObjectId:id}" --output tableFor sshPubKey, paste your public key, such as the output of cat ~/.ssh/id_ed25519.pub or cat ~/.ssh/id_rsa.pub.
For mgmtGroupId, pick a group you belong to, or kubectl won’t let you in later. This lists your groups with their IDs:
az ad user get-member-groups --id $(az ad signed-in-user show --query id --output tsv) --query "[].{Name:displayName, ObjectId:id}" --output tableaz ad user get-member-groups --id $(az ad signed-in-user show --query id --output tsv) --query "[].{Name:displayName, ObjectId:id}" --output tableFor sshPubKey, paste your public key, such as the output of cat ~/.ssh/id_ed25519.pub or cat ~/.ssh/id_rsa.pub.
For mgmtGroupId, pick a group you belong to, or kubectl won’t let you in later. This lists your groups with their IDs:
az ad user get-member-groups --id $(az ad signed-in-user show --query id --output tsv) --query "[].{Name:displayName, ObjectId:id}" --output tableaz ad user get-member-groups --id $(az ad signed-in-user show --query id --output tsv) --query "[].{Name:displayName, ObjectId:id}" --output tableFor sshPubKey, paste your public key, such as the output of cat ~/.ssh/id_ed25519.pub or cat ~/.ssh/id_rsa.pub.
The region is set in Pulumi.yaml: azure-native:location is westus2.
For mgmtGroupId, pick a group you belong to, or kubectl won’t let you in later. This lists your groups with their IDs:
az ad user get-member-groups --id $(az ad signed-in-user show --query id --output tsv) --query "[].{Name:displayName, ObjectId:id}" --output tableaz ad user get-member-groups --id $(az ad signed-in-user show --query id --output tsv) --query "[].{Name:displayName, ObjectId:id}" --output tableFor sshPubKey, paste your public key, such as the output of cat ~/.ssh/id_ed25519.pub or cat ~/.ssh/id_rsa.pub.
Review the code#
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfcontains the program code that declares your cloud resources.
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfcontains the program code that declares your cloud resources.
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfcontains the program code that declares your cloud resources.
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfcontains the program code that declares your cloud resources.
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the resources it declares.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfcontains the program code that declares your cloud resources.
Take a moment to open them up and have a look. Here’s what’s in index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tf:
import * as pulumi from "@pulumi/pulumi";import * as resources from "@pulumi/azure-native/resources";import * as network from "@pulumi/azure-native/network";import * as containerservice from "@pulumi/azure-native/containerservice";
// Grab some values from the Pulumi stack configuration (or use defaults)const projCfg = new pulumi.Config();const numWorkerNodes = projCfg.getNumber("numWorkerNodes") || 3;const k8sVersion = projCfg.get("kubernetesVersion") || "1.37";const prefixForDns = projCfg.get("prefixForDns") || "pulumi";const nodeVmSize = projCfg.get("nodeVmSize") || "Standard_DS2_v2";// The next two configuration values are required (no default can be provided)const mgmtGroupId = projCfg.require("mgmtGroupId");const sshPubKey = projCfg.require("sshPubKey");
// Create a new Azure Resource Groupconst resourceGroup = new resources.ResourceGroup("resourceGroup", {});
// Create a new Azure Virtual Networkconst virtualNetwork = new network.VirtualNetwork("virtualNetwork", { addressSpace: { addressPrefixes: ["10.0.0.0/16"], }, resourceGroupName: resourceGroup.name,});
// Create three subnets in the virtual networkconst subnet1 = new network.Subnet("subnet1", { addressPrefix: "10.0.0.0/22", resourceGroupName: resourceGroup.name, virtualNetworkName: virtualNetwork.name,});
const subnet2 = new network.Subnet("subnet2", { addressPrefix: "10.0.4.0/22", resourceGroupName: resourceGroup.name, virtualNetworkName: virtualNetwork.name,});
const subnet3 = new network.Subnet("subnet3", { addressPrefix: "10.0.8.0/22", resourceGroupName: resourceGroup.name, virtualNetworkName: virtualNetwork.name,});
// Create an Azure Kubernetes Clusterconst managedCluster = new containerservice.ManagedCluster("managedCluster", { aadProfile: { enableAzureRBAC: true, managed: true, adminGroupObjectIDs: [mgmtGroupId], }, addonProfiles: {}, // Use multiple agent/node pool profiles to distribute nodes across subnets agentPoolProfiles: [{ availabilityZones: ["1","2","3"], count: numWorkerNodes, enableNodePublicIP: false, mode: "System", name: "systempool", osType: "Linux", osDiskSizeGB: 30, type: "VirtualMachineScaleSets", vmSize: nodeVmSize, // Change next line for additional node pools to distribute across subnets vnetSubnetID: subnet1.id, }], // Change authorizedIPRanges to limit access to API server // Changing enablePrivateCluster requires alternate access to API server (VPN or similar) apiServerAccessProfile: { authorizedIPRanges: ["0.0.0.0/0"], enablePrivateCluster: false, }, dnsPrefix: prefixForDns, enableRBAC: true, identity: { type: "SystemAssigned", }, kubernetesVersion: k8sVersion, linuxProfile: { adminUsername: "azureuser", ssh: { publicKeys: [{ keyData: sshPubKey, }], }, }, networkProfile: { networkPlugin: "azure", networkPolicy: "azure", serviceCidr: "10.96.0.0/16", dnsServiceIP: "10.96.0.10", }, resourceGroupName: resourceGroup.name,});
// Build a user Kubeconfig// This SHOULD NOT be used for an explicit provider// This SHOULD be used for user logins to the clusterconst creds = containerservice.listManagedClusterUserCredentialsOutput({ resourceGroupName: resourceGroup.name, resourceName: managedCluster.name,});const encoded = creds.kubeconfigs[0].value;const decoded = encoded.apply(enc => Buffer.from(enc, "base64").toString());
// Build an admin Kubeconfig// This SHOULD be used for an explicit provider// This SHOULD NOT be used for user logins to the clusterconst adminCreds = containerservice.listManagedClusterAdminCredentialsOutput({ resourceGroupName: resourceGroup.name, resourceName: managedCluster.name,});const adminEncoded = adminCreds.kubeconfigs[0].value;const adminDecoded = adminEncoded.apply(enc => Buffer.from(enc, "base64").toString());
// Export some values for use elsewhereexport const rgName = resourceGroup.name;export const networkName = virtualNetwork.name;export const clusterName = managedCluster.name;export const kubeconfig = decoded;export const adminKubeconfig = pulumi.secret(adminDecoded)"""An Azure RM Python Pulumi program"""
import base64import pulumifrom pulumi_azure_native import resourcesfrom pulumi_azure_native import networkfrom pulumi_azure_native import containerservice
# Get some project-namespaced configuration values or use default valuesproj_cfg = pulumi.Config()num_worker_nodes = proj_cfg.get_int("numWorkerNodes", 3)k8s_version = proj_cfg.get("kubernetesVersion", "1.37")prefix_for_dns = proj_cfg.get("prefixForDns", "pulumi")node_vm_size = proj_cfg.get("nodeVmSize", "Standard_DS2_v2")# The next two configuration values are required (no default can be provided)mgmt_group_id = proj_cfg.require("mgmtGroupId")ssh_pub_key = proj_cfg.require("sshPubKey")
# Create an Azure Resource Groupresource_group = resources.ResourceGroup( "resource_group")
# Create an Azure Virtual Networkvirtual_network = network.VirtualNetwork( "virtual_network", address_space={ "address_prefixes": ["10.0.0.0/16"], }, resource_group_name=resource_group.name)
# Create three subnets in the virtual networksubnet1 = network.Subnet( "subnet-1", address_prefix="10.0.0.0/22", resource_group_name=resource_group.name, virtual_network_name=virtual_network.name)subnet2 = network.Subnet( "subnet-2", address_prefix="10.0.4.0/22", resource_group_name=resource_group.name, virtual_network_name=virtual_network.name)subnet3 = network.Subnet( "subnet-3", address_prefix="10.0.8.0/22", resource_group_name=resource_group.name, virtual_network_name=virtual_network.name)
# Create an Azure Kubernetes Service clustermanaged_cluster = containerservice.ManagedCluster( "managed_cluster", aad_profile={ "enable_azure_rbac": True, "managed": True, "admin_group_object_ids": [mgmt_group_id], }, # Use multiple agent/node pools to distribute nodes across subnets agent_pool_profiles=[{ "availability_zones": ["1","2","3",], "count": 3, "enable_node_public_ip": False, "mode": "System", "name": "systempool", "os_type": "Linux", "os_disk_size_gb": 30, "type": "VirtualMachineScaleSets", "vm_size": node_vm_size, # Change next line for additional node pools to distribute across subnets "vnet_subnet_id": subnet1.id }], # Change authorized_ip_ranges to limit access to API server # Changing enable_private_cluster requires alternate access to API server (VPN or similar) api_server_access_profile={ "authorized_ip_ranges": ["0.0.0.0/0"], "enable_private_cluster": False }, dns_prefix=prefix_for_dns, enable_rbac=True, identity={ "type": containerservice.ResourceIdentityType.SYSTEM_ASSIGNED, }, kubernetes_version=k8s_version, linux_profile={ "admin_username": "azureuser", "ssh": { "public_keys": [{ "key_data": ssh_pub_key, }], }, }, network_profile={ "network_plugin": "azure", "network_policy": "azure", "service_cidr": "10.96.0.0/16", "dns_service_ip": "10.96.0.10", }, resource_group_name=resource_group.name)
# Build a user Kubeconfig# This SHOULD NOT be used for an explicit provider# This SHOULD be used for user logins to the clustercreds = containerservice.list_managed_cluster_user_credentials_output( resource_group_name=resource_group.name, resource_name=managed_cluster.name,)encoded = creds.kubeconfigs[0].valuekubeconfig = encoded.apply(lambda enc: base64.b64decode(enc).decode())
# Build an admin Kubeconfig# This SHOULD be used for an explicit provider# THIS SHOULD NOT be used for user logins to the clusteradminCreds = containerservice.list_managed_cluster_admin_credentials_output( resource_group_name=resource_group.name, resource_name=managed_cluster.name,)encoded = adminCreds.kubeconfigs[0].valueadminKubeconfig = encoded.apply(lambda enc: base64.b64decode(enc).decode())
# Export some values for use elsewherepulumi.export("rgname", resource_group.name)pulumi.export("vnetName", virtual_network.name)pulumi.export("clusterName", managed_cluster.name)pulumi.export("kubeconfig", kubeconfig)pulumi.export("adminKubeconfig", pulumi.Output.secret(adminKubeconfig))package main
import ( "encoding/base64"
"github.com/pulumi/pulumi-azure-native-sdk/containerservice/v3" "github.com/pulumi/pulumi-azure-native-sdk/network/v3" "github.com/pulumi/pulumi-azure-native-sdk/resources/v3" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config")
func main() { pulumi.Run(func(ctx *pulumi.Context) error { // Get some configuration values or set default values cfg := config.New(ctx, "") prefixForDns, err := cfg.Try("prefixForDns") if err != nil { prefixForDns = "pulumi" } kubernetesVersion, err := cfg.Try("kubernetesVersion") if err != nil { kubernetesVersion = "1.37" } numWorkerNodes, err := cfg.TryInt("numWorkerNodes") if err != nil { numWorkerNodes = 3 } nodeVmSize, err := cfg.Try("nodeVmSize") if err != nil { nodeVmSize = "Standard_DS2_v2" } // The next two configuration values are required (no default can be provided) sshPubKey := cfg.Require("sshPubKey") mgmtGroup := cfg.Require("mgmtGroupId")
// Create an Azure Resource Group resourceGroup, err := resources.NewResourceGroup(ctx, "resourceGroup", &resources.ResourceGroupArgs{}) if err != nil { return err }
// Create an Azure Virtual Network virtualNetwork, err := network.NewVirtualNetwork(ctx, "aks-network", &network.VirtualNetworkArgs{ AddressSpace: &network.AddressSpaceArgs{ AddressPrefixes: pulumi.StringArray{ pulumi.String("10.0.0.0/16"), }, }, ResourceGroupName: resourceGroup.Name, }) if err != nil { return err }
// Create three subnets in the virtual network subnet1, err := network.NewSubnet(ctx, "subnet-1", &network.SubnetArgs{ AddressPrefix: pulumi.String("10.0.0.0/22"), ResourceGroupName: resourceGroup.Name, VirtualNetworkName: virtualNetwork.Name, }) if err != nil { return err }
subnet2, err := network.NewSubnet(ctx, "subnet-2", &network.SubnetArgs{ AddressPrefix: pulumi.String("10.0.4.0/22"), ResourceGroupName: resourceGroup.Name, VirtualNetworkName: virtualNetwork.Name, }) if err != nil { return err }
subnet3, err := network.NewSubnet(ctx, "subnet-3", &network.SubnetArgs{ AddressPrefix: pulumi.String("10.0.8.0/22"), ResourceGroupName: resourceGroup.Name, VirtualNetworkName: virtualNetwork.Name, }) if err != nil { return err }
// Create a managed AKS cluster cluster, err := containerservice.NewManagedCluster(ctx, "aks-cluster", &containerservice.ManagedClusterArgs{ AadProfile: &containerservice.ManagedClusterAADProfileArgs{ EnableAzureRBAC: pulumi.Bool(true), Managed: pulumi.Bool(true), AdminGroupObjectIDs: pulumi.StringArray{ pulumi.String(mgmtGroup), }, }, // Use multiple agent/node pool profiles to distribute nodes across subnets AgentPoolProfiles: containerservice.ManagedClusterAgentPoolProfileArray{ &containerservice.ManagedClusterAgentPoolProfileArgs{ AvailabilityZones: pulumi.StringArray{ pulumi.String("1"), pulumi.String("2"), pulumi.String("3"), }, Count: pulumi.Int(numWorkerNodes), EnableNodePublicIP: pulumi.Bool(false), Mode: pulumi.String("System"), Name: pulumi.String("systempool"), OsDiskSizeGB: pulumi.Int(30), OsType: pulumi.String("Linux"), VmSize: pulumi.String(nodeVmSize), // Change next line for additional node pools to distribute across subnets VnetSubnetID: subnet1.ID(), }, }, // Change AuthorizedIPRanges to limit access to API server // Changing EnablePrivateCluster requires alternate access to API server (VPN or similar) ApiServerAccessProfile: containerservice.ManagedClusterAPIServerAccessProfileArgs{ AuthorizedIPRanges: pulumi.StringArray{ pulumi.String("0.0.0.0/0"), }, EnablePrivateCluster: pulumi.Bool(false), }, DnsPrefix: pulumi.String(prefixForDns), EnableRBAC: pulumi.Bool(true), Identity: containerservice.ManagedClusterIdentityArgs{ Type: containerservice.ResourceIdentityTypeSystemAssigned, }, KubernetesVersion: pulumi.String(kubernetesVersion), LinuxProfile: &containerservice.ContainerServiceLinuxProfileArgs{ AdminUsername: pulumi.String("azureuser"), Ssh: containerservice.ContainerServiceSshConfigurationArgs{ PublicKeys: containerservice.ContainerServiceSshPublicKeyArray{ containerservice.ContainerServiceSshPublicKeyArgs{ KeyData: pulumi.String(sshPubKey), }, }, }, }, NetworkProfile: containerservice.ContainerServiceNetworkProfileArgs{ NetworkPlugin: pulumi.String("azure"), NetworkPolicy: pulumi.String("azure"), ServiceCidr: pulumi.String("10.96.0.0/16"), DnsServiceIP: pulumi.String("10.96.0.10"), }, ResourceGroupName: resourceGroup.Name, }) if err != nil { return err }
// Build a user Kubeconfig // This Kubeconfig SHOULD NOT be used for an explicit provider // This Kubeconfig SHOULD be used for user logins to the cluster creds := containerservice.ListManagedClusterUserCredentialsOutput(ctx, containerservice.ListManagedClusterUserCredentialsOutputArgs{ ResourceGroupName: resourceGroup.Name, ResourceName: cluster.Name, })
kubeconfig := creds.Kubeconfigs().Index(pulumi.Int(0)).Value(). ApplyT(func(encoded string) string { kubeconfig, err := base64.StdEncoding.DecodeString(encoded) if err != nil { return "" } return string(kubeconfig) })
// Build an admin Kubeconfig // This Kubeconfig SHOULD be used for an explicit provider // This Kubeconfig SHOULD NOT be used for user logins to the cluster adminCreds := containerservice.ListManagedClusterAdminCredentialsOutput(ctx, containerservice.ListManagedClusterAdminCredentialsOutputArgs{ ResourceGroupName: resourceGroup.Name, ResourceName: cluster.Name, })
adminKubeconfig := adminCreds.Kubeconfigs().Index(pulumi.Int(0)).Value(). ApplyT(func(encoded string) string { adminKubeconfig, err := base64.StdEncoding.DecodeString(encoded) if err != nil { return "" } return string(adminKubeconfig) })
// Export some values for use elsewhere ctx.Export("resourceGroupName", resourceGroup.Name) ctx.Export("networkName", virtualNetwork.Name) ctx.Export("subnet1Name", subnet1.Name) ctx.Export("subnet2Name", subnet2.Name) ctx.Export("subnet3Name", subnet3.Name) ctx.Export("clusterName", cluster.Name) ctx.Export("kubeconfig", kubeconfig) ctx.Export("adminKubeconfig", pulumi.ToSecret(adminKubeconfig))
return nil })}using Pulumi;using AzureNative = Pulumi.AzureNative;using System.Collections.Generic;using System.Text;using System;
return await Pulumi.Deployment.RunAsync(() =>{ // Grab some values from the Pulumi stack configuration (or use defaults) var projCfg = new Config(); var numWorkerNodes = projCfg.GetInt32("numWorkerNodes") ?? 3; var k8sVersion = projCfg.Get("kubernetesVersion") ?? "1.37"; var prefixForDns = projCfg.Get("prefixForDns") ?? "pulumi"; var nodeVmSize = projCfg.Get("nodeVmSize") ?? "Standard_DS2_v2";
// The next two configuration values are required (no default can be provided) var mgmtGroupId = projCfg.Require("mgmtGroupId"); var sshPubKey = projCfg.Require("sshPubKey");
// Create a new Azure Resource Group var resourceGroup = new AzureNative.Resources.ResourceGroup("resourceGroup");
// Create a new Azure Virtual Network var virtualNetwork = new AzureNative.Network.VirtualNetwork("virtualNetwork", new() { AddressSpace = new AzureNative.Network.Inputs.AddressSpaceArgs { AddressPrefixes = new[] { "10.0.0.0/16", }, }, ResourceGroupName = resourceGroup.Name, });
// Create three subnets in the virtual network var subnet1 = new AzureNative.Network.Subnet("subnet1", new() { AddressPrefix = "10.0.0.0/22", ResourceGroupName = resourceGroup.Name, VirtualNetworkName = virtualNetwork.Name, });
var subnet2 = new AzureNative.Network.Subnet("subnet2", new() { AddressPrefix = "10.0.4.0/22", ResourceGroupName = resourceGroup.Name, VirtualNetworkName = virtualNetwork.Name, });
var subnet3 = new AzureNative.Network.Subnet("subnet3", new() { AddressPrefix = "10.0.8.0/22", ResourceGroupName = resourceGroup.Name, VirtualNetworkName = virtualNetwork.Name, });
// Create an Azure Kubernetes Cluster var managedCluster = new AzureNative.ContainerService.ManagedCluster("managedCluster", new() { AadProfile =new AzureNative.ContainerService.Inputs.ManagedClusterAADProfileArgs { EnableAzureRBAC = true, Managed = true, AdminGroupObjectIDs = new[] { mgmtGroupId, }, }, AddonProfiles = {}, // Use multiple agent/node pool profiles to distribute nodes across subnets AgentPoolProfiles = new AzureNative.ContainerService.Inputs.ManagedClusterAgentPoolProfileArgs { AvailabilityZones = new[] { "1", "2", "3", }, Count = numWorkerNodes, EnableNodePublicIP = false, Mode = "System", Name = "systempool", OsType = "Linux", OsDiskSizeGB = 30, Type = "VirtualMachineScaleSets", VmSize = nodeVmSize, // Change next line for additional node pools to distribute across subnets VnetSubnetID = subnet1.Id, },
// Change authorizedIPRanges to limit access to API server // Changing enablePrivateCluster requires alternate access to API server (VPN or similar) ApiServerAccessProfile = new AzureNative.ContainerService.Inputs.ManagedClusterAPIServerAccessProfileArgs { AuthorizedIPRanges = new[] { "0.0.0.0/0", }, EnablePrivateCluster = false, }, DnsPrefix = prefixForDns, EnableRBAC = true, Identity = new AzureNative.ContainerService.Inputs.ManagedClusterIdentityArgs { Type = AzureNative.ContainerService.ResourceIdentityType.SystemAssigned, }, KubernetesVersion = k8sVersion, LinuxProfile = new AzureNative.ContainerService.Inputs.ContainerServiceLinuxProfileArgs { AdminUsername = "azureuser", Ssh = new AzureNative.ContainerService.Inputs.ContainerServiceSshConfigurationArgs { PublicKeys = new[] { new AzureNative.ContainerService.Inputs.ContainerServiceSshPublicKeyArgs { KeyData = sshPubKey, }, }, }, }, NetworkProfile = new AzureNative.ContainerService.Inputs.ContainerServiceNetworkProfileArgs { NetworkPlugin = "azure", NetworkPolicy = "azure", ServiceCidr = "10.96.0.0/16", DnsServiceIP = "10.96.0.10", }, ResourceGroupName = resourceGroup.Name, });
// Build a user Kubeconfig // This SHOULD NOT be used for an explicit provider // This SHOULD be used for user logins to the cluster var creds = AzureNative.ContainerService.ListManagedClusterUserCredentials.Invoke(new() { ResourceGroupName = resourceGroup.Name, ResourceName = managedCluster.Name, }); var encoded = creds.Apply(result => result.Kubeconfigs[0]!.Value); var decoded = encoded.Apply(enc => { var bytes = Convert.FromBase64String(enc); return Encoding.UTF8.GetString(bytes); });
// Build an admin Kubeconfig // This SHOULD be used for an explicit provider // This SHOULD NOT be used for user logins to the cluster var adminCreds = AzureNative.ContainerService.ListManagedClusterAdminCredentials.Invoke(new() { ResourceGroupName = resourceGroup.Name, ResourceName = managedCluster.Name, }); var adminEncoded = adminCreds.Apply(result => result.Kubeconfigs[0]!.Value); var adminDecoded = adminEncoded.Apply(enc => { var bytes = Convert.FromBase64String(enc); return Encoding.UTF8.GetString(bytes); });
// Export some values for use elsewhere return new Dictionary<string, object?> { ["rgName"] = resourceGroup.Name, ["networkName"] = virtualNetwork.Name, ["clusterName"] = managedCluster.Name, ["kubeconfig"] = decoded, ["adminKubeconfig"] = Pulumi.Output.CreateSecret(adminDecoded), };});name: my-projectdescription: A Pulumi YAML program to deploy a Kubernetes cluster on Azureruntime: yamlconfig: azure-native:location: value: westus2 numWorkerNodes: type: integer default: 3 prefixForDns: type: string default: pulumi kubernetesVersion: type: string default: "1.37" nodeVmSize: type: string default: Standard_DS2_v2 # The next two configuration values are required (no default can be provided) mgmtGroupId: type: string sshPubKey: type: string
resources: # Create a new resource group resourceGroup: type: azure-native:resources:ResourceGroup # Create a new virtual network virtualNetwork: type: azure-native:network:VirtualNetwork properties: addressSpace: # Define the CIDR used in the new virtual network addressPrefixes: - 10.0.0.0/16 resourceGroupName: ${resourceGroup.name} # Create subnets in the virtual network subnet1: type: azure-native:network:Subnet properties: addressPrefix: 10.0.0.0/22 resourceGroupName: ${resourceGroup.name} virtualNetworkName: ${virtualNetwork.name} subnet2: type: azure-native:network:Subnet properties: addressPrefix: 10.0.4.0/22 resourceGroupName: ${resourceGroup.name} virtualNetworkName: ${virtualNetwork.name} subnet3: type: azure-native:network:Subnet properties: addressPrefix: 10.0.8.0/22 resourceGroupName: ${resourceGroup.name} virtualNetworkName: ${virtualNetwork.name} # Create a managed cluster managedCluster: type: azure-native:containerservice:ManagedCluster properties: aadProfile: enableAzureRBAC: true managed: true # Supply the object ID of an existing Azure AD group to serve as cluster admins adminGroupObjectIDs: - ${mgmtGroupId} addonProfiles: {} agentPoolProfiles: - availabilityZones: ["1","2","3"] count: ${numWorkerNodes} enableNodePublicIP: false mode: System name: systempool osType: Linux type: VirtualMachineScaleSets vmSize: ${nodeVmSize} vnetSubnetID: ${subnet1.id} apiServerAccessProfile: authorizedIPRanges: - 0.0.0.0/0 enablePrivateCluster: false dnsPrefix: ${prefixForDns} enableRBAC: true identity: type: SystemAssigned kubernetesVersion: fn::toJSON: ${kubernetesVersion} linuxProfile: adminUsername: azureuser ssh: publicKeys: - keyData: ${sshPubKey} networkProfile: networkPlugin: azure networkPolicy: azure serviceCidr: 10.96.0.0/16 dnsServiceIP: 10.96.0.10 resourceGroupName: ${resourceGroup.name}
variables: # Create a user Kubeconfig # This SHOULD NOT be used for an explicit provider # This SHOULD be used for user logins to the cluster userKubeconfig: fn::fromBase64: ${aksUserCredentials.kubeconfigs[0].value} # Create a admin Kubeconfig # This SHOULD be used for an explicit provider # This SHOULD NOT be used for user logins to the cluster adminKubeconfig: fn::fromBase64: ${aksAdminCredentials.kubeconfigs[0].value} aksUserCredentials: fn::azure-native:containerservice:listManagedClusterUserCredentials: resourceGroupName: ${resourceGroup.name} resourceName: ${managedCluster.name} aksAdminCredentials: fn::azure-native:containerservice:listManagedClusterAdminCredentials: resourceGroupName: ${resourceGroup.name} resourceName: ${managedCluster.name}
outputs: # Export the Kubeconfig of the cluster clusterName: ${managedCluster.name} kubeconfig: ${userKubeconfig} adminKubeconfig: fn::secret: ${adminKubeconfig}terraform { required_providers { azure-native = { source = "pulumi/azure-native" } }}
variable "node_count" { description = "Number of worker nodes in the cluster" type = number default = 3}
variable "dns_prefix" { description = "DNS prefix for the cluster" type = string default = "pulumi"}
variable "node_vm_size" { description = "VM size to use for worker nodes in the cluster" type = string default = "Standard_DS2_v2"}
# Create a new resource groupresource "azure-native_resources_resource_group" "resource-group" {}
# Create a managed clusterresource "azure-native_containerservice_managed_cluster" "cluster" { resource_group_name = azure-native_resources_resource_group.resource-group.name dns_prefix = var.dns_prefix enable_rbac = true
identity = { type = "SystemAssigned" }
agent_pool_profiles { name = "systempool" count = var.node_count mode = "System" os_type = "Linux" vm_size = var.node_vm_size }}
# Create a user Kubeconfig# This SHOULD NOT be used for an explicit provider# This SHOULD be used for user logins to the clusterdata "azure-native_containerservice_list_managed_cluster_user_credentials" "credentials" { resource_group_name = azure-native_resources_resource_group.resource-group.name resource_name = azure-native_containerservice_managed_cluster.cluster.name}
# Export the Kubeconfig of the clusteroutput "cluster_name" { value = azure-native_containerservice_managed_cluster.cluster.name}
output "kubeconfig" { value = base64decode(data.azure-native_containerservice_list_managed_cluster_user_credentials.credentials.kubeconfigs[0].value) sensitive = true}Deploy the project#
Deploy with pulumi up. It starts with a preview of what it’s about to create and asks before it changes anything. Choose yes to deploy.
pulumi uppulumi upPulumi adds a random suffix to most resource names, so the resource group resourceGroup becomes something like resourceGroup3f8a2c1d. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.
Pulumi adds a random suffix to most resource names, so the resource group resource_group becomes something like resource_group3f8a2c1d. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.
Pulumi adds a random suffix to most resource names, so the resource group resourceGroup becomes something like resourceGroup3f8a2c1d. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.
Pulumi adds a random suffix to most resource names, so the resource group resourceGroup becomes something like resourceGroup3f8a2c1d. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.
Pulumi adds a random suffix to most resource names, so the resource group resourceGroup becomes something like resourceGroup3f8a2c1d. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.
Pulumi adds a random suffix to most resource names, so the resource group resource-group becomes something like resource-group3f8a2c1d. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.
When it finishes, Pulumi prints the stack’s outputs, values it only knows once the resources exist:
- rgName
The name of the Azure Resource Group containing the Kubernetes cluster resources.
- networkName
The name of the Azure Virtual Network used for worker nodes, apps, and workloads.
- clusterName
The name of the AKS cluster.
- kubeconfig
The cluster’s kubeconfig file, which you can use with
kubectlto access and communicate with your cluster.- adminKubeconfig
An admin kubeconfig for the cluster, stored as a secret.
- rgname
The name of the Azure Resource Group containing the Kubernetes cluster resources.
- vnetName
The name of the Azure Virtual Network used for worker nodes, apps, and workloads.
- clusterName
The name of the AKS cluster.
- kubeconfig
The cluster’s kubeconfig file, which you can use with
kubectlto access and communicate with your cluster.- adminKubeconfig
An admin kubeconfig for the cluster, stored as a secret.
- resourceGroupName
The name of the Azure Resource Group containing the Kubernetes cluster resources.
- networkName
The name of the Azure Virtual Network used for worker nodes, apps, and workloads.
- subnet1Name, subnet2Name, subnet3Name
The names of the three subnets in the virtual network.
- clusterName
The name of the AKS cluster.
- kubeconfig
The cluster’s kubeconfig file, which you can use with
kubectlto access and communicate with your cluster.- adminKubeconfig
An admin kubeconfig for the cluster, stored as a secret.
- rgName
The name of the Azure Resource Group containing the Kubernetes cluster resources.
- networkName
The name of the Azure Virtual Network used for worker nodes, apps, and workloads.
- clusterName
The name of the AKS cluster.
- kubeconfig
The cluster’s kubeconfig file, which you can use with
kubectlto access and communicate with your cluster.- adminKubeconfig
An admin kubeconfig for the cluster, stored as a secret.
- clusterName
The name of the AKS cluster.
- kubeconfig
The cluster’s kubeconfig file, which you can use with
kubectlto access and communicate with your cluster.- adminKubeconfig
An admin kubeconfig for the cluster, stored as a secret.
- cluster_name
The name of the AKS cluster.
- kubeconfig
The cluster’s kubeconfig file, which you can use with
kubectlto access and communicate with your cluster.
Read one any time with pulumi stack output <name>, or pass it to another command. The cluster signs you in with Microsoft Entra ID, so save the kubeconfig to a file, let kubelogin switch it to your Azure CLI login, and list the cluster’s nodes. If you don’t have kubelogin, install it with az aks install-cli, or with brew install Azure/kubelogin/kubelogin on macOS or winget install --id=Microsoft.Azure.Kubelogin -e on Windows:
pulumi stack output kubeconfig --show-secrets > kubeconfigkubelogin convert-kubeconfig -l azurecli --kubeconfig kubeconfigkubectl --kubeconfig kubeconfig get nodespulumi stack output kubeconfig --show-secrets | Out-File -Encoding ascii kubeconfigkubelogin convert-kubeconfig -l azurecli --kubeconfig kubeconfigkubectl --kubeconfig kubeconfig get nodesRead one any time with pulumi stack output <name>, or pass it to another command. The cluster signs you in with Microsoft Entra ID, so save the kubeconfig to a file, let kubelogin switch it to your Azure CLI login, and list the cluster’s nodes. If you don’t have kubelogin, install it with az aks install-cli, or with brew install Azure/kubelogin/kubelogin on macOS or winget install --id=Microsoft.Azure.Kubelogin -e on Windows:
pulumi stack output kubeconfig --show-secrets > kubeconfigkubelogin convert-kubeconfig -l azurecli --kubeconfig kubeconfigkubectl --kubeconfig kubeconfig get nodespulumi stack output kubeconfig --show-secrets | Out-File -Encoding ascii kubeconfigkubelogin convert-kubeconfig -l azurecli --kubeconfig kubeconfigkubectl --kubeconfig kubeconfig get nodesRead one any time with pulumi stack output <name>, or pass it to another command. The cluster signs you in with Microsoft Entra ID, so save the kubeconfig to a file, let kubelogin switch it to your Azure CLI login, and list the cluster’s nodes. If you don’t have kubelogin, install it with az aks install-cli, or with brew install Azure/kubelogin/kubelogin on macOS or winget install --id=Microsoft.Azure.Kubelogin -e on Windows:
pulumi stack output kubeconfig --show-secrets > kubeconfigkubelogin convert-kubeconfig -l azurecli --kubeconfig kubeconfigkubectl --kubeconfig kubeconfig get nodespulumi stack output kubeconfig --show-secrets | Out-File -Encoding ascii kubeconfigkubelogin convert-kubeconfig -l azurecli --kubeconfig kubeconfigkubectl --kubeconfig kubeconfig get nodesRead one any time with pulumi stack output <name>, or pass it to another command. The cluster signs you in with Microsoft Entra ID, so save the kubeconfig to a file, let kubelogin switch it to your Azure CLI login, and list the cluster’s nodes. If you don’t have kubelogin, install it with az aks install-cli, or with brew install Azure/kubelogin/kubelogin on macOS or winget install --id=Microsoft.Azure.Kubelogin -e on Windows:
pulumi stack output kubeconfig --show-secrets > kubeconfigkubelogin convert-kubeconfig -l azurecli --kubeconfig kubeconfigkubectl --kubeconfig kubeconfig get nodespulumi stack output kubeconfig --show-secrets | Out-File -Encoding ascii kubeconfigkubelogin convert-kubeconfig -l azurecli --kubeconfig kubeconfigkubectl --kubeconfig kubeconfig get nodesRead one any time with pulumi stack output <name>, or pass it to another command. The cluster signs you in with Microsoft Entra ID, so save the kubeconfig to a file, let kubelogin switch it to your Azure CLI login, and list the cluster’s nodes. If you don’t have kubelogin, install it with az aks install-cli, or with brew install Azure/kubelogin/kubelogin on macOS or winget install --id=Microsoft.Azure.Kubelogin -e on Windows:
pulumi stack output kubeconfig --show-secrets > kubeconfigkubelogin convert-kubeconfig -l azurecli --kubeconfig kubeconfigkubectl --kubeconfig kubeconfig get nodespulumi stack output kubeconfig --show-secrets | Out-File -Encoding ascii kubeconfigkubelogin convert-kubeconfig -l azurecli --kubeconfig kubeconfigkubectl --kubeconfig kubeconfig get nodesRead one any time with pulumi stack output <name>, or pass it to another command. Save the kubeconfig to a file and point kubectl at it to list the cluster’s nodes:
pulumi stack output kubeconfig --show-secrets > kubeconfigkubectl --kubeconfig kubeconfig get nodespulumi stack output kubeconfig --show-secrets | Out-File -Encoding ascii kubeconfigkubectl --kubeconfig kubeconfig get nodesYou should see three nodes with the status Ready.
Need help?
If pulumi up asks you to run az login, or says your sign-in has expired, sign in again:
az loginaz loginStill stuck? Let us know.
Customize the project#
Projects created with this template expose the following configuration settings:
- numWorkerNodes
The number of nodes in your cluster. Defaults to
3.- kubernetesVersion
The version of Kubernetes used in your AKS cluster. Defaults to
1.37.- prefixForDns
The unique DNS prefix for your AKS cluster. Defaults to
pulumi.- nodeVmSize
The VM instance type used to run your nodes. Defaults to
Standard_DS2_v2.
- numWorkerNodes
The number of nodes in your cluster. Defaults to
3.- kubernetesVersion
The version of Kubernetes used in your AKS cluster. Defaults to
1.37.- prefixForDns
The unique DNS prefix for your AKS cluster. Defaults to
pulumi.- nodeVmSize
The VM instance type used to run your nodes. Defaults to
Standard_DS2_v2.
- numWorkerNodes
The number of nodes in your cluster. Defaults to
3.- kubernetesVersion
The version of Kubernetes used in your AKS cluster. Defaults to
1.37.- prefixForDns
The unique DNS prefix for your AKS cluster. Defaults to
pulumi.- nodeVmSize
The VM instance type used to run your nodes. Defaults to
Standard_DS2_v2.
- numWorkerNodes
The number of nodes in your cluster. Defaults to
3.- kubernetesVersion
The version of Kubernetes used in your AKS cluster. Defaults to
1.37.- prefixForDns
The unique DNS prefix for your AKS cluster. Defaults to
pulumi.- nodeVmSize
The VM instance type used to run your nodes. Defaults to
Standard_DS2_v2.
- numWorkerNodes
The number of nodes in your cluster. Defaults to
3.- kubernetesVersion
The version of Kubernetes used in your AKS cluster. Defaults to
1.37.- prefixForDns
The unique DNS prefix for your AKS cluster. Defaults to
pulumi.- nodeVmSize
The VM instance type used to run your nodes. Defaults to
Standard_DS2_v2.
- node_count
The number of worker nodes in the cluster. Defaults to
3.- dns_prefix
The unique DNS prefix to use for the cluster. Defaults to
pulumi.- node_vm_size
The VM size to use for worker nodes. Defaults to
Standard_DS2_v2.
All of these settings are optional and may be adjusted either by editing the stack configuration file directly (by default, Pulumi.dev.yaml) or by changing their values with pulumi config set.
For example, grow the cluster to five nodes:
pulumi config set numWorkerNodes 5pulumi uppulumi config set numWorkerNodes 5pulumi upThe Python program sets the node count to 3 itself instead of reading numWorkerNodes. In __main__.py, change "count": 3, to "count": num_worker_nodes,, then run:
pulumi config set numWorkerNodes 5pulumi uppulumi config set numWorkerNodes 5pulumi uppulumi config set numWorkerNodes 5pulumi uppulumi config set numWorkerNodes 5pulumi uppulumi config set numWorkerNodes 5pulumi uppulumi config set numWorkerNodes 5pulumi uppulumi config set numWorkerNodes 5pulumi uppulumi config set numWorkerNodes 5pulumi uppulumi config set node_count 5pulumi uppulumi config set node_count 5pulumi upWhen it finishes, list the nodes again; there are five:
kubectl --kubeconfig kubeconfig get nodeskubectl --kubeconfig kubeconfig get nodesTo see what else you can add, browse the Azure Native provider in the Pulumi Registry.
Cleaning up#
You can cleanly destroy the stack and all of its infrastructure with pulumi destroy:
pulumi destroypulumi destroyLearn more#
- Browse other architecture templates in the Templates gallery.
- Explore the Azure Native provider API docs in the Pulumi Registry.
- Walk through Pulumi from the ground up in Pulumi Tutorials.
- Read the latest Kubernetes posts on the Pulumi blog.