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:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set azure-py-aks-helmcd pulumi-examples/azure-py-aks-helmThis 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.
Prerequisites#
-
Install Pulumi.
-
Install Python 3.6 or higher.
-
We will be deploying to Azure, so you will need an Azure account. If you do not have an account, sign up for free here.
-
Setup and authenticate the native Azure provider for Pulumi.
Running the Example#
In this example we will provision a Kubernetes cluster running a public Apache web server, verify we can access it, and clean up when done.
-
Get the code:
Terminal window git clone git@github.com:pulumi/examples.gitcd examples/azure-py-aks-helm -
Create a new stack, which is an isolated deployment target for this example:
Terminal window pulumi stack init -
Set the required configuration variables for this program:
Terminal window pulumi config set azure-native:location westus2 -
Deploy everything with the
pulumi upcommand. This provisions all the Azure resources necessary, including an Active Directory service principal, AKS cluster, and then deploys the Apache Helm Chart, all in a single gesture (takes 5-10 min):Terminal window pulumi upNote: this command will create a virtual environment and restore dependencies automatically as described in Pulumi docs.
-
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
kubectlclient using thekubeconfigconfiguration:Terminal window pulumi stack output kubeconfig --show-secrets > kubeconfig.yamlKUBECONFIG=./kubeconfig.yaml kubectl get serviceNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEapache-chart LoadBalancer 10.0.154.121 40.125.100.104 80:30472/TCP,443:30364/TCP 8mkubernetes ClusterIP 10.0.0.1 <none> 443/TCP 8m -
At this point, you have a running cluster. Feel free to modify your program, and run
pulumi upto 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. -
Once you are done, you can destroy all of the resources, and the stack:
Terminal window pulumi destroypulumi stack rmrm kubeconfig.yaml