1. Provision an AWS EKS Fargate cluster that uses ingress controllers to forward a subdomain to running pods.

    TypeScript

    To achieve this, we'll provision an EKS Fargate cluster, deploy an NGINX Ingress Controller, and set up an Ingress resource to route traffic to our pods. Below is the Pulumi program in TypeScript to accomplish this.

    import * as pulumi from "@pulumi/pulumi"; import * as aws from "@pulumi/aws"; import * as eks from "@pulumi/eks"; import * as k8s from "@pulumi/kubernetes"; import * as k8sIngressNginx from "kubernetes-ingress-nginx"; // Create an EKS cluster const cluster = new eks.Cluster("fargateCluster", { fargate: true, instanceRoles: [new aws.iam.Role("eksRole", { assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "eks.amazonaws.com" }), })], }); // Create a Fargate profile const fargateProfile = new aws.eks.FargateProfile("fargateProfile", { clusterName: cluster.eksCluster.name, fargateProfileName: "fargate-profile", podExecutionRoleArn: cluster.instanceRoles[0].arn, selectors: [{ namespace: "default", }], }); // Deploy the NGINX Ingress Controller using Helm const nginxIngress = new k8sIngressNginx.IngressController("nginxIngress", { controller: { publishService: { enabled: true, }, }, }, { provider: cluster.provider }); // Create a sample deployment const appLabels = { app: "hello-app" }; const deployment = new k8s.apps.v1.Deployment("hello-app", { spec: { selector: { matchLabels: appLabels }, replicas: 2, template: { metadata: { labels: appLabels }, spec: { containers: [{ name: "nginx", image: "nginx" }] } } } }, { provider: cluster.provider }); // Create a service for the deployment const service = new k8s.core.v1.Service("hello-app", { metadata: { labels: appLabels }, spec: { type: "ClusterIP", ports: [{ port: 80, targetPort: 80 }], selector: appLabels, } }, { provider: cluster.provider }); // Create an Ingress resource const ingress = new k8s.networking.v1.Ingress("hello-app-ingress", { metadata: { annotations: { "nginx.ingress.kubernetes.io/rewrite-target": "/", }, }, spec: { rules: [{ host: "subdomain.example.com", http: { paths: [{ path: "/", pathType: "Prefix", backend: { service: { name: service.metadata.name, port: { number: 80 }, } } }] } }] } }, { provider: cluster.provider }); // Export the cluster's kubeconfig export const kubeconfig = cluster.kubeconfig;

    This Pulumi program does the following:

    1. Creates an EKS cluster with Fargate support.
    2. Sets up a Fargate profile for the default namespace.
    3. Deploys the NGINX Ingress Controller using Helm.
    4. Creates a sample NGINX deployment and service.
    5. Sets up an Ingress resource to route traffic from a subdomain to the NGINX pods.

    Remember to replace subdomain.example.com with your actual subdomain.