Deploy the mariadb-persistent helm chart on Digital Ocean Kubernetes Service
TypeScriptTo deploy the
mariadb-persistent
Helm chart on DigitalOcean Kubernetes Service using Pulumi, we first need to create a Kubernetes cluster within DigitalOcean. After that, we can install the Helm chart to the cluster.Here's a detailed breakdown of the steps we'll follow:
-
Create a Kubernetes Cluster: Using the
digitalocean.KubernetesCluster
resource, we'll instantiate a new Kubernetes cluster on DigitalOcean. This cluster will have nodes where our applications (in this case,mariadb-persistent
) can run. -
Install Helm Chart: Once we have a Kubernetes cluster, we'll use the
kubernetes.helm.v3.Chart
resource to deploy themariadb-persistent
Helm chart. Helm allows us to define, install, and upgrade Kubernetes applications, and ourmariadb-persistent
chart will likely contain all the Kubernetes resources needed to run the MariaDB database with configured persistent storage.
Now, let's turn this into code.
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: "nyc1", version: "1.21.5-do.0", nodePool: { name: "default", size: "s-2vcpu-2gb", nodeCount: 3, }, }); // Get the kubeconfig from the created cluster const kubeconfig = cluster.kubeConfigs[0].rawConfig; // Use the kubeconfig to create a Provider resource const k8sProvider = new kubernetes.Provider("k8s-provider", { kubeconfig: kubeconfig, }); // Deploy the mariadb-persistent helm chart using the Helm Chart resource const mariadbChart = new kubernetes.helm.v3.Chart("mariadb-persistent", { chart: "mariadb", version: "7.3.14", // Specify the chart version you want to deploy namespace: "database", fetchOpts: { repo: "https://charts.bitnami.com/bitnami", // The repository where the mariadb chart is located }, values: { // Values to override default chart values, // For example: the following lines would enable persistence and set the size of the volume. // These values are examples and may not directly apply to your needs. persistence: { enabled: true, size: "10Gi", }, }, }, { provider: k8sProvider }); // Export the cluster's kubeconfig and the service IP of the MariaDB export const kubeConfigOut = kubeconfig; export const mariadbServiceIp = mariadbChart.getResourceProperty("v1/Service", "mariadb-persistent", "status") .apply(status => status.loadBalancer.ingress[0].ip);
In the above code:
- We import the required Pulumi packages.
- We create a DigitalOcean Kubernetes cluster in the
nyc1
region with three nodes of sizes-2vcpu-2gb
each. - We then extract the kubeconfig of the created cluster using the
kubeConfigs
array, which holds the configuration needed to connect to our cluster fromkubectl
, and pass it to the Kubernetes provider. - We then use this provider to deploy the
mariadb-persistent
chart from Bitnami's Helm chart repository, specifying a version and values that we desire. Here, you may need to tweak thevalues
object to match the specific configuration items you need for your deployment. - Finally, we export the kubeconfig to be able to interact with the cluster outside of Pulumi and the IP address of the MariaDB service.
Note that the specifics of
values
should be optimized based on your usage demands, and the commented portion is an example of how you might set a volume size for persistent storage. For a production setup, you might want to consider setting more parameters like CPU and memory limits, database credentials, replication, and so on.You can also add stack exports for the Kubernetes service endpoint or any other outputs that you might need to interact with the deployed Helm chart.
To run this program with Pulumi:
- Ensure you have Pulumi CLI installed and the DigitalOcean provider is configured with an appropriate access token.
- Save the above code in a file named
index.ts
. - Run
pulumi up
in the same directory as yourindex.ts
to create the resources. Pulumi will prompt you to confirm before creating anything.
This will set up MariaDB with persistent storage on the DigitalOcean Kubernetes Service.
-