Skip to main content

Multiple Azure Kubernetes Service (AKS) clusters

Create multiple Azure Kubernetes Service (AKS) clusters in different regions and with different node counts

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 classic-azure-go-aks-multicluster
cd pulumi-examples/classic-azure-go-aks-multicluster

This example demonstrates creating multiple Azure Kubernetes Service (AKS) clusters in different regions and with different node counts. Please see https://docs.microsoft.com/en-us/azure/aks/ for more information about AKS.

Prerequisites#

  1. Install Pulumi
  2. Configure Azure credentials
  3. Install Go

Deploying the example#

Note: Due to an issue in the Azure Terraform Provider (https://github.com/terraform-providers/terraform-provider-azurerm/issues/1635) the creation of an Azure Service Principal, which is needed to create the Kubernetes cluster (see main.go), is delayed and may not be available when the cluster is created. If you get a Service Principal not found error, as a work around, you should be able to run pulumi up again, at which time the Service Principal should have been created.

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

    Terminal window
    pulumi stack init
  2. Set the required configuration variables for this program:

    Terminal window
    pulumi config set azure:environment public
    pulumi config set azure:subscriptionId <YOUR_SUBSCRIPTION_ID>
    ssh-keygen -t rsa -f key.rsa
    pulumi config set sshPublicKey < key.rsa.pub
  3. Install dependencies:

    Terminal window
    go mod download
  4. Deploy everything with the pulumi up command. This provisions all the Azure resources necessary, including an Active Directory service principal and AKS clusters:

    Terminal window
    pulumi up
  5. After a couple minutes, your AKS clusters will be ready. The AKS cluster names will be printed as output variables once pulumi up completes.

    Outputs:
    + aksClusterNames: [
    + [0]: "akscluster-east7f398a0b"
    + [1]: "akscluster-west7ee96bf1"
    ]
  6. At this point, you have multiple AKS clusters running in different regions. Feel free to modify your program, and run pulumi up to redeploy changes. The Pulumi CLI automatically detects what has changed and makes the minimal edits necessary to accomplish these changes.

Cleaning up#

Once you are done, destroy all of the resources and the stack:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.