Deploy the cluster-redis helm chart on Azure Kubernetes Service (AKS)
TypeScriptTo deploy the
cluster-redis
Helm chart on an Azure Kubernetes Service (AKS) cluster using Pulumi, we will follow these steps:- Set up an AKS Cluster: First, we create an AKS cluster where our Helm chart will be deployed.
- Install the Helm chart: Once we have the Kubernetes cluster, we will use Pulumi's
Chart
resource which allows us to deploy Helm charts.
Here's a detailed walkthrough of the code you will use to accomplish this, written in TypeScript using Pulumi.
Program Explanation
Create an AKS Cluster
We start by importing the necessary Pulumi libraries for Azure and Kubernetes. Then, we define an AKS cluster. This part involves setting up configurations like the location, node count, and VM size for the nodes in the AKS cluster.
Deploy Helm Chart on AKS
Once the cluster is ready, we install the
cluster-redis
Helm chart. We use theChart
resource from the@pulumi/kubernetes
package that Pulumi provides to declare Helm charts in a Pulumi program.Accessing the Kubernetes Configuration
To interact with the AKS cluster, we need the kubeconfig, which is an output from the AKS cluster creation. We pass this configuration to the Helm chart so that it knows where to install the Redis instance.
Pulumi Program
Now, let's write the complete Pulumi program to deploy
cluster-redis
on AKS.import * as pulumi from "@pulumi/pulumi"; import * as azure from "@pulumi/azure"; import * as k8s from "@pulumi/kubernetes"; // Create an AKS cluster. const aksCluster = new azure.containerservice.KubernetesCluster("my-aks-cluster", { resourceGroupName: azureResourceGroupName, location: location, defaultNodePool: { name: "aksagentpool", nodeCount: 2, vmSize: "Standard_DS2_v2", }, dnsPrefix: `${pulumi.getStack()}-kube`, identity: { type: "SystemAssigned", }, }); // Export the kubeconfig. const kubeconfig = aksCluster.kubeConfigRaw; // Create a Kubernetes provider instance that uses our kubeconfig. const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: kubeconfig, }); // Deploy the `cluster-redis` Helm chart. const redisChart = new k8s.helm.v3.Chart("cluster-redis", { chart: "redis", version: "10.5.7", fetchOpts: { repo: "https://charts.bitnami.com/bitnami", }, // Values from the `values.yaml` file can be provided here. values: { cluster: { enabled: true, }, // Include any additional configuration here }, }, { provider: k8sProvider }); // Export the frontend IP of the `cluster-redis` service. export const redisFrontendIp = redisChart.getResourceProperty("v1/Service", "cluster-redis-master", "status") .apply(status => status.loadBalancer.ingress[0].ip);
In the
redisChart
declaration, you must replace thechart
andversion
properties with the appropriate values for thecluster-redis
chart you wish to deploy. Also, make sure to adjust thevalues
property to match the configuration that you wish for your Redis cluster deployment.Running the Program
Install Pulumi CLI and authenticate. Make sure you have an Azure account and the Azure CLI installed and configured.
- Create a new Pulumi project and set the appropriate stack, for example,
dev
.
pulumi new azure-typescript
-
Replace the contents of
index.ts
with the code provided above. -
Run
npm install
to install the dependencies.
npm install @pulumi/pulumi @pulumi/azure @pulumi/kubernetes
- Run
pulumi up
to create the resources on Azure.
pulumi up
Upon successful completion, your AKS cluster will be running, and the
cluster-redis
Helm chart will be deployed within it.Please note that the specific version and Helm repository I used in the code are illustrative, and you might need to choose the particular version and source repository of
cluster-redis
that best suits your needs.