Deploy the k0s-homelab helm chart on Azure Kubernetes Service (AKS)
TypeScriptTo deploy the
k0s-homelab
Helm chart on Azure Kubernetes Service (AKS) using Pulumi, you need to follow these steps:- Set up an AKS cluster.
- Install and configure the Helm chart on the AKS cluster.
Before you begin, make sure you have the following prerequisites installed and set up:
- Pulumi CLI
- Azure CLI
- An Azure account
- Helm CLI (optional, as Pulumi can work directly with Helm charts)
Part 1: Set up an AKS cluster
To set up an AKS cluster, you use the
azure-native
provider from Pulumi, which gives you access to Azure resources as Pulumi objects. The following program will create an AKS cluster with default settings:- The
ResourceGroup
resource is used to create a resource group in Azure to contain our AKS cluster. - The
ManagedCluster
resource is the AKS cluster itself with a default node pool.
Part 2: Install the Helm chart
For deploying the Helm chart, the
kubernetes
provider for Pulumi comes into play. It allows you to interact with the Kubernetes API, enabling you to manage Kubernetes resources, including Helm charts. Here is how you can define and install a Helm chart with Pulumi:- The
Chart
resource from thekubernetes
package is used to deploy a Helm chart to the Kubernetes cluster.
Below is a TypeScript program demonstrating these steps.
import * as pulumi from '@pulumi/pulumi'; import * as azure_native from '@pulumi/azure-native'; import * as kubernetes from '@pulumi/kubernetes'; import * as random from '@pulumi/random'; // Step 1: Create a new resource group to hold the resources const resourceGroup = new azure_native.resources.ResourceGroup('rg', { resourceGroupName: `k8s-resource-group`, }); // Generate a strong password for the AKS cluster const password = new random.RandomPassword("password", { length: 20, special: true, }); // Step 2: Create an AKS cluster const aksCluster = new azure_native.containerservice.ManagedCluster('aksCluster', { resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 1, vmSize: 'Standard_DS2_v2', name: 'agentpool', mode: 'System', }], dnsPrefix: 'aksk8s', linuxProfile: { adminUsername: 'adminuser', ssh: { publicKeys: [{ keyData: 'ssh-rsa AAA... your_public_ssh_key ...user@example.com', // Replace with your SSH public key }], }, }, servicePrincipalProfile: { clientId: 'clientId', // Replace with your Azure AD application/client ID secret: password.result, }, kubernetesVersion: '1.18.14', enableRbac: true, }); // Get the kubeconfig from the created AKS cluster const creds = pulumi.all([aksCluster.name, resourceGroup.name]).apply(([clusterName, rgName]) => azure_native.containerservice.listManagedClusterUserCredentials({ resourceGroupName: rgName, resourceName: clusterName, }), ); const kubeconfig = creds.apply(creds => Buffer.from(creds.kubeconfigs[0].value, 'base64').toString()); // Step 3: Create a Kubernetes provider using the generated kubeconfig const k8sProvider = new kubernetes.Provider('k8sProvider', { kubeconfig: kubeconfig, }); // Step 4: Deploy the k0s-homelab Helm chart const k0sHomelabChart = new kubernetes.helm.v3.Chart('k0s-homelab-chart', { chart: 'k0s-homelab', version: '1.0.0', // Replace with the version of the chart you want to deploy fetchOpts: { repo: 'https://example.com/helm-charts', // Replace with the Helm chart's repository URL }, }, { provider: k8sProvider }); // Export the kubeconfig and AKS cluster name export const kubeconfigExport = pulumi.secret(kubeconfig); export const clusterName = aksCluster.name;
In the code block above, you'll need to replace the placeholders with your own values:
- Replace
'ssh-rsa AAA... your_public_ssh_key ...user@example.com'
with your SSH public key. - Replace
'clientId'
and'password'
with your Azure AD application/client ID and a generated secret. - Replace the chart
version
with the version of thek0s-homelab
chart you want to deploy. - Replace
'https://example.com/helm-charts'
with the actual repository URL where thek0s-homelab
Helm chart is located.
Once this program is executed with
pulumi up
, it will create the specified resources in Azure and deploy the Helm chart to the AKS cluster. Note thatpulumi.secret
is used to export the kubeconfig so it won't be displayed in plaintext in the Pulumi console or state.Remember to customize the values for the AKS cluster and the Helm chart as per your requirements, and make sure the given repository URL and chart version are correct before running the program.
Upon successful execution, you will have a running k0s-homelab on your AKS cluster, managed by Pulumi.