1. Deploy the opentelemetry-demo helm chart on Azure Kubernetes Service (AKS)

    TypeScript

    To deploy the opentelemetry-demo Helm chart on Azure Kubernetes Service (AKS) using Pulumi, you'll perform several steps which include:

    1. Provisioning an AKS cluster.
    2. Deploying the Helm chart to the AKS cluster.

    I'll provide you with a detailed Pulumi program in TypeScript to achieve this. We will use two main resources from Pulumi:

    • KubernetesCluster from the azure.containerservice package: This resource will be used to create and manage an AKS cluster.
    • Chart from the kubernetes.helm.sh/v3 package: This resource will deploy a Helm chart onto a Kubernetes cluster.

    Before we begin with the code, please make sure you have the following prerequisites:

    • Pulumi CLI installed and logged in.
    • Azure CLI installed and logged in.
    • An Azure subscription and resource group.
    • The kubectl tool installed to interact with Kubernetes clusters.

    Now let's go through the steps to create a program that deploys opentelemetry-demo on AKS using Pulumi.

    Step 1: Set up the Pulumi project

    Create a new directory for your Pulumi project and initialize it:

    mkdir pulumi-opentelemetry-demo-aks cd pulumi-opentelemetry-demo-aks pulumi new azure-typescript

    Step 2: Writing the Pulumi Program

    Here is the TypeScript program which includes the necessary imports, the creation of the AKS cluster resource, and the deployment of the opentelemetry-demo Helm chart onto the cluster.

    import * as pulumi from "@pulumi/pulumi"; import * as azure from "@pulumi/azure"; import * as azuread from "@pulumi/azuread"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create an AKS cluster const resourceGroupName = "pulumi-opentelemetry-rg"; const resourceGroup = new azure.core.ResourceGroup(resourceGroupName, { location: "East US", // Choose the location appropriate for you }); // Service Principal (replace appId and password with your own) const adApp = new azuread.Application("aks"); const adSp = new azuread.ServicePrincipal("aksSp", { applicationId: adApp.applicationId }); const adSpPassword = new azuread.ServicePrincipalPassword("aksSpPassword", { servicePrincipalId: adSp.id, value: "<password>", endDate: "2099-01-01T00:00:00Z", }); // Create an AKS cluster const cluster = new azure.containerservice.KubernetesCluster("opentelemetry-aks", { resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 2, maxPods: 110, mode: "System", name: "agentpool", osDiskSizeGb: 30, osType: "Linux", vmSize: "Standard_DS2_v2", }], dnsPrefix: "pulumi-opentelemetry-k8s", linuxProfile: { adminUsername: "pulumi", sshKey: { keyData: "<ssh-rsa PUBLIC KEY>", }, }, servicePrincipal: { clientId: adApp.applicationId, clientSecret: adSpPassword.value, }, roleBasedAccessControl: { enabled: true, }, tags: { "project": "pulumi-opentelemetry-demo", }, }); const creds = pulumi.all([cluster.name, resourceGroup.name]).apply(([clusterName, rgName]) => { return azure.containerservice.getKubernetesCluster({ name: clusterName, resourceGroupName: rgName, }); }); const kubeConfig = creds.kubeConfigRaw; // Step 2: Deploy the opentelemetry-demo Helm chart on the AKS cluster const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: kubeConfig, }); const chart = new k8s.helm.v3.Chart("opentelemetry-demo", { chart: "opentelemetry-demo", version: "1.0.0", // Specify the version you want to deploy // Add your values.yaml properties here // For example, to enable persistence: // values: { // persistence: { // enabled: true, // storageClassName: "default", // accessMode: "ReadWriteOnce", // size: "1Gi" // } // }, }, { provider: k8sProvider }); // Export the cluster's kubeconfig. export const kubeConfigOut = kubeConfig;

    Replace <password>, <ssh-rsa PUBLIC KEY> with your Azure AD service principal password and SSH public key, respectively.

    Explanation:

    1. We start with importing the required Pulumi packages.
    2. We define a resource group for our AKS cluster.
    3. We then set up Azure AD application and service principal which AKS uses for integration with Azure APIs.
    4. We create the AKS cluster using the KubernetesCluster resource.
      • The agentPoolProfiles describes the size and count of nodes.
      • The linuxProfile provides SSH access configurations.
      • We enable RBAC for our cluster for better security.
    5. We fetch the generated kubeconfig from the created AKS cluster which is required to authenticate against our Kubernetes cluster.
    6. We set up a Pulumi Kubernetes provider using the kubeconfig which allows us to deploy Kubernetes resources.
    7. We deploy the opentelemetry-demo Helm chart using the Chart resource.
    8. Finally, we export the kubeconfig so you can use it locally with kubectl if needed.

    Conclusion:

    After writing this program in a file named index.ts, run pulumi up in the terminal from the same directory. Pulumi will perform the deployment, and once complete, the opentelemetry-demo application will be running on your AKS cluster.

    To clean up the resources after you are done with them, you can run pulumi destroy. Remember that this will tear down everything made by this program, including the AKS cluster.