Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Azure Kubernetes Service (AKS) cluster and Helm chart

Azure Native Python Pulumi example featuring Helm chart deployment to AKS

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 azure-py-aks-helm
cd pulumi-examples/azure-py-aks-helm

This example demonstrates creating an Azure Kubernetes Service (AKS) cluster and deploying a Helm Chart from Bitnami Helm chart repository into this cluster, all in one Pulumi program.

The example showcases the native Azure provider for Pulumi. It provisions a Kubernetes cluster running a public Apache web server, verifies we can access it, and cleans up when done.

Prerequisites#

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

Deploying the example#

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

    Terminal window
    pulumi stack init
  2. Set the Azure region location to use:

    Terminal window
    pulumi config set azure-native:location westus2
  3. Install dependencies:

    Terminal window
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  4. Deploy everything with the pulumi up command. This provisions all the Azure resources necessary, including an Active Directory service principal and AKS cluster, and then deploys the Apache Helm Chart, all in a single gesture (takes 5-10 min):

    Terminal window
    pulumi up
  5. Now your cluster and Apache server are ready. Several output variables will be printed, including your cluster name (cluster_name), Kubernetes config (kubeconfig) and server IP address (apache_service_ip).

    Using these output variables, you may access your Apache server:

    Terminal window
    curl $(pulumi stack output apache_service_ip)
    <html><body><h1>It works!</h1></body></html>

    And you may also configure your kubectl client using the kubeconfig configuration:

    Terminal window
    pulumi stack output kubeconfig --show-secrets > kubeconfig.yaml
    KUBECONFIG=./kubeconfig.yaml kubectl get service
    NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    apache-chart LoadBalancer 10.0.154.121 40.125.100.104 80:30472/TCP,443:30364/TCP 8m
    kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 8m
  6. At this point, you have a running cluster. 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. This could be altering the existing chart, adding new Azure or Kubernetes resources, or anything, really.

Cleaning up#

Once you’re finished experimenting, you can destroy your stack and remove it to avoid incurring any additional cost:

Terminal window
pulumi destroy
pulumi stack rm
rm kubeconfig.yaml

Related

The infrastructure as code platform for any cloud.