Deploy the stackdriver-metrics-adapter helm chart on Azure Kubernetes Service (AKS)
TypeScriptTo deploy the Stackdriver Metrics Adapter on an Azure Kubernetes Service (AKS) cluster using Pulumi, we will need to first ensure that we have an AKS cluster available. Then we will use the
kubernetes.helm.v3.Chart
resource to deploy the Stackdriver Metrics Adapter Helm chart to the cluster.Below is a step-by-step Pulumi program written in TypeScript that will:
- Provision an AKS cluster using the
azure-native.containerservice.ManagedCluster
resource. - Use the
kubernetes.helm.v3.Chart
resource from the Kubernetes provider to deploy the Stackdriver Metrics Adapter Helm chart to the provisioned AKS cluster.
Ensure that you have the Pulumi CLI installed and configured with Azure credentials.
Let's go through the code:
import * as azure from "@pulumi/azure-native"; import * as pulumi from "@pulumi/pulumi"; import * as k8s from "@pulumi/kubernetes"; // Create an Azure Resource Group const resourceGroup = new azure.resources.ResourceGroup("myResourceGroup"); // Create an AKS cluster const cluster = new azure.containerservice.ManagedCluster("myAksCluster", { resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 1, maxPods: 110, mode: "System", name: "agentpool", osDiskSizeGB: 30, osType: "Linux", vmSize: "Standard_DS2_v2", }], dnsPrefix: "myakscluster", enableRBAC: true, kubernetesVersion: "1.18.14", linuxProfile: { adminUsername: "testuser", ssh: { publicKeys: [{ keyData: "ssh-rsa YOUR_SSH_PUBLIC_KEY", }], }, }, identity: { type: "SystemAssigned", }, location: resourceGroup.location, }); // Export the Cluster's kubeconfig export const kubeconfig = pulumi. all([cluster.name, resourceGroup.name]). apply(([clusterName, rgName]) => { return azure.containerservice.listManagedClusterUserCredentials({ resourceGroupName: rgName, resourceName: clusterName, }); }).apply(creds => { const enc = new Buffer(creds.kubeconfigs[0].value, "base64"); return enc.toString(); }); // Create a Kubernetes provider instance that uses our cluster from above. const k8sProvider = new k8s.Provider("k8sProvider", { kubeconfig: kubeconfig, }); // Deploy the Stackdriver Metrics Adapter using Helm const metricsAdapterChart = new k8s.helm.v3.Chart("stackdriver-metrics-adapter", { chart: "stackdriver-metrics-adapter", fetchOpts: { repo: "http://stackdriver-metrics-adapter-charts.storage.googleapis.com", }, // If Stackdriver Metrics Adapter requires additional values, specify them here // values: { ... } }, { provider: k8sProvider });
The above program does the following:
-
Resource Group: We create a new Azure Resource Group which is a container that holds related resources for an Azure solution.
-
AKS Cluster: We provision an AKS cluster using the
azure.containerservice.ManagedCluster
resource, specifying various configurations such as the size of the VMs in the agent pool and the Kubernetes version. -
Kubeconfig: This step exports the kubeconfig file needed to connect to the Kubernetes cluster. It retrieves the user credentials for the cluster that allow us to deploy applications on it.
-
Kubernetes Provider: We create a Pulumi Kubernetes provider which is responsible for deploying Kubernetes resources and uses the kubeconfig we got from the AKS cluster.
-
Helm Chart: Finally, we use the Pulumi Kubernetes provider to deploy the Stackdriver Metrics Adapter Helm chart into the AKS cluster. The Helm chart is referenced by its name, and you can optionally provide configuration values specific to the Stackdriver Metrics Adapter.
Replace
"YOUR_SSH_PUBLIC_KEY"
with your actual SSH public key.The
metricsAdapterChart
instance will deploy the Helm chart to your AKS cluster. If there are any additional configurations or custom values you need to apply to the Stackdriver Metrics Adapter, you would specify them in thevalues
argument in the Helm chart resource.Please note that in order to apply this Pulumi program, you should save it to a file (e.g.,
index.ts
), then runpulumi up
to execute it, upon which Pulumi will perform the deployment.For more information on the resources used:
- Provision an AKS cluster using the