Notes to Self

Alex Sokolsky's Notes on Computers and Programming

k8s Nodes

Count cluster nodes:

kubectl get nodes --no-headers | wc -l


kubectl get nodes -o json | jq '.items | length'

List taints for all the nodes

kubectl get nodes -o json|jq '.items[].spec.taints'

Example output:

    "effect": "NoSchedule",
    "key": "",
    "value": "fargate"
    "effect": "NoSchedule",
    "key": "",
    "value": "eks-core-services"


kubectl get nodes -o=",TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect"


NodeName                               TaintKey                         TaintValue          TaintEffect
fargate-ip-10-14-81-126.ec2.internal   fargate             NoSchedule
ip-10-14-102-143.ec2.internal               eks-core-services   NoSchedule
ip-10-14-103-86.ec2.internal           <none>                           <none>              <none>
ip-10-14-83-79.ec2.internal                 eks-core-services   NoSchedule
ip-10-14-86-20.ec2.internal                 eks-core-services   NoSchedule
ip-10-14-86-93.ec2.internal            <none>                           <none>              <none>
ip-10-14-91-35.ec2.internal                 eks-core-services   NoSchedule
ip-10-14-94-20.ec2.internal                 eks-core-services   NoSchedule
ip-10-14-94-45.ec2.internal            <none>                           <none>              <none>
ip-10-14-99-93.ec2.internal            <none>                           <none>              <none>

List info for all the nodes:

kubectl get nodes -o json|jq '.items[].status.nodeInfo'

Example output:

  "architecture": "amd64",
  "bootID": "**************",
  "containerRuntimeVersion": "containerd://1.6.6",
  "kernelVersion": "5.10.210-201.855.amzn2.x86_64",
  "kubeProxyVersion": "v1.27.9-eks-680e576",
  "kubeletVersion": "v1.27.9-eks-680e576",
  "machineID": "",
  "operatingSystem": "linux",
  "osImage": "Amazon Linux 2",
  "systemUUID": "******************"
  "architecture": "amd64",
  "bootID": "****************************",
  "containerRuntimeVersion": "containerd://1.6.31+bottlerocket",
  "kernelVersion": "5.15.152",
  "kubeProxyVersion": "v1.27.11-eks-9572756",
  "kubeletVersion": "v1.27.11-eks-9572756",
  "machineID": "*******************",
  "operatingSystem": "linux",
  "osImage": "Bottlerocket OS 1.19.4 (aws-k8s-1.27)",
  "systemUUID": "***********************"

Taint/UnTaint a node

To taint the node1 with key1=value1:

kubectl taint nodes node1 key1=value1:NoSchedule

No pod will be able to schedule onto node1 unless it has a matching toleration.

To remove the taint added by the command above, you can run:

kubectl taint nodes node1 key1=value1:NoSchedule-

Label a node

kubectl label node node01 color=blue

Node affinity

Drain the node

kubectl drain --ignore-daemonsets node01

Bring the node back online

kubectl uncordon node01