Skip to main content

CDK construct library that allows you install Karpenter in an AWS EKS cluster

Project description

cdk-eks-karpenter

This construct configures the necessary dependencies and installs Karpenter on an EKS cluster managed by AWS CDK.

Prerequisites

Usage with EC2 Spot Capacity

If you have not used EC2 spot in your AWS account before, follow the instructions here to create the service linked role in your account allowing Karpenter to provision EC2 Spot Capacity.

Using

In your CDK project, initialize a new Karpenter construct for your EKS cluster, like this:

const cluster = new Cluster(this, 'testCluster', {
  vpc: vpc,
  role: clusterRole,
  version: KubernetesVersion.V1_21,
  defaultCapacity: 1
});

const karpenter = new Karpenter(this, 'Karpenter', {
  cluster: cluster
});

This will install and configure Karpenter in your cluster. To have Karpenter do something useful, you also need to create a provisioner for AWS. You can do that from CDK using addProvisioner(), similar to the example below:

karpenter.addProvisioner('spot-provisioner', {
  requirements: [{
    key: 'karpenter.sh/capacity-type',
    operator: 'In',
    values: ['spot']
  }],
  limits: {
    resources: {
      cpu: 20
    }
  },
  provider: {
    subnetSelector: {
      Name: 'PublicSubnet*'
    },
    securityGroupSelector: {
      'aws:eks:cluster-name': cluster.clusterName
    }
  }
});

Known issues

Versions earlier than v0.6.1 fails to install

As of aws/karpenter#1145 the Karpenter Helm chart is refactored to specify clusterEndpoint and clusterName on the root level of the chart values, previously these values was specified under the key controller.

Testing

This construct adds a custom task to projen, so you can test a full deployment of an EKS cluster with Karpenter installed as specified in test/integ.karpenter.ts by running the following:

export CDK_DEFAULT_REGION=<aws region>
export CDK_DEFAULT_ACCOUNT=<account id>
npx projen test:deploy

As the above will create a cluster without EC2 capacity, with CoreDNS and Karpenter running as Fargate pods, you can test out the functionality of Karpenter by deploying an inflation deployment, which will spin up a number of pods that will trigger Karpenter creation of worker nodes:

kubectl apply -f test/inflater-deployment.yml

You can clean things up by deleting the deployment and the CDK test stack:

kubectl delete -f test/inflater-deployment.yml
npx projen test:destroy

FAQ

I'm not able to launch spot instances

  1. Ensure you have the appropriate linked role available in your account, for more details, see the karpenter documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk-eks-karpenter-0.0.0.tar.gz (35.9 kB view details)

Uploaded Source

Built Distribution

cdk_eks_karpenter-0.0.0-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

Details for the file cdk-eks-karpenter-0.0.0.tar.gz.

File metadata

  • Download URL: cdk-eks-karpenter-0.0.0.tar.gz
  • Upload date:
  • Size: 35.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.25.0 requests-toolbelt/0.9.1 urllib3/1.26.2 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.3 CPython/3.9.10

File hashes

Hashes for cdk-eks-karpenter-0.0.0.tar.gz
Algorithm Hash digest
SHA256 b5c013f337d3000b3fdd64dcfd41cd3ab7d79dffdf7179243056e2bdc65caa1e
MD5 c009f5f6bad9e9e7a52e67a480c1b0ca
BLAKE2b-256 9c2b864b895c57e5ea02cd040e470fad6c8e2da046b8db1d028c2b097a8d2a9b

See more details on using hashes here.

File details

Details for the file cdk_eks_karpenter-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: cdk_eks_karpenter-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 34.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.25.0 requests-toolbelt/0.9.1 urllib3/1.26.2 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.3 CPython/3.9.10

File hashes

Hashes for cdk_eks_karpenter-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81518cf451e1e7de09e6eb9f8ad054f1d6f1fc40d7f330ea72c668dc720ff5b1
MD5 61203cf75acc4d0d5df842c9444ec4b8
BLAKE2b-256 8288858ca3a7b57b90c6daf6772fa3648768383eb3ed15fccd6582e4d5d8e6e0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page