Deploy the elk-frontend helm chart on Azure Kubernetes Service (AKS)
TypeScriptTo deploy the
elk-frontend
Helm chart on Azure Kubernetes Service (AKS), we will undertake the following steps:- Set up the Azure Kubernetes Service (AKS) cluster using Pulumi.
- Deploy the
elk-frontend
Helm chart to the AKS cluster using Pulumi's Kubernetes provider.
We'll create the AKS cluster first, and then deploy the Helm chart onto this cluster. Pulumi enables you to seamlessly create cloud resources and workloads such as Kubernetes services using code and programming languages.
Below is a Pulumi TypeScript program that performs these operations:
Step 1: Create an AKS Cluster
First, we configure the AKS cluster. We define the AKS cluster with the desired node count, node size, and default node pool settings. Using the
azure-native
provider, we interact directly with Azure's APIs in a native way without any abstractions.Step 2: Deploy the Helm Chart
After creating the AKS cluster, we will deploy the Helm chart. We need to configure Pulumi to use the Kubernetes provider that connects to the created AKS cluster. The
kubernetes.helm.v3.Chart
resource will deploy the Helm chart on this cluster.Let's write the Pulumi program:
import * as pulumi from '@pulumi/pulumi'; import * as azure_native from '@pulumi/azure-native'; import * as k8s from '@pulumi/kubernetes'; // Step 1: Create an Azure Resource Group const resourceGroup = new azure_native.resources.ResourceGroup("aksResourceGroup"); // Step 2: Create the AKS cluster const aksCluster = new azure_native.containerservice.ManagedCluster("aksCluster", { resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 1, maxPods: 110, mode: "System", name: "agentpool", osDiskSizeGB: 30, osType: "Linux", vmSize: "Standard_D2_v2", }], dnsPrefix: "aks", enableRBAC: true, kubernetesVersion: "1.19.11", linuxProfile: { adminUsername: "aksuser", ssh: { publicKeys: [{ keyData: "ssh-rsa AAAAB3Nz...", }], }, }, nodeResourceGroup: "nodeResourceGroup", resourceGroupName: resourceGroup.name, }); // Export the AKS cluster's kubeconfig export const kubeconfig = pulumi.all([aksCluster.name, resourceGroup.name]).apply(([name, rgName]) => azure_native.containerservice.listManagedClusterUserCredentials({ resourceName: name, resourceGroupName: rgName, }).then(creds => { const encoded = creds.kubeconfigs[0].value; return Buffer.from(encoded, 'base64').toString(); }) ); // Step 3: Configure Kubernetes provider to connect to the AKS cluster const provider = new k8s.Provider("k8sProvider", { kubeconfig: kubeconfig, }); // Step 4: Deploy the elk-frontend Helm chart on the cluster const elkChart = new k8s.helm.v3.Chart("elk-frontend", { chart: "elk-frontend", version: "1.0.0", fetchOpts:{ repo: "http://charts.myorg.com", // Specify the Helm chart repository URL here }, }, { provider }); // Export the frontend service public endpoint export const frontendIp = elkChart.getResourceProperty("v1/Service", "elk-frontend", "status") .apply(status => status.loadBalancer.ingress[0].ip);
Explanation and Steps
- We begin by importing necessary Pulumi packages for interacting with Azure and Kubernetes.
- We create a new Azure Resource Group
aksResourceGroup
that will hold all related resources for the AKS cluster. - We define the AKS cluster
aksCluster
with a single system node pool for simplicity. We also set RBAC, the Kubernetes version and set up an SSH public key for access. - We then generate a kubeconfig using the
listManagedClusterUserCredentials
function from Azure, which enables us to connect to our AKS cluster programmatically. - We instantiate the Kubernetes provider
provider
with the kubeconfig from the newly created cluster. - We then deploy the
elk-frontend
Helm chart using the Kubernetes provider with theChart
resource from the Pulumi Kubernetes Helm package. You should replace thechart
andrepo
parameters with the appropriate values for theelk-frontend
Helm chart. - Finally, we export two crucial outputs from our program: the
kubeconfig
for potential external use, and the public IP address of the frontend servicefrontendIp
, once the deployment is complete and services are allocated IP addresses by Azure.
To run this program, save it in a
index.ts
file, ensure you have the Pulumi CLI installed, and runpulumi up
. It will prompt you for confirmation before creating the resources in Azure.Remember: Before you run
pulumi up
, authenticate with Azure CLI usingaz login
and set up the Pulumi Azure Native provider with the required credentials via environment variables or Pulumi config.