Deploy the aws-eks-asg-rolling-update-handler helm chart on AWS EKS
TypeScriptIn order to deploy the
aws-eks-asg-rolling-update-handler
helm chart onto an AWS EKS cluster using Pulumi, you'll need to perform the following steps:-
Create an EKS Cluster: You need an existing Kubernetes cluster to install helm charts. AWS EKS is Amazon's managed Kubernetes service, which can be created using Pulumi's EKS package.
-
Create an IAM Role for EKS: AWS EKS requires a Role with specific permissions that the EKS service can assume to create AWS resources.
-
Install the Helm Chart: Once you have the cluster up and running, you can deploy the helm chart into your EKS cluster using the
helm.sh/v3.Chart
class from Pulumi's Kubernetes provider.
Here's a program written in TypeScript that does all of the above:
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", { instanceType: "t2.medium", desiredCapacity: 2, minSize: 1, maxSize: 2, storageClasses: "gp2", deployDashboard: false, }); // Create an IAM role and instance profile to use with the node group const role = new aws.iam.Role("my-cluster-iam-role", { assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "ec2.amazonaws.com" }), }); // Attach the Amazon EKS worker node IAM managed policy to the created role const policyAttachment = new aws.iam.RolePolicyAttachment("my-cluster-role-policy", { policyArn: "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy", role: role.name, }); const instanceProfile = new aws.iam.InstanceProfile("my-cluster-instance-profile", { role: role.name, }); // Create a node group based on the given IAM role and profile const nodeGroup = cluster.createNodeGroup("my-cluster-node-group", { instanceType: "t2.medium", desiredCapacity: 2, minSize: 1, maxSize: 2, instanceProfile: instanceProfile, }); // Create a provider for installing Helm charts in the EKS cluster const provider = new k8s.Provider("my-k8s-provider", { kubeconfig: cluster.kubeconfig.apply(JSON.stringify), }); // Deploy the aws-eks-asg-rolling-update-handler helm chart into the EKS cluster const asgRollingUpdateHandlerChart = new k8s.helm.v3.Chart( "asg-rolling-update-handler", { chart: "aws-eks-asg-rolling-update-handler", version: "0.1.0", // You should specify the exact version you want to deploy fetchOpts: { repo: "https://aws.github.io/eks-charts", // Replace with the correct repository if different }, }, { provider: provider } ); // Export the cluster's kubeconfig. export const kubeconfig = cluster.kubeconfig;
This program does the following:
- It imports the required Pulumi packages, including AWS, EKS, and Kubernetes.
- It creates an EKS cluster with
eks.Cluster
, specifying the instance type, desired capacity, and other cluster-related configurations. The EKS cluster will function as the host for our Kubernetes applications.- You can find detailed documentation of the
eks.Cluster
here.
- You can find detailed documentation of the
- An IAM Role necessary for EKS worker nodes is created with the
aws.iam.Role
class, assuming an EC2 role policy.- The created role is subsequently attached to the Amazon-provided EKS worker node policy.
- A
kubernetes.Provider
is then declared using the generated kubeconfig from our EKS cluster. This provider is necessary for Pulumi to communicate with the cluster. - We install the
aws-eks-asg-rolling-update-handler
Helm chart into our EKS cluster usingk8s.helm.v3.Chart
, which is a higher-level abstraction provided by Pulumi to manage Helm charts in a Kubernetes cluster.- Make sure to specify the exact version of the Helm chart and the correct repository URL.
- Finally, we export the kubeconfig to allow interaction with the cluster using
kubectl
or any other Kubernetes tool.
You need to check if the
aws-eks-asg-rolling-update-handler
helm chart is available in the Helm repository and find out the current version of the chart for a proper setup.Remember to run
npm install
to install the necessary dependencies before running this program with Pulumi CLI. Deploy this Pulumi stack using the commandpulumi up
. When prompted, confirm the deployment by selectingyes
.-