Skip to content

Karpenter Custom NodePool as Default

Configure a custom NodePool as your primary

karpenter

EKS Auto mode comes with pre-installed Karpenter Autoscaler, a default NodeClass, and a default NodePool. The default NodePool provisions AMD architecture, on-demand servers. While this makes it easy to get started, many organisations have more complex requirements — such as deploying specific CPU or GPU instances, or using Spot or Reserved instances to reduce cost.

Custom NodePool as default

The default NodePool provided by AWS cannot be modified. However, Karpenter allows you to order NodePools using the spec.weight field so the scheduler attempts to schedule one NodePool before another. This can be used to define a custom NodePool with higher priority than the default.

ec2 Spot instance

NodePool with Spot and On-Demand instances

In this example, I am creating a custom NodePool with priority over the default. This NodePool provisions both Spot and On-Demand instances. Karpenter aims to use the most cost-effective instances, which are often Spot. You can control the On-Demand vs Spot ratio using weighted NodePools or by creating two NodePools at the same weight.

primary-nodepool.yaml

apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: primary-nodepool
spec:
  weight: 50
  template:
    spec:
      expireAfter: 336h
      nodeClassRef:
        group: eks.amazonaws.com
        kind: NodeClass
        name: default
      requirements:
      - key: karpenter.sh/capacity-type
        operator: In
        values: ["spot","on-demand"]
      - key: eks.amazonaws.com/instance-category
        operator: In
        values: ["c","m","r"]
      - key: eks.amazonaws.com/instance-generation
        operator: Gt
        values: ["5"]
      - key: kubernetes.io/arch
        operator: In
        values:
        - amd64
      - key: kubernetes.io/os
        operator: In
        values:
        - linux
      terminationGracePeriod: 24h0m0s

Since primary-nodepool has a higher weight, it will be selected first.

karpenter

If you have purchased a Savings Plan or Reserved Instances, this method can be used to make Karpenter prioritise that reserved capacity ahead of other instance types.