1. Deploy the aws-node-termination-handler-2 helm chart on AWS EKS

    TypeScript

    In order to deploy the aws-node-termination-handler-2 Helm chart on AWS EKS, we'll need to follow a few steps. This involves setting up an EKS cluster, creating a node group, and then deploying the Helm chart to the cluster. The aws-node-termination-handler is an operational tool that helps you manage EC2 instance shutdown within Kubernetes.

    Here is a program written in TypeScript using Pulumi to accomplish this task:

    1. Set up an EKS cluster: We'll start by provisioning an EKS cluster using the eks.Cluster resource.
    2. Create a Node Group: After the cluster is provisioned, we will create an EKS managed node group using the eks.ManagedNodeGroup resource.
    3. Deploy the Helm Chart: Once the cluster is ready and the nodes are joined to the cluster, we will deploy the aws-node-termination-handler Helm chart using Pulumi's helm.v3.Chart resource.

    Below is the Pulumi TypeScript program that provides the complete setup. Make sure you have Pulumi installed, AWS credentials configured, and Helm CLI installed in your environment before you run the program.

    import * as pulumi from "@pulumi/pulumi"; import * as eks from "@pulumi/eks"; import * as aws from "@pulumi/aws"; import * as helm from "@pulumi/kubernetes/helm"; // Create an EKS cluster with default settings. const cluster = new eks.Cluster("my-cluster", { version: "1.21", instanceType: "t2.medium", desiredCapacity: 2, minSize: 1, maxSize: 3, storageClasses: "gp2", // default storage class for EKS }); // Export the cluster's kubeconfig. export const kubeconfig = cluster.kubeconfig; // Once the cluster is provisioned, create an EKS managed node group on it. const nodeGroup = new eks.ManagedNodeGroup("node-group", { cluster: cluster.core, nodeGroupName: "aws-node-termination-handler-node-group", nodeRoleArn: cluster.instanceRoles.apply(roles => roles[0].arn), scalingConfig: { desiredSize: 2, minSize: 1, maxSize: 3, }, instanceTypes: ["t3.medium"], }, { providers: { kubernetes: cluster.provider }, }); // Deploy the aws-node-termination-handler helm chart. const awsNodeTerminationHandlerChart = new helm.v3.Chart("aws-node-termination-handler", { chart: "aws-node-termination-handler", version: "2.x.x", // Specify the version you wish to deploy, which you can find in the Helm repository. fetchOpts: { repo: "https://aws.github.io/eks-charts", // Use the proper repository which contains the chart. }, }, { provider: cluster.provider }); // Export the Helm chart resources. export const helmResources = awsNodeTerminationHandlerChart.resources;

    Explanation

    • EKS Cluster: We're defining an EKS cluster using Pulumi's EKS package. This includes the Kubernetes version, size of the nodes, and the number of nodes in the cluster.

    • Node Group: We then define a managed node group. This is where EC2 instances will be provisioned and added to our cluster. We assign the role ARN from the cluster creation to ensure proper permissions.

    • Helm Chart: Finally, we're deploying the aws-node-termination-handler Helm chart. This chart installs a Kubernetes DaemonSet to help manage node shutdowns due to EC2 instance terminations.

    Run this program using pulumi up in the Pulumi project directory. It will perform the setup and output the kubeconfig that you can use to interact with the cluster and the resources created by the Helm chart.

    Remember that the aws-node-termination-handler requires that certain IAM policies be attached to the instance role so that it can properly manage EC2 instances. Make sure those policies are in place before deploying the chart.

    You can verify the deployment of the Helm Chart by checking the resources in the Kubernetes cluster:

    kubectl --kubeconfig=<path-to-kubeconfig> get all -n kube-system

    You should see the aws-node-termination-handler pods running in the kube-system namespace.