1. Using kubernetes kustomize with stack.formance.com

    TypeScript

    Kustomize is a standalone tool to customize Kubernetes objects through a kustomization file. With Pulumi, you can apply kustomization directly by using Kubernetes provider's kubernetes.kustomize.Directory class.

    Using this class, you can deploy resources from a directory containing kustomization.yaml. This approach is beneficial for managing complex Kubernetes applications with ease, as kustomize allows for template-free customization of the configuration.

    Below is a TypeScript program that demonstrates how you can use Pulumi to deploy a set of Kubernetes resources described by kustomize. Make sure you have a directory with a kustomization.yaml and related Kubernetes YAML configuration files that you wish to apply to the cluster.

    import * as k8s from "@pulumi/kubernetes"; const kustomizeDirectory = "path/to/your/kustomization/folder"; // Create resources from the kustomization directory const kustomizedResources = new k8s.kustomize.Directory("kustomizedResources", { directory: kustomizeDirectory, }); // You can export certain values from the stack if needed // For example, if your kustomization creates a Kubernetes Service with a LoadBalancer, // you might want to export the resulting LoadBalancer endpoint: export const serviceEndpoint = kustomizedResources.getResourceProperty("v1/Service", "yourServiceName", "status").apply(status => status.loadBalancer?.ingress[0].hostname || status.loadBalancer?.ingress[0].ip);

    In this program:

    1. We import the @pulumi/kubernetes package which contains the Kubernetes-related resources you can manage with Pulumi.
    2. We define kustomizeDirectory which points to the directory containing your kustomization.yaml file and associated Kubernetes YAMLs. Replace "path/to/your/kustomization/folder" with the correct path.
    3. We create a Pulumi resource of kind kustomize.Directory which represents the set of Kubernetes resources defined by the kustomization file.
    4. Additionally, we show an example of how to export values from the stack. Here, serviceEndpoint would export the endpoint of the LoadBalancer service if one is created using the kustomize configuration.

    To use this program, replace "path/to/your/kustomization/folder" with the actual directory path containing your kustomization.yaml. If you're interested in capturing the output of a specific Kubernetes resource created by kustomize, adapt the getResourceProperty method with the appropriate resource type and name.

    Remember to have your Kubernetes cluster access configured, and Pulumi CLI installed and set up. You will also need to install the required NPM packages by running npm install in your project directory.

    After that, deploy the configuration using the Pulumi CLI by running pulumi up. This will provision the Kubernetes resources as per the kustomization file on your configured cluster.

    For more information on using the Pulumi Kubernetes kustomize integration, you can check the official Pulumi documentation.