Custom node condition in Kubernetes

Sun 30 August 2020 by admin

When you go through node object in k8s you can see that there is a field called Conditions:

$ kubectl describe node kind-control-plane
...
Conditions:
  Type              Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----              ------  -----------------                 ------------------                ------                       -------
  MemoryPressure    False   Sun, 30 Aug 2020 10:54:31 +0200   Sun, 30 Aug 2020 10:53:23 +0200   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure      False   Sun, 30 Aug 2020 10:54:31 +0200   Sun, 30 Aug 2020 10:53:23 +0200   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure       False   Sun, 30 Aug 2020 10:54:31 +0200   Sun, 30 Aug 2020 10:53:23 +0200   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready             True    Sun, 30 Aug 2020 10:54:31 +0200   Sun, 30 Aug 2020 10:54:31 +0200   KubeletReady                 kubelet is posting ready status
  ...

builtin conditions are described in NodeConditionType. Kubelet is responsible for setting Ready condition, then kube-controller-manager is watching for changes, when kubelet/node is not ready ie. starts to reschedule pods on another node. We can create our own custom condition main.go. Of course setting this condition doesn't trigger any action on kubernetes side, but gives us better view what is happing with node using standard tools (ie. kubectl) or with automated way by using ie. kube-state-metrics as kube_node_status_condition.


Comments