Deploy the nodelocaldns helm chart on Azure Kubernetes Service (AKS)
TypeScriptTo deploy the
nodelocaldns
Helm chart on an Azure Kubernetes Service (AKS) cluster using Pulumi, we'll complete a few high-level steps:- Provision an AKS cluster using the
azure-native
package. - Install the Helm chart onto the AKS cluster by utilizing the
kubernetes
provider.
Before we begin, make sure you have Pulumi installed and set up with the correct Azure credentials.
For step 1, using the
azure-native
package, we'll instantiate a new AKS cluster. Theazure-native
package is the Pulumi equivalent of using Azure's API directly, which allows you to interact with Azure resources using Pulumi's infrastructure as code approach.For step 2, once the AKS cluster is ready, we'll use Pulumi's
kubernetes
provider to deploy thenodelocaldns
Helm chart. Pulumi'skubernetes
package can be used to operate Kubernetes resources, including deploying Helm charts.Below is the TypeScript program that accomplishes these steps. This program assumes that you already have the
@pulumi/azure-native
and@pulumi/kubernetes
packages installed. If not, you can install them by runningnpm install @pulumi/azure-native @pulumi/kubernetes
.import * as pulumi from "@pulumi/pulumi"; import * as azureNative from "@pulumi/azure-native"; import * as k8s from "@pulumi/kubernetes"; // Create an Azure Resource Group const resourceGroup = new azureNative.resources.ResourceGroup("aksResourceGroup"); // Create an AKS cluster const aksCluster = new azureNative.containerservice.ManagedCluster("aksCluster", { resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 1, maxPods: 110, mode: "System", name: "agentpool", osDiskSizeGB: 30, osType: "Linux", vmSize: "Standard_DS2_v2", }], dnsPrefix: "aksk8s", enableRBAC: true, kubernetesVersion: "1.21.1", linuxProfile: { adminUsername: "aksuser", ssh: { publicKeys: [{ keyData: "<SSH_PUBLIC_KEY>", // replace with your SSH public key }], }, }, location: resourceGroup.location, }); // Export the kubeconfig export const kubeconfig = aksCluster.kubeConfigRaw; // Create a Kubernetes provider instance using the kubeconfig from the AKS cluster const k8sProvider = new k8s.Provider("k8sProvider", { kubeconfig: aksCluster.kubeConfigRaw, }); // Deploy the nodelocaldns Helm chart on the AKS cluster const nodelocaldnsChart = new k8s.helm.v3.Chart("nodelocaldns", { chart: "nodelocaldns", version: "1.15.13", // specify the version of the chart you want to deploy fetchOpts: { repo: "https://kubernetes-sigs.github.io/nodelocaldns/", // replace with the correct Helm repo URL }, }, { provider: k8sProvider }); // Export the Helm chart's status export const nodelocaldnsStatus = nodelocaldnsChart.status;
Make sure to replace the
<SSH_PUBLIC_KEY>
placeholder with your actual SSH public key.This program performs the following actions:
- It creates an Azure resource group to hold the AKS cluster.
- It provisions a new AKS cluster with one node in the "System" pool.
- It exports the kubeconfig required to interact with the AKS cluster via kubectl.
- It creates a Pulumi Kubernetes provider that uses this kubeconfig.
- It deploys the
nodelocaldns
Helm chart on the AKS cluster, specifying the version of the chart and the repository from which to fetch the chart.
Once you have replaced the placeholder with your SSH public key and reviewed the program, save it to a
.ts
file and run thepulumi up
command in the same directory to create the resources.Remember that the AKS cluster will incur costs on Azure, and leaving it running will lead to ongoing charges on your Azure account. Remember to destroy the cluster with
pulumi destroy
if it was only for testing.- Provision an AKS cluster using the