Skip to content

Instantly share code, notes, and snippets.

@artipixel
Created September 15, 2022 10:42
Show Gist options
  • Select an option

  • Save artipixel/6849d2ebbfc77340877c13761fb4a6df to your computer and use it in GitHub Desktop.

Select an option

Save artipixel/6849d2ebbfc77340877c13761fb4a6df to your computer and use it in GitHub Desktop.
Kubernetes - AWS Karpenter auto scaling - specify a provisioner for a pod

Specify a specific provisioner for a pod

  1. Create your provisioner, important thing to add is a custom label and a value that we will use in node affinity on our pod.
  2. In your deployment, add under spec.template.spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                - key: node-pool
                  operator: In
                  values:
                  - test-pool   

as node-pool is your custom label and test-pool is the value that werte defined in the provisioner.

apiVersion: apps/v1
kind: Deployment
metadata:
name: inflate
namespace: dev
spec:
replicas: 0
selector:
matchLabels:
app: inflate
template:
metadata:
labels:
app: inflate
spec:
terminationGracePeriodSeconds: 0
containers:
- name: inflate
image: public.ecr.aws/eks-distro/kubernetes/pause:3.2
resources:
requests:
cpu: 1
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-pool
operator: In
values:
- test-pool
apiVersion: karpenter.sh/v1alpha5
kind: Provisioner
metadata:
name: test-provisioner
spec:
labels:
provisioner: default
autoscaler: karpenter
instance-type: spot
node-pool: test-pool
requirements:
- key: "node.kubernetes.io/instance-type"
operator: In
values: [t2.small, t2.large]
- key: topology.kubernetes.io/zone
operator: In
values: [eu-west-1a, eu-west-1b, eu-west-1c] # Zones
- key: karpenter.sh/capacity-type
operator: In
values: [spot]
- key: "kubernetes.io/arch"
operator: In
values: ["amd64"]
limits:
resources:
cpu: 100
provider:
subnetSelector:
karpenter.sh/discovery: data
securityGroupSelector:
karpenter.sh/discovery: data
ttlSecondsAfterEmpty: 300 # Keep the node alive for 5 minutes when empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment