Using kubernetes karpenter.k8s.aws with image.toolkit.fluxcd.io
TypeScriptKarpenter is an open-source, flexible, and high-performance Kubernetes cluster autoscaler built by AWS that runs alongside the Kubernetes Cluster Autoscaler. It works directly with Kubernetes Scheduling to efficiently launch right-sized compute resources in response to unscheduled pods.
Flux is a set of continuous and progressive delivery solutions for Kubernetes, and it is a part of the CNCF incubating projects. With Flux, you can implement GitOps strategies to manage your clusters and deliver applications automatically.
In the Pulumi program below, we will use the Pulumi Kubernetes Provider to deploy Karpenter and Flux on an existing Kubernetes cluster. Please note that the program assumes you have an existing EKS Cluster on AWS and that you have already configured Pulumi with the appropriate credentials and settings.
Here is a Pulumi TypeScript program that achieves this:
- It installs the Karpenter Helm chart into an AWS EKS cluster.
- It installs the Flux toolkit into the same cluster.
Before you run this program, make sure to set up your Pulumi and Kubernetes configurations for AWS and ensure that
kubectl
is able to connect to your EKS cluster.import * as k8s from "@pulumi/kubernetes"; const karpenterVersion = "0.5.0" // Specify the desired version of Karpenter here const fluxVersion = "0.23.0" // Specify the desired version of Flux here // Helm Release for installing Karpenter to the cluster const karpenterRelease = new k8s.helm.v3.Release("karpenter", { chart: "karpenter", version: karpenterVersion, repositoryOpts: { repo: "https://charts.karpenter.sh", }, namespace: "karpenter", // It's good practice to deploy system tools in separate namespaces // Values from: https://karpenter.sh/docs/getting-started/ values: { clusterName: "YOUR_EKS_CLUSTER_NAME", // Replace with your EKS cluster name clusterEndpoint: "YOUR_EKS_CLUSTER_ENDPOINT", // Replace with your EKS cluster endpoint aws: { defaultInstanceProfile: "KarpenterNodeInstanceProfile", // Replace with your instance profile }, }, }, { provider: k8sProvider }); // Helm Release for installing Flux Toolkit to the cluster const fluxBootstrapRelease = new k8s.helm.v3.Release("fluxcd", { chart: "flux2", version: fluxVersion, repositoryOpts: { repo: "https://charts.fluxcd.io", }, namespace: "flux-system", // It's good practice to deploy system tools in separate namespaces // Values from: https://fluxcd.io/docs/installation/ values: { gitRepository: { url: "https://github.com/your-org/your-repo", // Replace with your Git repository for storing Flux configurations ref: { branch: "main", }, }, // Define additional custom values or use default ones }, }, { provider: k8sProvider }); // Export the Helm chart names export const karpenterChartName = karpenterRelease.name; export const fluxChartName = fluxBootstrapRelease.name;
Replace the following placeholders with your actual values:
YOUR_EKS_CLUSTER_NAME
: Your Amazon EKS cluster name.YOUR_EKS_CLUSTER_ENDPOINT
: Endpoint URL of your EKS cluster.KarpenterNodeInstanceProfile
: The instance profile for the nodes that Karpenter will manage.https://github.com/your-org/your-repo
: The URL of the Git repository where Flux will monitor for changes.
This program initializes two
Helm Release
resources, one forkarpenter
and one forfluxcd
. TheHelm Release
resource is a custom resource provided by Pulumi's Kubernetes provider that allows deploying Helm charts.The
karpenterRelease
object will deploy Karpenter using its Helm chart, specifying the version and necessary configuration for integration with your EKS cluster.Similarly, the
fluxBootstrapRelease
object will deploy the Flux toolkit using its Helm chart and automatically set up your cluster to synchronize with a specified Git repository.You must ensure that your CLI has access to your Kubernetes cluster (
kubectl
is configured correctly) and that you have the necessary permissions to deploy to the cluster. After setting the correct values for your environment and running the program with Pulumi, Karpenter and Flux would be deployed in your Kubernetes cluster, automating pod scheduling and application delivery through GitOps.