Deploy the cluster-gitlab-runner helm chart on Azure Kubernetes Service (AKS)
TypeScriptTo deploy the
cluster-gitlab-runner
Helm chart on Azure Kubernetes Service (AKS), we will first provision an AKS cluster using Pulumi. After that, we will use theChart
resource from the Pulumi Kubernetes provider to deploy the Helm chart to our newly created AKS cluster. Below is a step-by-step guide and the corresponding Pulumi TypeScript program to achieve this.Step 1: Prerequisites
Ensure you have the following installed:
- Pulumi CLI
- Azure CLI
- Node.js and npm
Also, authenticate with Azure using the Azure CLI by running
az login
.Step 2: Create a new Pulumi project
Create a new directory for your project and initialize a new Pulumi project with TypeScript as the language of choice.
mkdir aks-gitlab-runner cd aks-gitlab-runner pulumi new azure-typescript
Step 3: Define AKS Cluster
In the Pulumi program, we will define an AKS cluster resource. We use
azure-native
because it provides a native Azure experience.import * as pulumi from "@pulumi/pulumi"; import * as azure from "@pulumi/azure-native";
Step 4: Provision AKS Cluster
We will provision the AKS cluster with the required properties such as node count, VM size, and Kubernetes version.
Step 5: Deploy the Helm chart
We'll then deploy the
cluster-gitlab-runner
Helm chart to the AKS cluster using the Pulumi Kubernetes provider. We'll have to add the Helm repository that contains thecluster-gitlab-runner
chart, specify the chart version, and provide any custom values that are particular to our deployment.Step 6: Stack Exports
We'll output the AKS cluster name and Kubernetes config so that you can interact with your cluster using
kubectl
after the deployment.Now, let's write the Pulumi TypeScript program:
import * as pulumi from "@pulumi/pulumi"; import * as azure from "@pulumi/azure-native"; import * as k8s from "@pulumi/kubernetes"; // Create a resource group for the AKS cluster. const resourceGroup = new azure.resources.ResourceGroup("aksResourceGroup"); // Create the AKS cluster. const aksCluster = new azure.containerservice.ManagedCluster("aksCluster", { resourceGroupName: resourceGroup.name, agentPoolProfiles: [{ count: 2, maxPods: 110, mode: "System", name: "agentpool", osType: "Linux", vmSize: "Standard_DS2_v2", }], dnsPrefix: "aks-gitlab", enableRBAC: true, kubernetesVersion: "1.20.9", }); // Export the kubeconfig. export const kubeconfig = pulumi. all([aksCluster.name, resourceGroup.name]). apply(([clusterName, rgName]) => { return azure.containerservice.listManagedClusterUserCredentials({ resourceName: clusterName, resourceGroupName: rgName, }); }).apply(creds => Buffer.from(creds.kubeconfigs[0].value, "base64").toString()); // Create a Kubernetes provider instance that uses our kubeconfig. const k8sProvider = new k8s.Provider("k8sProvider", { kubeconfig: kubeconfig, }); // Create the GitLab Runner Helm chart. const gitlabRunnerChart = new k8s.helm.v3.Chart("gitlabRunner", { chart: "cluster-gitlab-runner", version: "0.1.0", // Replace with the actual chart version namespace: "gitlab-runner", fetchOpts:{ repo: "https://charts.gitlab.io/" // The Helm repository URL }, values: { // Specify the values for the GitLab Runner chart here }, }, { provider: k8sProvider }); // Export the AKS cluster name and the Helm chart status. export const clusterName = aksCluster.name; export const gitlabRunnerStatus = gitlabRunnerChart.status;
This program sets up an AKS cluster and then deploys the
cluster-gitlab-runner
Helm chart to it. Here's a breakdown of what each part of the code is doing:- We import the Pulumi packages necessary for defining Azure and Kubernetes resources.
- We create an Azure resource group to house our AKS cluster.
- We provision an AKS cluster with a defined DNS prefix, RBAC enabled, and a specific Kubernetes version.
- We export the kubeconfig needed to interact with the AKS cluster using
kubectl
. - We set up a Pulumi Kubernetes provider that uses our kubeconfig.
- We create a Helm chart resource and point it to the Helm repository URL that contains the
cluster-gitlab-runner
chart. We also specify the namespace and the chart version. - We export the cluster's name and the Helm chart status so you can access them outside of Pulumi—for instance, when you need to use
kubectl
.
To run this Pulumi program, save it as
index.ts
, and then runpulumi up
from the command line. Pulumi will provision the AKS cluster and deploy the Helm chart, all while providing you with detailed status updates and any configuration outputs.Before running this program, please make sure to replace the
chart
andversion
ingitlabRunnerChart
with the actual chart name and version you want to deploy. Additionally, populate thevalues
property with your configuration needs, which will be set as Helm values on the deployment.