Deploy the rotate-elasticsearch-index helm chart on Azure Kubernetes Service (AKS)
TypeScriptTo deploy the "rotate-elasticsearch-index" Helm chart on Azure Kubernetes Service (AKS), you'll need to perform several steps:
- Create an AKS cluster if you don't have one already.
- Install and configure
kubectl
to communicate with the AKS cluster. - Add the Helm repository that contains the "rotate-elasticsearch-index" chart.
- Install the Helm chart onto your AKS cluster.
In this program, we will focus on the Pulumi part of this process, which is to programmatically create an AKS cluster and then deploy the Helm chart to this cluster. We will be using the
azure-native
package for creating an AKS cluster and thekubernetes
package to deploy the Helm chart.Creating an AKS Cluster
To create an AKS cluster, we will use the
azure-native
resources. Theazure-native
package uses the Azure Resource Manager APIs directly. Thus it gives us fine-grained control over the Azure resources, maintaining familiarity with Azure concepts and terminology.Here is a Pulumi program in TypeScript that sets up an AKS cluster:
import * as pulumi from "@pulumi/pulumi"; import * as azure from "@pulumi/azure-native"; import * as k8s from "@pulumi/kubernetes"; // Create an Azure Resource Group const resourceGroup = new azure.resources.ResourceGroup("myResourceGroup"); // Create an AD service principal for the AKS cluster. const adApp = new azure.ad.Application("aks"); const adSp = new azure.ad.ServicePrincipal("aksSp", { applicationId: adApp.applicationId, }); // Create the AD service principal password. const adSpPassword = new azure.ad.ServicePrincipalPassword("aksSpPassword", { servicePrincipalId: adSp.id, value: "YOUR_PASSWORD", // Replace with a real password. endDate: "2099-01-01T00:00:00Z", }); // Create an AKS cluster. const cluster = new azure.containerservice.ManagedCluster("myAksCluster", { resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 2, maxPods: 110, mode: "System", name: "agentpool", osDiskSizeGB: 30, osType: "Linux", vmSize: "Standard_DS2_v2", }], dnsPrefix: "myakscluster", linuxProfile: { adminUsername: "adminuser", ssh: { publicKeys: [{ keyData: "ssh-rsa ...", // Replace with your SSH key. }], }, }, servicePrincipalProfile: { clientId: adApp.applicationId, secret: adSpPassword.value, }, }); // Export the kubeconfig export const kubeConfig = cluster.kubeConfig;
The program above sets up an AKS cluster with a standard set of configurations:
- A new resource group is created to host the AKS cluster.
- An Azure Active Directory application and service principal are created, which AKS uses to interact with other Azure services securely.
- The AD service principal password and SSH key are set for the cluster. Make sure to replace the placeholder values with actual secure passwords and your SSH key.
- A new AKS cluster is declared with a single system node pool, which consists of virtual machines that will run the Kubernetes nodes.
Deploying a Helm Chart to AKS
Once you have the AKS cluster up and running, the next step is to deploy the "rotate-elasticsearch-index" Helm chart. You can create a
Chart
resource from thekubernetes
package to accomplish this. TheChart
resource will use Helm to install the chart. Here is how you do it:// Ensure you have added the correct Helm Chart repository and updated your local Helm chart repository list. // Create a Kubernetes provider instance that uses the kubeConfig from the AKS cluster created above const k8sProvider = new k8s.Provider("k8sProvider", { kubeconfig: kubeConfig.rawConfig.apply(c => c), // This converts the output to a string that the k8s provider can understand }); // Deploy the rotate-elasticsearch-index Helm chart to the AKS cluster const elasticsearchIndexRotator = new k8s.helm.v3.Chart("elasticsearch-index-rotator", { chart: "rotate-elasticsearch-index", // This is the chart name available in your Helm repository version: "1.0.0", // Use the appropriate chart version namespace: "default", // Define which namespace the chart should be deployed into; make sure this namespace exists in your cluster // values here should be the actual values required by the Helm chart }, { provider: k8sProvider }); // Export the Chart name of the deployed elasticsearch index rotator export const chartName = elasticsearchIndexRotator.chart;
In the code:
- We establish a
k8s.Provider
resource that allows Pulumi to communicate with the Kubernetes cluster. It uses thekubeConfig
obtained from the AKS cluster creation process to establish this connection. - Then we instantiate a
Chart
which represents the Helm chart. You need to ensure that Helm is properly installed and configured to access the Helm repository that hosts the "rotate-elasticsearch-index" chart. If the Helm chart requires it, provide the necessary configuration values under thevalues
key in theChart
resource.
Remember to replace the placeholders with the actual chart repository and version, and you might also need to provide your Helm chart's specific configurations (
values
) tailored to your use case.Execute the Pulumi program by running
pulumi up
. This will create the resources on Azure and apply the Helm chart to your AKS cluster. Make sure Pulumi is installed and configured with the appropriate access to your Azure subscription.