Azure Kubernetes Service (AKS) Cluster and Helm Chart
The example showcases the native Azure provider for Pulumi.
Install .NET Core
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:
$ git clone email@example.com:pulumi/examples.git $ cd examples/azure-cs-aks-helm
Restore dependencies and build:
$ dotnet build
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-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):
$ pulumi up
Now your cluster and Apache server are ready. Several output variables will be printed, including your cluster name (
ClusterName), Kubernetes config (
Kubeconfig) and server IP address (
Using these output variables, you may access your Apache server:
$ curl $(pulumi stack output ApacheServiceIP) <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-chart LoadBalancer 10.0.58.153 220.127.116.11 80:32707/TCP,443:32495/TCP 3m23s kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 21m
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.
TIP: if you make changes to the example code outside of an IDE, run the C# compiler after every change:
$ dotnet build
Once you are done, you can destroy all of the resources, and the stack:
$ pulumi destroy $ pulumi stack rm $ rm kubeconfig.yaml