Deploy the traefik2 helm chart on AWS EKS
TypeScriptDeploying the Traefik v2 Helm chart on AWS EKS involves setting up an EKS cluster and then using the
kubernetes.helm.v3.Chart
resource to deploy Traefik. Below is a step-by-step explanation and corresponding Pulumi TypeScript program to achieve this.Step 1: Set up an EKS Cluster
We will use the
awsx.eks.Cluster
resource which is a high-level component that abstractly represents an EKS cluster, to create the Kubernetes cluster. This includes creating the necessary AWS resources such as the EKS cluster itself, EC2 instances, and associated networking infrastructure like VPC, subnets, and security groups.Step 2: Deploy the Traefik v2 Helm Chart
Once the cluster is set up, we use
kubernetes.helm.v3.Chart
from the Kubernetes provider to deploy Traefik. This resource abstractly represents a Helm chart, which can be deployed onto a Kubernetes cluster. The Traefik Helm chart installs all necessary Kubernetes resources required for the ingress controller to work.Now, let's proceed with the Pulumi TypeScript program:
import * as eks from "@pulumi/eks"; import * as pulumi from "@pulumi/pulumi"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create an EKS Cluster. // The `awsx.eks.Cluster` resource creates and manages an EKS cluster. const cluster = new eks.Cluster("my-cluster", { vpcId: /* VPC ID here */, subnetIds: /* Subnet IDs here */, instanceType: "t2.medium", desiredCapacity: 2, // Set the number of worker nodes that we want. minSize: 1, maxSize: 3, storageClasses: "gp2", // Standard storage class. deployDashboard: false, // Dashboard is not recommended in production. }); // Export the cluster kubeconfig. export const kubeconfig = cluster.kubeconfig; // Step 2: Deploy the Traefik v2 Helm Chart. // The `kubernetes.helm.v3.Chart` resource deploys the specified Helm chart onto the EKS cluster. // Ensure that the `kubernetes` provider uses the cluster kubeconfig. const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: cluster.kubeconfig.apply(JSON.stringify), }); // Deploy Traefik using the Helm chart. const traefikChart = new k8s.helm.v3.Chart("traefik", { // The chart name "traefik" will fetch the Traefik v2 helm chart from the default Helm repository. chart: "traefik", version: "9.18.2", // Use the specific version you want to install. namespace: "kube-system", // Best practice to deploy infrastructure components into `kube-system`. fetchOpts: { repo: "https://helm.traefik.io/traefik", // The repository URL where the chart is located. } }, { provider: k8sProvider }); // Export the Traefik dashboard service endpoint. export const traefikEndpoint = traefikChart.getResourceProperty("v1/Service", "kube-system/traefik", "status") .apply(status => status.loadBalancer.ingress[0].hostname || status.loadBalancer.ingress[0].ip);
The above Pulumi program will create a new EKS cluster and deploy Traefik on it. The program also exports the kubeconfig necessary to manage the Kubernetes cluster with tools like
kubectl
and the Traefik dashboard service endpoint.To run the program, you'll need to have Pulumi installed, an AWS account and the AWS CLI set up, and aws-iam-authenticator installed. Save the code to a file called
index.ts
, then run the following Pulumi commands:pulumi stack init [stack-name]
pulumi up
- This command will prompt you to review the infrastructure changes and approve them.
After the run completes successfully, it will output the kubeconfig and Traefik dashboard endpoint, which you can use to access your Kubernetes cluster and the Traefik dashboard, respectively.