Featured image of post Kubernetes Node role labeler

Kubernetes Node role labeler

Now nodes can assign roles to themselves

Description

Node Role Labeler has long been sought after, a simple operator, but the task is fulfilled. The problem is that Kubernetes, specifically kubelet, cannot assign itself a label of node-role.kubernetes.io/ROLE_NAME when creating a node, because of the kubernetes.io protected prefix. Not very convenient.

Here I have Karpenter, or Cluster Autoscaler, no matter what, I want nodes to have nice roles immediately, and it does not come out of the box only by hand. Now we can attach node-role.cluster.local/NAME and the operator will create an automatically copy with a domain kubernetes.io. In reverse also works. More information - read on GitHub.

Demo

Karpenter configuration

Here is how we can immediately attach labels to Karpenter nodes.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
apiVersion: karpenter.k8s.aws/v1beta1
kind: EC2NodeClass
metadata:
  name: private
spec:
  amiFamily: AL2
  metadataOptions:
    httpEndpoint: enabled
    httpProtocolIPv6: disabled
    httpPutResponseHopLimit: 2
    httpTokens: required
  role: Karpenter-development-role
  securityGroupSelectorTerms:
  - tags:
      karpenter.sh/discovery: development
  subnetSelectorTerms:
  - tags:
      karpenter.sh/discovery/development/subnet: private
  tags:
    karpenter.sh/discovery: development
---
apiVersion: karpenter.sh/v1beta1
kind: NodePool
metadata:
  name: on-demand-amd64
spec:
  disruption:
    budgets:
    - nodes: 20%
    - nodes: "5"
    - duration: 20h
      nodes: "0"
      schedule: 0 5 * * *
    consolidationPolicy: WhenUnderutilized
    expireAfter: 720h
  limits:
    cpu: "200"
    memory: 400Gi
  template:
    metadata:
      labels:
        node-role.cluster.local/on-demand-amd64: ""
    spec:
      nodeClassRef:
        name: private
      requirements:
      - key: kubernetes.io/arch
        operator: In
        values:
        - amd64
      - key: node.kubernetes.io/instance-type
        operator: In
        values:
        - r5a.4xlarge
        - r5a.2xlarge
        - r5a.xlarge
        - r5a.large
        - r5a.medium
        - r5.4xlarge
        - r5.2xlarge
        - r5.xlarge
        - r5.large
        - r5.medium
        - m6i.4xlarge
        - m6i.2xlarge
        - m6i.xlarge
        - m6i.large
        - m6i.medium
        - m5a.4xlarge
        - m5a.2xlarge
        - m5a.xlarge
        - m5a.large
        - m5a.medium
        - c6a.4xlarge
        - c6a.2xlarge
        - c6a.xlarge
        - c6a.large
        - c6a.medium
        - c6.4xlarge
        - c6.2xlarge
        - c6.xlarge
        - c6.large
        - c6.medium
        - t3a.4xlarge
        - t3a.2xlarge
        - t3a.xlarge
        - t3a.large
        - t3a.medium
      - key: karpenter.sh/capacity-type
        operator: In
        values:
        - on-demand
All rights reserved
Built with Hugo
Theme Stack designed by Jimmy