Deploy the prometheus-monitoring-stack helm chart on Azure Kubernetes Service (AKS)
TypeScriptTo deploy the Prometheus Monitoring Stack Helm chart on Azure Kubernetes Service (AKS), you will be performing the following steps:
- Set up an AKS cluster using the
azure-native
Pulumi provider, which uses the native Azure Resource Manager (ARM) API, providing direct access to Azure's services. - Deploy the Helm chart to the AKS cluster using Pulumi's
helm.v3.Chart
resource from the@pulumi/kubernetes
SDK, which abstracts Helm operations.
Below is the complete program written in TypeScript that will create an AKS cluster and deploy the Prometheus Monitoring Stack. Note that you will need the Helm chart's repository URL and chart name, which we will assume are
https://prometheus-community.github.io/helm-charts
andkube-prometheus-stack
, respectively.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("resourceGroup"); // Create an AKS cluster const aksCluster = new azureNative.containerservice.ManagedCluster("aksCluster", { // Provide the required configurations for the AKS cluster resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 2, maxPods: 110, mode: "System", name: "agentpool", osDiskSizeGB: 30, osType: "Linux", vmSize: "Standard_DS2_v2", }], dnsPrefix: "akscluster", enableRBAC: true, // Enable Kubernetes Role-Based Access Control kubernetesVersion: "1.21.2", // Use your preferred Kubernetes version linuxProfile: { adminUsername: "aksuser", ssh: { publicKeys: [{ keyData: "ssh-rsa ...", // Replace with your SSH public key }], }, }, // Additional configurations can be set depending on your needs }); // Output the generated Kubernetes cluster's kubeconfig export const kubeconfig = aksCluster.kubeConfigRaw; // Use the obtained kubeconfig from the cluster to interact with the Kubernetes API const k8sProvider = new k8s.Provider("k8sProvider", { kubeconfig: kubeconfig, }); // Deploy the Prometheus Monitoring Stack Helm chart const prometheusStack = new k8s.helm.v3.Chart("kube-prometheus-stack", { chart: "kube-prometheus-stack", version: "14.5.0", // Specify the chart version you want to deploy namespace: "monitoring", // Namespace where the Helm chart resources will be deployed fetchOpts: { repo: "https://prometheus-community.github.io/helm-charts", // The Helm repository URL }, // Override default values by specifying your custom configuration values: { // For example, you could change the number of replicas for the Prometheus StatefulSet prometheus: { prometheusSpec: { replicas: 2, }, }, // Add additional customizations based on the monitoring needs }, }, { providers: { kubernetes: k8sProvider } }); // Export the Prometheus access URL export const prometheusUrl = pulumi.interpolate`http://prometheus.${aksCluster.name}.${resourceGroup.location}.cloudapp.azure.com/`;
This program performs the following actions:
- Resource Group Creation: A new Azure Resource Group is created as a container for your AKS cluster.
- AKS Cluster Creation: The AKS cluster is defined with system settings such as the node pool, VM size, OS type, SSH key for Linux profile, and Kubernetes version. Adjust these settings as needed for your use case.
- Kubeconfig Output: This is the configuration needed by
kubectl
and other Kubernetes tools to connect to your AKS cluster. We output this from the program so it can be used to configure the subsequent Kubernetes provider. - Kubernetes Provider Setup: A Pulumi Kubernetes provider is instantiated with the kubeconfig obtained from the AKS cluster, which allows Pulumi to deploy Kubernetes resources.
- Prometheus Helm Chart Deployment: The
helm.v3.Chart
resource represents the Prometheus Monitoring Stack Helm chart, specifying the chart version, namespace, repository, and any additional custom values you want to define. - Prometheus URL Export: A sample output is provided to access the Prometheus instance after it is deployed; you may need to configure DNS and ingress settings appropriately for actual access.
Please make sure you have Pulumi installed and configured with the appropriate cloud credentials. After setting up, you should run
pulumi up
to execute this program and deploy the resources.Remember to replace placeholders like
ssh-rsa ...
with your actual SSH public key. You might also need to adjust other configuration details like the Kubernetes version and Helm chart version according to your preferences and the availability in Azure and Helm repositories at the time of deployment.- Set up an AKS cluster using the