Deploy the mysql-imagestreams helm chart on Digital Ocean Kubernetes Service
TypeScriptTo deploy a Helm chart on the Digital Ocean Kubernetes Service (DOKS), you'll start by setting up a Kubernetes cluster on Digital Ocean. Then you'll use the Helm package from the Kubernetes provider in Pulumi to deploy the
mysql-imagestreams
chart.Let's break down the steps:
-
Create a Kubernetes Cluster on Digital Ocean: You'll create a Kubernetes cluster by using the
digitalocean.KubernetesCluster
resource. You need to specify the region, version of Kubernetes, the size of the node droplets (virtual machines), and the number of nodes in the node pool. -
Deploy Helm Chart: After the cluster is created, you'll use the
kubernetes.helm.v3.Chart
resource to deploy the Helm chart. You will provide the chart name and specify the repository if it is not a standard chart in the Helm stable repository.
Here's a Pulumi program written in TypeScript that accomplishes these steps:
import * as digitalocean from "@pulumi/digitalocean"; import * as k8s from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; // Step 1: Create a Kubernetes cluster on Digital Ocean const cluster = new digitalocean.KubernetesCluster("my-do-k8s-cluster", { region: "nyc1", // This should be a region that is geographically close to you or your customers version: "1.21.5-do.0", // The version of Kubernetes you want to use nodePool: { size: "s-1vcpu-2gb", // The size of your droplet (virtual machine) nodeCount: 2, // The number of nodes in your Kubernetes cluster }, }); // Wait for the cluster to be created to get the kubeconfig const kubeConfig = pulumi.all([cluster.name, cluster.kubeConfigs]).apply(([_, kubeConfigs]) => { return kubeConfigs[0].rawConfig; }); // Step 2: Deploy the mysql imagestreams Helm chart on the cluster const mySqlImageChart = new k8s.helm.v3.Chart("mysql-imagestreams", { chart: "mysql", // Specify the repository if the chart is not from the default Helm repo fetchOpts: { repo: "https://charts.helm.sh/stable", }, }, { provider: new k8s.Provider("do-k8s", { kubeconfig: kubeConfig }) }); // Export the cluster's kubeconfig and the MySQL service endpoint export const kubeConfigOut = kubeConfig; export const mysqlServiceEndpoint = mySqlImageChart.getResourceProperty("v1/Service", "mysql-imagestreams-mysql", "status").apply(status => status.loadBalancer.ingress[0].ip);
Explanation
-
The
digitalocean.KubernetesCluster
constructs a new Kubernetes cluster in the specified region and with the given settings (docs). -
The
kubernetes.helm.v3.Chart
resource is used to deploy a Helm chart. Here, we specify themysql
chart as an example; you need to replace this withmysql-imagestreams
or your specific chart's name. Assuming themysql-imagestreams
chart exists in the provided repository, you would update therepo
field accordingly. If it's in a different repository, you would use that URL (docs). -
We use the
k8s.Provider
to ensure Pulumi knows how to communicate with your Digital Ocean Kubernetes cluster by using the generated kubeConfig.
Next Steps
After applying this program with Pulumi CLI, your MySQL Helm chart should be deployed to your Digital Ocean Kubernetes cluster. You can use the
kubectl get services
command with yourkubeConfig
to see the IP address of your MySQL service, or you can use the exportedmysqlServiceEndpoint
which Pulumi will display after the deployment is done.-