Add azure-ts-aks-helm
Add azure-ts-aks-helm example
ADD
azure-ts-aks-helm/.gitignore
+/bin/
+/node_modules/

ADD
azure-ts-aks-helm/Pulumi.yaml
+name: azure-ts-aks-helm
+runtime: nodejs
+description: Azure Native TypeScript Pulumi example featuring Helm chart deployment
+ to AKS

ADD
azure-ts-aks-helm/README.md
+[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)
+
+# Azure Kubernetes Service (AKS) Cluster and Helm Chart
+
+This example demonstrates creating an [Azure Kubernetes Service (AKS)](https://docs.microsoft.com/en-us/azure/aks/)
+cluster and deploying a Helm Chart from [Bitnami Helm chart repository](https://github.com/bitnami/charts)
+into this cluster, all in one Pulumi program.
+
+The example showcases the [native Azure provider for Pulumi](https://www.pulumi.com/docs/intro/cloud-providers/azure/).
+
+
+## Prerequisites
+
+- Install [Pulumi](https://www.pulumi.com/docs/get-started/install/).
+
+- Install [TypeScript](https://www.typescriptlang.org/#installation) and [NPM](https://www.npmjs.com/get-npm).
+
+- 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](https://azure.microsoft.com/en-us/free/).
+
+- Setup and authenticate the [native Azure provider for Pulumi](https://www.pulumi.com/docs/intro/cloud-providers/azure/setup/).
+
+
+## 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.
+
+1. Get the code:
+
+ ```bash
+ $ git clone git@github.com:pulumi/examples.git
+ $ cd examples/azure-ts-aks-helm
+ ```
+
+2. Restore dependencies:
+
+ ```bash
+ $ npm install
+ # OR
+ $ yarn install
+ ```
+
+3. Create a new stack, which is an isolated deployment target for this example:
+
+ ```bash
+ $ pulumi stack init
+ ```
+
+4. Set the required configuration variables for this program:
+
+ ```bash
+ $ pulumi config set azure-native:location westus2
+ ```
+
+5. Deploy everything with the `pulumi up` command. 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):
+
+ ```bash
+ $ pulumi up
+ ```
+
+6. 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 (`apacheServiceIP`).
+
+ Using these output variables, you may access your Apache server:
+
+ ```bash
+ $ curl $(pulumi stack output apacheServiceIP)
+ <html><body><h1>It works!</h1></body></html>
+ ```
+
+ And you may also configure your `kubectl` client using the
+ `kubeConfig` configuration:
+
+ ```bash
+ $ 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
+ ```
+
+7. 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.
+
+ TIP: if you make changes to the example code outside of an IDE, run
+ the TypeScript compiler to type-check your changes before executing
+ them:
+
+ ```bash
+ $ tsc --build tsconfig.json
+ ```
+
+8. Once you are done, you can destroy all of the resources, and the
+ stack:
+
+ ```bash
+ $ pulumi destroy
+ $ pulumi stack rm
+ $ rm kubeconfig.yaml
+ ```

ADD
azure-ts-aks-helm/cluster.ts
+// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
+
+import * as containerservice from "@pulumi/azure-native/containerservice";
+import * as resources from "@pulumi/azure-native/resources";
+import * as azuread from "@pulumi/azuread";
+import * as k8s from "@pulumi/kubernetes";
+import * as pulumi from "@pulumi/pulumi";
+
+import * as config from "./config";
+
+const resourceGroup = new resources.ResourceGroup("rg");
+
+const adApp = new azuread.Application("app");
+
+const adSp = new azuread.ServicePrincipal("service-principal", {
+ applicationId: adApp.applicationId,
+});
+
+const adSpPassword = new azuread.ServicePrincipalPassword("sp-password", {
+ servicePrincipalId: adSp.id,
+ value: config.password,
+ endDate: "2099-01-01T00:00:00Z",
+});
+
+export const k8sCluster = new containerservice.ManagedCluster("cluster", {
+ resourceGroupName: resourceGroup.name,
+ addonProfiles: {
+ KubeDashboard: {
+ enabled: true,
+ },
+ },
+ agentPoolProfiles: [{
+ count: config.nodeCount,
+ maxPods: 110,
+ mode: "System",
+ name: "agentpool",
+ nodeLabels: {},
+ osDiskSizeGB: 30,
+ osType: "Linux",
+ type: "VirtualMachineScaleSets",
+ vmSize: config.nodeSize,
+ }],
+ dnsPrefix: resourceGroup.name,
+ enableRBAC: true,
+ kubernetesVersion: config.k8sVersion,
+ linuxProfile: {
+ adminUsername: config.adminUserName,
+ ssh: {
+ publicKeys: [{
+ keyData: config.sshPublicKey,
+ }],
+ },
+ },
+ nodeResourceGroup: "node-resource-group",
+ servicePrincipalProfile: {
+ clientId: adApp.applicationId,
+ secret: adSpPassword.value,
+ },
+});
+
+const creds = pulumi.all([k8sCluster.name, resourceGroup.name]).apply(([clusterName, rgName]) => {
+ return containerservice.listManagedClusterUserCredentials({
+ resourceGroupName: rgName,
+ resourceName: clusterName,
+ });
+});
+
+export const kubeconfig =
+ creds.kubeconfigs[0].value
+ .apply(enc => Buffer.from(enc, "base64").toString());
+
+export const k8sProvider = new k8s.Provider("k8s-provider", {
+ kubeconfig: kubeconfig,
+});

ADD
azure-ts-aks-helm/config.ts
+// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
+
+import * as pulumi from "@pulumi/pulumi";
+import * as random from "@pulumi/random";
+import * as tls from "@pulumi/tls";
+
+const config = new pulumi.Config();
+
+export const k8sVersion = config.get("k8sVersion") || "1.18.14";
+
+export const password = config.get("password") || new random.RandomPassword("pw", {
+ length: 20,
+ special: true,
+}).result;
+
+export const generatedKeyPair = new tls.PrivateKey("ssh-key", {
+ algorithm: "RSA",
+ rsaBits: 4096,
+});
+
+export const adminUserName = config.get("adminUserName") || "testuser";
+
+export const sshPublicKey = config.get("sshPublicKey") || generatedKeyPair.publicKeyOpenssh;
+
+export const nodeCount = config.getNumber("nodeCount") || 2;
+
+export const nodeSize = config.get("nodeSize") || "Standard_D2_v2";

ADD
azure-ts-aks-helm/index.ts
+// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
+
+import * as k8s from "@pulumi/kubernetes";
+
+import * as cluster from "./cluster";
+
+export let clusterName = cluster.k8sCluster.name;
+
+export let kubeconfig = cluster.kubeconfig;
+
+const apache = new k8s.helm.v3.Chart(
+ "apache-chart",
+ {
+ repo: "bitnami",
+ chart: "apache",
+ version: "8.3.2",
+ fetchOpts: {
+ repo: "https://charts.bitnami.com/bitnami",
+ },
+ },
+ { provider: cluster.k8sProvider },
+);
+
+export let apacheServiceIP = apache
+ .getResourceProperty("v1/Service", "apache-chart", "status")
+ .apply(status => status.loadBalancer.ingress[0].ip);

ADD
azure-ts-aks-helm/package.json
+{
+ "name": "azure-ts-aks-helm",
+ "devDependencies": {
+ "@types/node": "^10.0.0"
+ },
+ "dependencies": {
+ "@pulumi/pulumi": "^2.0.0",
+ "@pulumi/azuread": "^2.4.0",
+ "@pulumi/azure-native": "^0.7.1",
+ "@pulumi/kubernetes": "^2.0.0",
+ "@pulumi/random": "^2.2.0",
+ "@pulumi/tls": "v2.2.0"
+ }
+}

ADD
azure-ts-aks-helm/tsconfig.json
+{
+ "compilerOptions": {
+ "strict": true,
+ "outDir": "bin",
+ "target": "es2016",
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "sourceMap": true,
+ "experimentalDecorators": true,
+ "pretty": true,
+ "noFallthroughCasesInSwitch": true,
+ "noImplicitReturns": true,
+ "forceConsistentCasingInFileNames": true
+ },
+ "files": [
+ "config.ts",
+ "cluster.ts",
+ "index.ts"
+ ]
+}

Add azure-ts-aks-helm (#941)

Add azure-ts-aks-helm example