Deploy the nodeapp-chart helm chart on AWS EKS
TypeScriptTo deploy a Helm chart on AWS EKS using Pulumi, you'll need to follow these main steps:
- Provision an EKS cluster.
- Deploy the Helm chart to the EKS cluster.
I'll walk you through a Pulumi TypeScript program that accomplishes this. The program will use AWS and Kubernetes Pulumi providers. First, you will create an EKS cluster, and then you will deploy a Helm chart named
nodeapp-chart
to it.Here's an explanation of the resources used:
eks.Cluster
: This creates a new EKS cluster. It is a managed Kubernetes service that makes it easy to run Kubernetes on AWS without needing to manage the Kubernetes control plane.kubernetes.helm.v3.Chart
: This resource is used to deploy a Helm chart to a Kubernetes cluster. Helm charts help you define, install, and upgrade even the most complex Kubernetes applications.
Below is the detailed Pulumi program:
import * as pulumi from "@pulumi/pulumi"; import * as aws from "@pulumi/aws"; import * as eks from "@pulumi/eks"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create an EKS cluster const cluster = new eks.Cluster("my-cluster", { // `desiredCapacity`: the number of worker nodes // `minSize`: the minimum number of worker nodes the cluster can auto-scale to // `maxSize`: the maximum number of worker nodes the cluster can auto-scale to desiredCapacity: 2, minSize: 1, maxSize: 2, }); // Export the cluster's kubeconfig. export const kubeconfig = cluster.kubeconfig; // Step 2: Deploy the Helm chart to the cluster. // Pulumi uses the Helm SDK to manage Helm chart releases. const nodeappChart = new k8s.helm.v3.Chart("nodeapp-chart", { chart: "nodeapp-chart", // Fetch the Chart from a repository or a local Helm Chart (if it's not from a Helm repo). // `repo`: the Helm chart repository URL fetchOpts: { repo: "http://example.com/helm-charts", }, // `values`: the configuration for the Helm chart. You need to pass the configuration // specific to your application for the relevant Helm chart. values: { service: { type: "LoadBalancer", }, }, // Specify the namespace to deploy the Helm chart into. namespace: "default", }, { provider: cluster.provider }); // Useful for seeing the output in the Pulumi CLI after an update. // This line of code will give you the IP address that you can use to access your application. export const nodeappServiceIP = nodeappChart.getResourceProperty("v1/Service", "nodeapp-chart-nodeapp-chart", "status").apply(status => status.loadBalancer.ingress[0].ip);
Let's break down the important parts:
- We create an EKS cluster using
eks.Cluster
which abstracts away much of the setup. - We export the kubeconfig from the cluster which can be used to interface with the cluster using the kubectl CLI.
- The
k8s.helm.v3.Chart
resource is used to deploy a Helm chart onto the cluster. Thechart
argument specifies the name of the chart,fetchOpts
can contain the repository URL where the chart is hosted, andvalues
can be supplied to customize the chart settings. - The last line exports an IP address that can be used to access your Node.js application once it's deployed.
This program assumes that you have the
nodeapp-chart
available in a reachable Helm chart repository and that the chart includes a KubernetesService
namednodeapp-chart-nodeapp-chart
of typeLoadBalancer
which exposes the Node.js application to the internet. You'll need to replace the example repository URL and chart configurations with ones that match your actual chart.Please make sure you have Pulumi and AWS CLI set up and configured with the necessary permissions before running this program. Also, have Helm and kubectl CLI installed to interact with Helm charts and clusters, respectively. Run the program using the
pulumi up
command to deploy it to AWS.