1. Deploy the sonatype-nexus helm chart on Kubernetes

    TypeScript

    To deploy the Sonatype Nexus Helm chart on a Kubernetes cluster using Pulumi, you will utilize the kubernetes.helm.sh/v3.Chart Pulumi resource. This allows you to deploy Helm charts within your Kubernetes cluster programmatically.

    Before you begin, make sure you have the following prerequisites in place:

    1. Pulumi CLI: Make sure you have installed Pulumi CLI and logged in to your Pulumi account.
    2. Kubernetes Cluster: You should have a Kubernetes cluster up and running and configured your kubectl to connect to it.
    3. Helm: The Nexus Helm chart should be available in a Helm repository. For the sake of this example, we'll assume it's in the default Helm stable repository which is deprecated but can still be used for learning purposes.
    4. Node.js and NPM: Pulumi programs are authored in general-purpose programming languages. In our case, we’re using TypeScript, which requires Node.js and npm.
    5. TypeScript: Make sure TypeScript is installed in your environment as we are going to write the Pulumi program using TypeScript.

    The following Pulumi program will declare a new Helm chart from a public repository and deploy it into the Kubernetes cluster. Remember to replace namespace with the namespace where you want to deploy Sonatype Nexus:

    import * as k8s from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; // Create an instance of the Kubernetes Chart class to deploy the Sonatype Nexus Helm chart. const nexusHelmChart = new k8s.helm.v3.Chart("nexus", { repo: "sonatype", // Specify the repository name, this should contain the Nexus Helm chart. chart: "nexus-repository-manager", // The name of the chart in the repository. namespace: "nexus", // The namespace in which to deploy the chart, replace with your desired namespace. // You can specify additional configurations here, like values to override defaults in the chart. values: { // Add necessary values here. // For example, if you want to expose Nexus as a LoadBalancer service, you could do something like: service: { type: "LoadBalancer", // More service configuration here, if required. }, // Always check the Helm chart's `values.yaml` file for the available configuration options. }, }); // Export the URL by getting the LoadBalancer IP allocated by the service, if applicable. export const nexusUrl = nexusHelmChart.getResourceProperty("v1/Service", "nexus/nexus-repository-manager", "status") .apply(status => `http://${status.loadBalancer.ingress[0].ip}:8081`);

    Here's an explanation of the components within our program:

    • @pulumi/kubernetes: This is the Pulumi Kubernetes provider package that gives you access to Kubernetes resources, including Helm charts.
    • Chart: This is the resource provided by Pulumi to deploy a Helm chart to the Kubernetes cluster. You will have to specify the necessary details, like the Helm repository and the chart you want to deploy.
    • values: This section is a direct mapping to the values.yaml file that you would have typically edited when using Helm CLI. Here, you can override any defaults set in the Helm chart. For Sonatype Nexus, you may want to configure persistence, networking, and Nexus-specific settings.
    • export: Pulumi allows you to export outputs which can be used to access information about your deployment. In this case, we are exporting the Nexus URL which will be assigned by the service of type LoadBalancer.

    To run this Pulumi program, save it to a file named index.ts, then execute the following commands:

    pulumi up

    This will prompt you to confirm the deployment. Upon confirmation, Pulumi will proceed to deploy the Nexus Helm chart into your Kubernetes cluster. After deployment, you can use the output URL to access the Nexus Repository Manager.