Azure Kubernetes Service (AKS) Cluster and Helm Chart
This example demonstrates creating an Azure Kubernetes Service (AKS) Cluster, and deploying a Helm Chart into it, all in one Pulumi program. Please see https://docs.microsoft.com/en-us/azure/aks/ for more information about AKS.
Ensure you have downloaded and installed the Pulumi CLI.
This example deploys a Helm Chart from Bitnami’s Helm chart repository
In addition you will need the following CLI tools:
$ az --version # Azure CLI azure-cli 2.11.1 core 2.11.1 telemetry 1.0.5 ... $ npm --version # Node.js Package Manager 6.14.6 $ tsc --version # TypeScript compiler Version 4.0.2
Running the Example
After cloning this repo,
cd into it and run these commands. A Kubernetes cluster and Apache web server will appear!
Login to your Azure account:
$ az login
Download nodejs dependencies:
$ npm install
Create a new stack, which is an isolated deployment target for this example:
$ pulumi stack init
Set the required configuration variables for this program:
$ pulumi config set azure:environment public $ pulumi config set password --secret [your-cluster-password-here] $ ssh-keygen -t rsa -f key.rsa $ pulumi config set sshPublicKey < key.rsa.pub
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:
Note: Due to an issue in Azure Terraform Provider, the creation of an Azure Service Principal, which is needed to create the Kubernetes cluster (see cluster.ts), 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 upagain, at which time the Service Principal replication should have been completed. See this issue and this doc for further details.
$ pulumi up
After a couple minutes, your cluster and Apache server will be ready. Three output variables will be printed, reflecting your cluster name (
cluster), Kubernetes config (
kubeConfig) and server IP address (
Using these output variables, you may
curlyour Apache server’s
$ curl $(pulumi stack output serviceIP) <html><body><h1>It works!</h1></body></html>
And you may also configure your
kubectlclient using the
$ pulumi stack output kubeconfig --show-secrets > kubeconfig.yaml $ KUBECONFIG=./kubeconfig.yaml kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE apache-apache LoadBalancer 10.0.125.196 18.104.22.168 80:32080/TCP,443:31419/TCP 9m kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 13h
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:
$ pulumi destroy $ pulumi stack rm
If you make changes to the example
tscode outside of an IDE, run the TypeScript compiler to check your changes:
$ tsc --build tsconfig.json