1. Deploy the simple-mongodb helm chart on Kubernetes


    To deploy a Helm chart on a Kubernetes cluster using Pulumi, you'll need to use the @pulumi/kubernetes package which provides the resources for managing Kubernetes resources including deploying Helm charts.

    In this tutorial, I'll walk you through deploying the simple-mongodb Helm chart. We'll use the Chart resource from the Pulumi Kubernetes package that makes deploying Helm charts simple and declarative.

    The Helm chart will be deployed into a Kubernetes cluster, which you need to have access to. This program assumes you have a configured kubeconfig file on your machine or in your environment which Pulumi will use to communicate with your cluster.

    Here's how you can do it with Pulumi using TypeScript:

    1. First, make sure you have Pulumi installed and configured for TypeScript.
    2. You need to have access to a Kubernetes cluster and have your kubeconfig file set up.
    3. Create a new Pulumi project if you haven't already.

    Now let's proceed with the program.

    import * as k8s from "@pulumi/kubernetes"; // We are creating a new instance of Chart, which represents a Helm chart installation. // 'simple-mongodb' is the name we're giving to our deployment. const mongoDbChart = new k8s.helm.v3.Chart("simple-mongodb", { // Specify the chart and version you wish to deploy. // Here 'chart' refers to the Helm chart we'd like to deploy. // If you're referencing a chart from a specific Helm repo, you'll also need to provide 'repo' attribute. chart: "mongodb", version: "7.8.10", // Replace with the version of MongoDB Helm chart you want to deploy namespace: "default", // The Kubernetes namespace to which the Helm chart will be deployed. // Values in the 'values' block are passed to the Helm chart, allowing you to customize the deployment. values: { // Customize your MongoDB deployment here. For example, you can set MongoDB username, password, etc. // These values depend on the Helm chart's available configurable options. // Check the chart documentation for available configuration parameters. // For our example, we'll set the service type to LoadBalancer to expose it externally. // This is just a default example, the actual MongoDB Helm chart might require different options. service: { type: "LoadBalancer", }, }, }); // Export the MongoDB instance's name and service URL export const mongoDbName = mongoDbChart.getResourceProperty("v1/Service", "default", "service-name", "metadata"); export const mongoDbEndpoint = mongoDbChart.getResourceProperty("v1/Service", "default", "service-name", "status");


    • We import the necessary Pulumi Kubernetes package.
    • We create a new Helm chart instance named simple-mongodb.
    • We specify the Helm chart (mongodb) and the exact chart version we want to deploy. It's a good practice to specify the version to ensure the deployment does not change unexpectedly when the chart gets updated.
    • We define the namespace where we want to deploy the chart. In this case, it's the default namespace, but you can specify a different one if required.
    • We're passing a set of values to the values property to customize our MongoDB deployment. The example shows how you might set the service type; however, you would need to check the actual MongoDB Helm chart for the configurable options it supports.
    • Lastly, we export some of the deployment's properties for easy access. This will make it easier to identify the created resources' names and access the MongoDB service URL once deployed.

    What's Next?

    After running this Pulumi program, the specified version of MongoDB will be installed onto your Kubernetes cluster. You can then access the MongoDB instance using the service URL provided in the exported variables. Make sure the security settings of your Kubernetes cluster allow you to access the resources as needed.