How to setup Karpenter on existing cluster?

To setup Karpenter in the existing cluster, the user should follow below steps:

1. Setup environment variable

export KARPENTER_VERSION=v0.26.1

export CLUSTER_NAME="<cluster-name>"

export AWS_DEFAULT_REGION="<region-name>"

export AWS_ACCOUNT_ID="$(aws sts get-caller-identity --query Account --output text)"

export CLUSTER_ENDPOINT="$(aws eks --region <region-name> describe-cluster --name <cluster-name> --query "cluster.endpoint" --output text)"

export TEMPOUT=$(mktemp)

echo $KARPENTER_VERSION $CLUSTER_NAME $AWS_DEFAULT_REGION $AWS_ACCOUNT_ID $CLUSTER_ENDPOINT $TEMPOUT

2. Cloudformation template to create IAM instance role

curl -fsSL https://github.com/aws/karpenter/blob/df39f82ab40ac2a63160a2d1954a277c744a50a3/website/content/en/v0.26/getting-started/getting-started-with-eksctl/cloudformation.yaml  > $TEMPOUT \

&& aws cloudformation deploy \

  --stack-name "Karpenter-${CLUSTER_NAME}" \

  --template-file "${TEMPOUT}" \

  --capabilities CAPABILITY_NAMED_IAM \

  --parameter-overrides "ClusterName=${CLUSTER_NAME}"

export KARPENTER_IAM_ROLE_ARN="arn:aws:iam::${AWS_ACCOUNT_ID}:role/${CLUSTER_NAME}-karpenter"

echo $CLUSTER_ENDPOINT $KARPENTER_IAM_ROLE_ARN

$ aws iam create-service-linked-role --aws-service-name spot.amazonaws.com || true

3. Create IAM identity mapping

$ eksctl create iamidentitymapping \

  –-username=system:node:{{EC2PrivateDNSName}} \

  –-arn="arn:aws:iam::${AWS_ACCOUNT_ID}:role/KarpenterNodeRole-${CLUSTER_NAME}" \

  –-group=system:bootstrappers \

  –-group=system:nodes

4. Create the KarpenterController IAM role

$ eksctl create iamserviceaccount --cluster=${CLUSTER_NAME} --name=karpenter --namespace=karpenter --attach-policy-arn=arn:aws:iam:${AWS_ACCOUNT_ID}:policy/KarpenterControllerPolicy-${CLUSTER_NAME} --override-existing-serviceaccounts --approve

5. Install Karpenter using helm

helm install karpenter oci://public.ecr.aws/karpenter/karpenter --version ${KARPENTER_VERSION} –-namespace karpenter –-create-namespace \

  karpenter karpenter/karpenter \

  –-version ${KARPENTER_VERSION} \

  –-set serviceAccount.annotations."eks\.amazonaws\.com/role-arn"=${KARPENTER_IAM_ROLE_ARN} \

  –-set clusterName=${CLUSTER_NAME} \

  –-set clusterEndpoint=${CLUSTER_ENDPOINT} \

  –-set aws.defaultInstanceProfile=KarpenterNodeInstanceProfile-${CLUSTER_NAME} \

  –-wait # for the defaulting webhook to install before creating a Provisioner

For a detailed document

For any kind of support, put it in the comment box.


Similar Articles