Deploy the auditbeat helm chart on Azure Kubernetes Service (AKS)
TypeScriptDeploying the Auditbeat Helm chart on an Azure Kubernetes Service (AKS) cluster involves several steps: provisioning an AKS cluster, if not already available, and then deploying the Helm chart to that cluster.
Firstly, we will need to set up the AKS cluster using Pulumi with the Azure Native provider. Once the cluster is up and running, we can configure
kubectl
to connect to our AKS cluster. Then, we will use the Kubernetes provider to deploy the Auditbeat Helm Chart.Below is a TypeScript program using Pulumi to deploy an AKS cluster and then the Auditbeat Helm chart.
import * as pulumi from "@pulumi/pulumi"; import * as azure_native from "@pulumi/azure-native"; import * as k8s from "@pulumi/kubernetes"; import * as random from "@pulumi/random"; // Create an Azure Resource Group const resourceGroup = new azure_native.resources.ResourceGroup("my-resource-group"); // Create an AKS cluster const managedCluster = new azure_native.containerservice.ManagedCluster("my-aks-cluster", { resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 1, vmSize: "Standard_DS2_v2", name: "agentpool", mode: "System", }], dnsPrefix: "my-aks-cluster", linuxProfile: { adminUsername: "adminuser", ssh: { publicKeys: [{ keyData: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3b3IyEb..." }] } }, servicePrincipalProfile: { clientId: "client-id", secret: "client-secret", }, }, { dependsOn: resourceGroup }); // Export the kubeconfig to connect to the AKS cluster export const kubeconfig = pulumi.all([managedCluster.name, resourceGroup.name]).apply(([clusterName, rgName]) => azure_native.containerservice.listManagedClusterUserCredentials({ resourceGroupName: rgName, resourceName: clusterName, })).apply(credentials => { const encoded = credentials.kubeconfigs[0].value; return Buffer.from(encoded, "base64").toString(); }); // Create a Kubernetes provider instance that uses our kubeconfig const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: kubeconfig, }); // Generate a random string for the Helm chart release name to avoid conflicts const releaseName = new random.RandomString("helm-release-name", { upper: false, length: 10, }).result; // Deploy the Auditbeat Helm chart const auditbeatChart = new k8s.helm.v3.Chart("auditbeat-helm-chart", { chart: "auditbeat", version: "7.14.0", // Specify the version of Auditbeat you wish to deploy fetchOpts: { repo: "https://helm.elastic.co", }, namespace: "kube-system", // Deploying to the kube-system namespace }, { provider: k8sProvider }); // Export the release name of the chart export const auditbeatReleaseName = releaseName;
This program does the following:
- It declares an Azure resource group to contain our infrastructure.
- It then defines a managed Kubernetes cluster (AKS) with a single agent pool.
- A
kubeconfig
is exported for connecting to our AKS cluster usingkubectl
or any Kubernetes client. This is essential to deploy applications onto the cluster. - A
k8s.Provider
instance is created using thekubeconfig
. This allows Pulumi to communicate with the AKS cluster and manage our Kubernetes resources. - A random string is generated to use as a unique name for the Helm chart deployment. This approach prevents conflicts with other releases in the same namespace.
- Finally, it deploys the Auditbeat Helm chart to the
kube-system
namespace of the AKS cluster using Pulumi's Helm Chart resource. It specifies which version of Auditbeat to deploy and where to fetch the chart from.
Make sure to replace
"client-id"
and"client-secret"
with your actual Azure service principal credentials and the SSH public key data with your own. The code is structured to declare resources and export outputs, which we will use to connect and interact with our cluster.To run this program:
- Install Pulumi CLI and set up Azure credentials.
- Create a new Pulumi project and set the runtime to
TypeScript
. - Create a
index.ts
file with the above code. - Run
pulumi up
to preview and deploy the resources. This will provision the AKS cluster and deploy the Helm chart.
Please remember to check the Helm Chart version and repository URL to ensure that you are deploying the version of Auditbeat that you require.