Deploy the ingress-controller helm chart on AWS EKS
TypeScriptTo deploy an ingress-controller Helm chart on an AWS EKS cluster using Pulumi, you will need to follow a series of steps:
-
Set up the EKS cluster using the
aws.eks.Cluster
resource, which allows you to provision an EKS cluster on AWS. EKS Cluster Documentation -
Once you have the EKS cluster ready, use the
kubernetes.helm.v3.Chart
resource from the Kubernetes package to deploy the ingress-controller Helm chart onto the cluster. Helm Chart Documentation
Here's a program written in TypeScript that accomplishes these steps. Notice that this program assumes that you have set up the Pulumi AWS provider and have AWS credentials configured in your environment.
import * as pulumi from "@pulumi/pulumi"; import * as aws from "@pulumi/aws"; import * as eks from "@pulumi/eks"; import * as k8s from "@pulumi/kubernetes"; // Create an EKS cluster. const cluster = new eks.Cluster("my-cluster", { // You can specify additional options here, like instance size, desired capacity for the default node group, etc. }); // Export the cluster's kubeconfig. export const kubeconfig = cluster.kubeconfig; // Create a Kubernetes provider instance that uses our EKS cluster. const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: cluster.kubeconfig.apply(JSON.stringify), }); // Deploy the ingress-controller Helm chart onto our EKS cluster. const ingressControllerChart = new k8s.helm.v3.Chart( "nginx-ingress", { chart: "nginx-ingress", version: "1.41.3", // Optional: specify the chart version repo: "ingress-nginx", // Optional: if your helm chart is in a helm repo, specify it here // You can specify additional chart values here, such as configuration parameters }, { provider: k8sProvider } ); // Optional: Export the ingress-controller endpoint to access it from the internet export const ingressEndpoint = ingressControllerChart.getResourceProperty("v1/Service", "my-nginx-ingress-controller", "status").apply(status => { const ingress = status.loadBalancer.ingress[0]; if (ingress.hostname !== undefined) { return `http://${ingress.hostname}/`; } return ingress.ip !== undefined ? `http://${ingress.ip}/` : undefined; });
Let's go through what this code does:
-
The
eks.Cluster
resource is used to create an EKS cluster named "my-cluster". This cluster will have a default node group with the default configuration unless other parameters are specified. -
The kubeconfig needed to communicate with the cluster is exported, making it possible to interact with the cluster using
kubectl
or other Kubernetes tools. -
A
k8s.Provider
resource instance is created which instructs Pulumi to use the kubeconfig of the newly created EKS cluster for deploying Kubernetes resources. -
The
k8s.helm.v3.Chart
resource is used to deploy thenginx-ingress
Helm chart. Thechart
,version
, andrepo
properties specify which Helm chart to deploy. In this case, it's thenginx-ingress
chart from theingress-nginx
repository.
Lastly, there is an optional export of
ingressEndpoint
which would provide the internet-facing endpoint of the ingress controller. However, depending on your cloud configurations and settings within your Helm chart, you might need to adjust the details for how you get the endpoint.Please note that some parameters are optional and need to be adjusted based on the actual ingress controller's Helm chart version, repository, and configuration options.
Make sure to run this code using the Pulumi CLI, which will take care of provisioning the resources in the correct order. You can run
pulumi up
after setting up your Pulumi project and placing this code inindex.ts
.-