How Do I Deploy the Karpenter Helm Chart on AWS EKS?
Deploying Karpenter on AWS EKS
In this guide, we will deploy Karpenter, an open-source node provisioning project built for Kubernetes, on an AWS EKS cluster using Pulumi. Karpenter automatically launches just the right compute resources to handle your cluster’s applications. The key services involved in this deployment are AWS EKS for the Kubernetes cluster and Helm for managing the Karpenter installation.
Step-by-Step Explanation
Step 1: Set Up Pulumi and AWS
- Ensure you have Pulumi installed. If not, you can install it from Pulumi’s installation guide.
- Configure AWS CLI with the necessary credentials. You can follow the AWS CLI configuration guide.
- Set up a new Pulumi project using
pulumi new
and select the appropriate template for TypeScript.
Step 2: Create an EKS Cluster
- Define the EKS cluster in your Pulumi program. This includes setting up the VPC, subnets, and the EKS cluster itself.
- Ensure that the EKS cluster has the necessary IAM roles and policies for Karpenter to function.
Step 3: Deploy Karpenter using Helm
- Add the Helm repository for Karpenter.
- Use the
@pulumi/kubernetes
package to deploy the Karpenter Helm chart to the EKS cluster. - Configure the necessary values for the Karpenter Helm chart, such as the cluster endpoint and service account.
Step 4: Verify the Deployment
- Once the deployment is complete, verify that Karpenter is running by checking the pods in the
karpenter
namespace. - You can also check the logs of the Karpenter controller to ensure it is functioning correctly.
Summary and Conclusion
In this guide, we successfully deployed Karpenter on an AWS EKS cluster using Pulumi. We started by setting up Pulumi and AWS, then created an EKS cluster, and finally deployed Karpenter using Helm. Karpenter helps in automatically managing the compute resources for your Kubernetes applications, making your cluster more efficient and cost-effective. By following these steps, you can leverage Karpenter to optimize your Kubernetes workloads on AWS EKS.
Full Code Example
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as k8s from "@pulumi/kubernetes";
// Create a VPC
const vpc = new aws.ec2.Vpc("eks-vpc", {
cidrBlock: "10.0.0.0/16",
enableDnsHostnames: true,
enableDnsSupport: true,
tags: {
Name: "eks-vpc",
},
});
// Create subnets
const subnet1 = new aws.ec2.Subnet("subnet1", {
vpcId: vpc.id,
cidrBlock: "10.0.1.0/24",
availabilityZone: "us-west-2a",
tags: { Name: "subnet1" },
});
const subnet2 = new aws.ec2.Subnet("subnet2", {
vpcId: vpc.id,
cidrBlock: "10.0.2.0/24",
availabilityZone: "us-west-2b",
tags: { Name: "subnet2" },
});
// Create an EKS cluster
const eksCluster = new aws.eks.Cluster("eks-cluster", {
roleArn: "arn:aws:iam::123456789012:role/EKS-Cluster-Role",
vpcConfig: {
subnetIds: [subnet1.id, subnet2.id],
},
tags: {
Name: "eks-cluster",
},
});
// Create IAM role and policy for Karpenter
const karpenterRole = new aws.iam.Role("karpenter-role", {
assumeRolePolicy: JSON.stringify({
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Principal: {
Service: "eks.amazonaws.com",
},
Action: "sts:AssumeRole",
},
],
}),
});
const karpenterPolicy = new aws.iam.RolePolicy("karpenter-policy", {
role: karpenterRole.id,
policy: JSON.stringify({
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Action: [
"ec2:DescribeInstances",
"ec2:DescribeLaunchTemplates",
"ec2:RunInstances",
"ec2:TerminateInstances",
],
Resource: "*",
},
],
}),
});
// Deploy Karpenter using Helm
const karpenterHelm = new k8s.helm.v3.Release("karpenter-helm", {
chart: "karpenter",
version: "0.5.0",
repositoryOpts: {
repo: "https://charts.karpenter.sh",
},
values: {
clusterName: eksCluster.name,
clusterEndpoint: eksCluster.endpoint,
serviceAccount: {
create: true,
name: "karpenter",
annotations: {
"eks.amazonaws.com/role-arn": karpenterRole.arn,
},
},
},
namespace: "karpenter",
});
export const vpcId = vpc.id;
export const eksClusterName = eksCluster.name;
export const karpenterHelmReleaseName = karpenterHelm.name;
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.