Deploy the nats-streaming helm chart on AWS EKS
TypeScriptIn order to deploy the NATS Streaming helm chart on an AWS EKS cluster using Pulumi, you will need to follow several steps. First, you must create an EKS cluster if you don't already have one. After the cluster is set up, you'll deploy the NATS Streaming helm chart onto it.
Below is a program written in TypeScript using Pulumi which sets up an EKS cluster and then deploys the NATS Streaming helm chart. The program uses two main Pulumi resources:
eks.Cluster
: This resource creates an EKS cluster on AWS. You can specify various configurations such as the desired capacity, instance types, and version of Kubernetes.kubernetes.helm.v3.Chart
: This Helm Chart resource allows you to deploy Helm charts onto your Kubernetes cluster. We will use this to install the NATS Streaming chart.
Here's the program:
import * as pulumi from "@pulumi/pulumi"; import * as awsx from "@pulumi/awsx"; import * as eks from "@pulumi/eks"; import * as k8s from "@pulumi/kubernetes"; // Create an EKS cluster. const cluster = new eks.Cluster("nats-streaming-cluster", { desiredCapacity: 2, minSize: 1, maxSize: 3, instanceType: "t2.medium", providerCredentialOpts: { profileName: pulumi.config.require("aws-profile"), // Ensure the AWS profile is configured in Pulumi config }, }); // Export the cluster's kubeconfig. export const kubeconfig = cluster.kubeconfig; // Set up the NATS Streaming Helm chart. // Make sure that Helm is installed and configured on your system. const natsStreamingChart = new k8s.helm.v3.Chart( "nats-streaming", { chart: "nats-streaming", version: "0.8.0", // Specify the version of the NATS Streaming helm chart you wish to deploy fetchOpts: { repo: "https://charts.helm.sh/stable", // The repository where the NATS Streaming helm chart is located }, }, {provider: cluster.provider} ); // Export the NATS Streaming service endpoint to access NATS. export const natsEndpoint = natsStreamingChart.getResourceProperty("v1/Service", "nats-streaming", "status").apply(status => status.loadBalancer.ingress[0].hostname);
Before running this program, you will need to configure your Pulumi with the relevant AWS credentials and settings. Make sure you have AWS access set up and kubectl installed and configured to manage Kubernetes clusters.
In the script:
- We initialize a new EKS cluster by defining the node size, and min/max scaling options. More configurations can be implemented as necessary.
- The
kubeconfig
output provides the necessary details to interact with your EKS cluster usingkubectl
. - We define a Helm chart resource for NATS Streaming, specifying the chart name and version.
- We fetch the helm chart from a specified helm repository.
- The EKS cluster is passed as the provider to the helm chart resource, linking the chart to the created cluster.
- Exported
natsEndpoint
parses the load balancer information from the deployed NATS Streaming service to give you an endpoint you can use to interact with the NATS Streaming service.
Please ensure that helm is installed and initialized in your local machine to successfully deploy helm charts with Pulumi.
After you've written this code in a
index.ts
file, you can deploy your infrastructure with the following steps:- Run
pulumi up
to preview and deploy the changes. - Pulumi CLI will show you the changes expected as per the script.
- Upon confirmation, Pulumi will provision the resources in the order specified.