Deploy the ocs-operator helm chart on Digital Ocean Kubernetes Service
TypeScriptTo deploy the
ocs-operator
Helm chart on Digital Ocean Kubernetes Service (DOKS), you will first need to create a Kubernetes cluster in Digital Ocean. Once you have the cluster, you can use the Pulumi Kubernetes provider to deploy the Helm chart to that cluster.Here's a step-by-step breakdown of the tasks needed, followed by a Pulumi TypeScript program that carries out the deployment.
-
Create a DOKS cluster: Using the
digitalocean.KubernetesCluster
resource, we can define a new Kubernetes cluster. You'll need to provide essential properties like the region, version, and node pool configuration. -
Install the Pulumi Kubernetes provider: The Kubernetes provider is used to interact with the newly created DOKS cluster and deploy resources on it.
-
Deploy the
ocs-operator
Helm chart: To deploy a Helm chart, we make use of Pulumi'shelm.v3.Chart
resource. You'll specify the chart name, version, and any values you want to override in the chart's default configuration.
Now, let's write the Pulumi program in TypeScript which encapsulates all of these steps:
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("doks-cluster", { // Assign a name to our cluster name: "doks-cluster", // Specify the region for the cluster region: digitalocean.Regions.NYC1, // Specify the Kubernetes version. Use the DigitalOcean dashboard to choose a valid version // This version string is an example; you'll need to check DigitalOcean to get a current version. version: "1.21.6-do.0", // Define the node pool nodePool: { name: "default-pool", size: digitalocean.DropletSlugs.DropletS2VCPU2GB, // This specifies the size of each node nodeCount: 2, // How many nodes you want in the node pool }, }); // Instantiate a Kubernetes provider that uses the kubeconfig from our newly created DOKS cluster const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: cluster.kubeConfigs[0].rawConfig, }); // Deploy the 'ocs-operator' Helm chart const ocsOperatorChart = new k8s.helm.v3.Chart("ocs-operator", { // Define the chart and version chart: "ocs-operator", version: "0.1.0", // Replace with the desired chart version // Add the chart repository here, if it's not one of the stable/default repos fetchOpts: { repo: "https://your-helm-chart-repo.com/", // Replace with the correct Helm chart repository URL }, // Define a values file or an inline values object to override chart defaults values: { // Specify any custom values for the Helm chart here }, }, { provider: k8sProvider }); // Export the cluster's kubeconfig export const kubeconfig = cluster.kubeConfigs[0].rawConfig; // Export the public IP to access the cluster export const clusterEndpoint = cluster.endpoint;
Explanation:
-
We use
@pulumi/digitalocean
to create a new Kubernetes cluster on Digital Ocean. Thename
,region
,version
, andnodePool
properties dictate the cluster's characteristics. -
Then, we use
@pulumi/kubernetes
to create a new provider instance that will allow us to interact with the Kubernetes cluster using the kubeconfig provided by the cluster we just created. -
We deploy the
ocs-operator
Helm chart usingk8s.helm.v3.Chart
. In theChart
resource, we need to specify the chart name, version, and potentially the custom Helm chart repository URL if it's not in one of the pre-configured Helm repositories known to Pulumi. -
Lastly, we export the kubeconfig and the public endpoint for the cluster. The kubeconfig is necessary for using
kubectl
and other Kubernetes tooling with your new cluster, and the public endpoint can be used to access Kubernetes services deployed in the cluster.
Be sure to replace the placeholders, such as chart version (
0.1.0
), and Helm repo URL (https://your-helm-chart-repo.com/
), with actual values that are applicable to theocs-operator
chart you want to deploy.To run this Pulumi program:
- Ensure you have the Pulumi CLI installed and the Digital Ocean token configured as per Pulumi's setup documentation.
- Create a new directory, initialize a Pulumi project and select the Digital Ocean cloud.
- Save this code in a TypeScript file, for example
index.ts
. - Run
pulumi up
, review the proposed changes, and confirm them by selecting 'yes' if everything looks good.
This will deploy the required resources and print out the cluster's kubeconfig and endpoint as stack outputs.
-