Deploy the mailtrain helm chart on Azure Kubernetes Service (AKS)
TypeScriptTo deploy the Mailtrain Helm chart on Azure Kubernetes Service (AKS), you will first need to provision an AKS cluster. After setting up the AKS cluster, you can configure Pulumi to deploy the Helm chart onto the AKS cluster.
Here are the steps we're going to follow in this Pulumi program:
- Provision an AKS cluster using the
azure-native
provider, which is Pulumi's native Azure provider offering fine-grained resources and reflecting the latest API features. - Deploy the Mailtrain Helm chart using Pulumi's
kubernetes
provider once the AKS cluster is up and running.
Prerequisites
Before running the Pulumi program:
- Install Pulumi CLI.
- Install Node.js.
- Set up Azure CLI and log in using
az login
. - Configure Azure credentials for Pulumi using
az account get-access-token
as Pulumi will use them to provision resources.
Now, here's the full TypeScript program to deploy the Mailtrain helm chart on AKS:
import * as pulumi from '@pulumi/pulumi'; import * as azure_native from '@pulumi/azure-native'; import * as k8s from '@pulumi/kubernetes'; // Step 1: Provision an Azure Kubernetes Service (AKS) cluster // The following code will provision a basic AKS cluster with default settings. const resourceGroup = new azure_native.resources.ResourceGroup('myResourceGroup'); const aksCluster = new azure_native.containerservice.ManagedCluster('myAKSCluster', { resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 1, vmSize: 'Standard_DS2_v2', name: 'agentpool', mode: 'System', }], dnsPrefix: 'myakscluster', identity: { type: 'SystemAssigned', }, kubernetesVersion: '1.20.9', location: resourceGroup.location, }); // Step 2: Deploy the Mailtrain helm chart onto the AKS cluster // After the cluster is created, we configure the kubernetes provider to deploy the Mailtrain helm chart. // Expose the kubeconfig of the cluster export const kubeconfig = aksCluster.kubeConfigRaw; const k8sProvider = new k8s.Provider('k8s-provider', { kubeconfig: kubeconfig, }); // Deploy the Mailtrain helm chart const mailtrainChart = new k8s.helm.v3.Chart('mailtrain', { chart: 'mailtrain', version: '1.24.1', // Use the appropriate version fetchOpts: { repo: 'https://charts.example.com/', // Use the Helm repository URL that hosts the Mailtrain chart }, }, { provider: k8sProvider }); // Export the public IP to access the Mailtrain application export const mailtrainIp = mailtrainChart.getResourceProperty('v1/Service', 'mailtrain', 'status').apply(status => status.loadBalancer.ingress[0].ip);
Explanation
-
The program starts by creating a resource group to host all the resources. An AKS cluster with a name
myAKSCluster
and default settings suitable for small applications is then provisioned. -
After setting up the AKS cluster, we retrieve the kubeconfig which is necessary to authenticate to the Kubernetes cluster.
-
The Kubernetes provider is instantiated with the retrieved kubeconfig, this allows Pulumi to connect to the AKS cluster.
-
mailtrainChart
uses thek8s.helm.v3.Chart
resource with thechart
andversion
specified. You need to replace'https://charts.example.com/'
with the actual Helm repository URL for Mailtrain. -
Finally, the program exports the IP address under which Mailtrain will be reachable. This is retrieved by accessing the
status
field of theService
object created by the Mailtrain Helm chart.
Running the Program
To run this program:
- Save the code to a file with the
.ts
extension, e.g.,index.ts
. - Run
pulumi up
in the directory where your file is saved. - Pulumi will prompt you with an update plan and ask for confirmation before provisioning the resources.
- Once the provisioning is complete, it will print the exported public IP address.
- Use this IP address in your browser to access the Mailtrain application.
Remember to replace the dummy values in
mailtrainChart
with the actual values corresponding to the Mailtrain Helm chart you want to deploy. If you wish to customize the AKS cluster settings, such as the region or node size, modify the settings in theManagedCluster
constructor accordingly.- Provision an AKS cluster using the