Deploy the stateful helm chart on Digital Ocean Kubernetes Service
TypeScriptTo deploy a stateful Helm chart on DigitalOcean's Kubernetes Service (DOKS), you'll first need to create a Kubernetes cluster in DigitalOcean, and then use the Helm package manager to deploy your chart to that cluster.
For the sake of this guide, let's assume the stateful application you want to deploy is a database or any other application that requires persistent storage. Helm doesn't directly manage stateful resources; instead, it uses
StatefulSets
in Kubernetes to manage the application state.I'll guide you through a Pulumi TypeScript program that sets up the following:
- A new Kubernetes cluster in DigitalOcean using the
digitalocean.KubernetesCluster
resource. - The deployment of a stateful Helm chart to the created cluster using the
kubernetes.helm.v3.Chart
resource.
Here's an outline of the Pulumi program:
- We start with importing necessary packages and setting up the DigitalOcean provider.
- Next, we instantiate a Kubernetes cluster in DigitalOcean.
- We configure Kubeconfig to point to our new DOKS cluster.
- Lastly, we use the Helm package to deploy a stateful Helm chart into our cluster.
Below is the detailed Pulumi TypeScript program to achieve this:
import * as pulumi from "@pulumi/pulumi"; import * as digitalocean from "@pulumi/digitalocean"; import * as kubernetes from "@pulumi/kubernetes"; // Create a DigitalOcean Kubernetes cluster const cluster = new digitalocean.KubernetesCluster("do-cluster", { region: "nyc3", // Choose the appropriate region for you version: "1.21.5-do.0", // Specify the desired Kubernetes version nodePool: { name: "default", size: "s-2vcpu-2gb", // Choose the appropriate size for your workload and budget nodeCount: 1, // Specify the number of nodes }, }); // Export the Kubeconfig for the cluster export const kubeconfig = cluster.kubeConfigs[0].rawConfig; // Create a Kubernetes provider instance using the cluster kubeconfig const k8sProvider = new kubernetes.Provider("k8s-provider", { kubeconfig: kubeconfig, }); // Deploy the stateful Helm chart using the kubernetes.helm.v3.Chart class const statefulHelmChart = new kubernetes.helm.v3.Chart("stateful-helm-chart", { chart: "my-stateful-chart", // Replace with your stateful chart's name version: "1.0.0", // Specify the chart version fetchOpts: { repo: "http://charts.mycompany.com/", // Replace with your chart repository }, }, { provider: k8sProvider }); // Export the Helm chart deployment status export const helmChartStatus = statefulHelmChart.status;
Here's an explanation of what each part of the program is doing:
-
digitalocean.KubernetesCluster
: This creates a Kubernetes cluster in the specified region with the given version and node configuration. ThenodePool
specifies the size and number of the nodes for the cluster.- Link to resource documentation: DigitalOcean KubernetesCluster
-
kubeconfig
: This outputs the raw Kubernetes config string that you can use withkubectl
or any Kubernetes client to interact with your cluster. -
kubernetes.Provider
: This sets up a Kubernetes provider to interact with the Kubernetes cluster we just created. It uses the kubeconfig from thedigitalocean.KubernetesCluster
to authenticate.- Link to resource documentation: Pulumi Kubernetes Provider
-
kubernetes.helm.v3.Chart
: This represents a Helm chart for deploying applications on Kubernetes. By usingfetchOpts
, you provide the location of the custom Helm chart repository and specify the chart and version to deploy. Theprovider
argument ensures that the Helm chart is deployed to the cluster we created with DigitalOcean.- Link to resource documentation: Helm Chart
-
helmChartStatus
: This output can be used to check the deployment status of your Helm chart.
To run this Pulumi program:
- Ensure you have Pulumi installed and the DigitalOcean Pulumi provider configured with your DigitalOcean token.
- Save the program code to a file with a
.ts
extension, such asindex.ts
. - Run
pulumi up
to create the infrastructure and deploy your application.
Please replace
"my-stateful-chart"
with the actual name of your stateful Helm chart and provide the correct repository URL. Also, adjust the Kubernetes cluster version and node pool settings to match your requirements.This program assumes that you have a Helm chart ready for deployment and if it has any configurable values, you can pass them using the
values
option in theChart
resource constructor.With this Pulumi program, you'll be able to deploy a stateful application on DigitalOcean Kubernetes Service using a Helm chart.
- A new Kubernetes cluster in DigitalOcean using the