Deploy the akash-hostname-operator helm chart on Azure Kubernetes Service (AKS)
TypeScriptTo deploy the
akash-hostname-operator
Helm chart on Azure Kubernetes Service (AKS), you'll need to perform the following steps with Pulumi:- Set up an AKS cluster: This involves creating a resource group and defining the AKS cluster itself.
- Install the Helm chart: Once the AKS cluster is running, you'll install the
akash-hostname-operator
Helm chart.
Below is a TypeScript program using Pulumi to carry out these tasks. We'll use the
@pulumi/azure-native
package because it provides native Azure resource management including AKS (azure-native.containerservice.KubernetesCluster
).Detailed Steps:
- Resource Group: Create a new resource group within Azure to organize the resources we'll use.
- AKS Cluster: Provision an AKS cluster within the resource group. Setting up AKS involves choosing the appropriate size for the nodes (VMs) in the default node pool, and configuring other cluster parameters like the version of Kubernetes.
- Kubeconfig: Once the AKS cluster is provisioned, we get the kubeconfig file that will allow us to communicate with the cluster using
kubectl
. - Helm Chart: Using Pulumi's Helm support, provided by the
@pulumi/kubernetes
package, we deploy theakash-hostname-operator
helm chart into our AKS cluster.
To run this Pulumi program, ensure you have:
- Installed Pulumi CLI and logged in
- Configured Azure credentials for Pulumi to use
- Installed Node.js and initialized a new Pulumi project
Now, let's go through the program.
import * as pulumi from "@pulumi/pulumi"; import * as azure_native from "@pulumi/azure-native"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create a new resource group. const resourceGroup = new azure_native.resources.ResourceGroup("myResourceGroup"); // Step 2: Create the AKS cluster. const aksCluster = new azure_native.containerservice.ManagedCluster("myAksCluster", { resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 2, // Number of nodes in the node pool maxPods: 110, mode: "System", name: "agentpool", osType: "Linux", vmSize: "Standard_DS2_v2", // Size of the virtual machines used as nodes }], dnsPrefix: "myakscluster", enableRBAC: true, // Enable Role-Based Access Control (RBAC) kubernetesVersion: "1.18.14", // Kubernetes version linuxProfile: { adminUsername: "adminuser", ssh: { publicKeys: [{ keyData: "ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZ...", // Public key for SSH }], }, }, nodeResourceGroup: `MC_${pulumi.interpolate(resourceGroup.name)}_myAksCluster_${resourceGroup.location}`, }, {dependsOn: resourceGroup}); // Step 3: Extract the kubeconfig. const creds = pulumi.all([resourceGroup.name, aksCluster.name]).apply(([rgName, clusterName]) => azure_native.containerservice.listManagedClusterUserCredentials({ resourceGroupName: rgName, resourceName: clusterName, }), ); const kubeconfig = creds.kubeconfigs[0].value.apply(kc => Buffer.from(kc, 'base64').toString()); // Setup a Kubernetes provider instance using the kubeconfig from the AKS cluster. const k8sProvider = new k8s.Provider("k8sProvider", { kubeconfig: kubeconfig, }); // Step 4: Deploy the akash-hostname-operator Helm chart. const chart = new k8s.helm.v3.Chart("akash-hostname-operator-chart", { chart: "akash-hostname-operator", // Specifying the repository and version is often necessary when deploying a Helm chart. repositoryOpts: { repo: "http://<repository-url>", // Replace with the Helm chart's repository URL. }, version: "0.1.0", // Replace with the Helm chart version you want to deploy. }, { provider: k8sProvider }); // Export the kubeconfig to standard out to make cluster interaction convenient. export const kubeConfigOutput = kubeconfig;
Explanation:
-
Resource Group: We're creating a resource group named
myResourceGroup
where all our resources will reside. -
AKS Cluster: Provisioning
myAksCluster
with desired settings, note thedependsOn
parameter makes sure the resource group is created first.The
adminUsername
andssh.publicKeys.keyData
need to be set so you can access the node VMs via SSH if needed (replace the placeholder SSH key with your public key). -
Kubeconfig: Extracting the AKS cluster's kubeconfig to interact with the cluster through
kubectl
. We're using Pulumi'sapply
to decode it from base64.Note that you should handle your kubeconfig securely and avoid exposing it unnecessarily.
-
Helm Chart:
akash-hostname-operator-chart
is deployed using the@pulumi/kubernetes
package. You should replace<repository-url>
and theversion
with valid values corresponding to the Helm chart you intend to deploy.
Throughout the codes mentioned above, resource names, and especially the content of the SSH public key, are placeholders and should be replaced with actual values before running the program.
After this program is executed successfully with
pulumi up
, theakash-hostname-operator
Helm chart will be deployed on the AKS cluster. This will create the necessary Kubernetes resources as defined by the Helm chart. ThekubeConfigOutput
can be used to interact with the cluster usingkubectl
from your local machine.