Deploy the haproxytech-haproxy-ingress helm chart on Digital Ocean Kubernetes Service
TypeScriptDeploying a Helm chart like
haproxytech-haproxy-ingress
on the DigitalOcean Kubernetes Service (DOKS) involves several steps that can be orchestrated using Pulumi. The Pulumi program will need:-
A DigitalOcean Kubernetes cluster: This object represents a managed Kubernetes cluster on DigitalOcean, where our applications will run.
-
A Helm chart: Helm charts are packages of pre-configured Kubernetes resources. We will deploy the
haproxytech-haproxy-ingress
chart which sets up HAProxy as an ingress controller within our DOKS cluster.
The primary Pulumi resources used to define this deployment are:
digitalocean.KubernetesCluster
: This resource is used to create and manage a Kubernetes cluster on DigitalOcean.kubernetes.helm.v3.Chart
: This resource is used to deploy a Helm chart into a Kubernetes cluster.
Below is the Pulumi program in TypeScript that sets up a DigitalOcean Kubernetes cluster and deploys the
haproxytech-haproxy-ingress
Helm chart on it.import * as pulumi from "@pulumi/pulumi"; import * as digitalocean from "@pulumi/digitalocean"; import * as k8s from "@pulumi/kubernetes"; // Create a DigitalOcean Kubernetes cluster const cluster = new digitalocean.KubernetesCluster("do-cluster", { region: "nyc3", version: "1.21.5-do.0", // Please choose the desired Kubernetes version nodePool: { name: "default-pool", size: "s-2vcpu-2gb", // Select the droplet size as per your requirement nodeCount: 2, // Define the number of nodes in the node pool } }); // Create a provider for the created cluster const k8sProvider = new k8s.Provider("do-k8s-provider", { kubeconfig: cluster.kubeConfigs[0].rawConfig, }); // Deploy the haproxytech-haproxy-ingress Helm chart const haproxyIngressChart = new k8s.helm.v3.Chart("haproxy-ingress", { chart: "haproxy-ingress", version: "0.13.4", // Specify the chart version you want to deploy fetchOpts: { repo: "https://haproxy-ingress.github.io/charts", // The repository for the helm chart }, namespace: "ingress", // Define the namespace for the ingress controller if needed }, { provider: k8sProvider }); // Export the cluster endpoint to access the Kubernetes API export const kubeApiEndpoint = cluster.endpoint; // Export the Kubernetes cluster name export const kubeClusterName = cluster.name;
In this program:
- We declare a DigitalOcean Kubernetes cluster with two worker nodes.
- We specify the version of Kubernetes for the cluster. You should replace
1.21.5-do.0
with the version you want to use. - We configure the
nodePool
with a specified droplet size and the number of nodes. These values should be selected based on your specific workload requirements. - We declare a Pulumi Kubernetes provider associated with our new DOKS cluster by using its
kubeconfig
. - We deploy the
haproxytech-haproxy-ingress
Helm chart using thek8s.helm.v3.Chart
class and the chart's repository location. - We are creating the ingress resources within the
ingress
namespace.
You will notice two exported variables at the end of the script –
kubeApiEndpoint
andkubeClusterName
. These exports are handy for accessing your cluster outside of Pulumi, for example, usingkubectl
.To apply this Pulumi program:
- Ensure you have Pulumi installed, and you are logged in state backend used.
- Ensure you have your DigitalOcean API token configured either in the Pulumi configuration or set as an environment variable.
- Save this code to a file named
index.ts
in a directory. - Run
pulumi up
to create the cluster and deploy the ingress controller.
Would you like to go ahead with this, or would you like more guidance on any of these steps?
-