How to identify planned nodes in Kubernet

I want to (programmatically) get a list of all the planned nodes in my kubernetes cluster.

I am pretty sure that this was possible by looking .spec.unschedulableat the full output kubectl get nodes(using JSON or template output), but now it seems that this information is inside the key scheduler.alpha.kubernetes.io/taints, which is much more difficult to parse and just does not feel in the right place.

Is there any other way to find this information? Am I missing something? I am currently using version 1.5.1.

UPDATE: I can almost get there with some Go patterns:

$ kubectl get nodes -o go-template='{{range .items}}{{with $x := index .metadata.annotations "scheduler.alpha.kubernetes.io/taints"}}{{.}}{{end}}{{end}}'
[{"key":"dedicated","value":"master","effect":"NoSchedule"}]

But that leaves me with a JSON blob that I cannot parse in the template, and I still need to invert the results and get the name node.

UPDATE 2: Obviously, unplanned nodes must have .spec.unschedulable. This does not seem to be always the case; not sure if this is due to a mistake or misunderstanding on my part.

+5
source share
3 answers

Here is the working text / template that works now when spec.taints- GA:

{{/* scehdulable.gotmpl */}}
{{- range .items }}
  {{- $taints:="" }}
  {{- range .spec.taints }}
    {{- if eq .effect "NoSchedule" }}
      {{- $taints = print $taints .key "," }}
    {{- end }}
  {{- end }}
  {{- if not $taints }}
    {{- .metadata.name}}{{ "\n" }}
  {{- end }}
{{- end }}
kubectl get no -o go-template-file=./schedulable.gotmpl
kind-worker
kind-worker2

Compact version:

kubectl get no -o 'go-template={{range .items}}{{$taints:=""}}{{range .spec.taints}}{{if eq .effect "NoSchedule"}}{{$taints = print $taints .key ","}}{{end}}{{end}}{{if not $taints}}{{.metadata.name}}{{ "\n"}}{{end}}{{end}}'
+2
source

Despite being late at the party, I needed something similar today to determine when scheduling would be really successful:

kubectl get nodes -o jsonpath="{range .items[*]}{.metadata.name} {.spec.taints[?(@.effect=='NoSchedule')].effect}{\"\n\"}{end}" | awk 'NF==1 {print $0}'

this, in fact, is simply a more compact template than the one that the OP laid out with the inversion performed by filterung with awk.

: , , , . , , NoSchedule ( ), , awk ( , NF==1).

+2

unschedulable false, , true. .

+1

Source: https://habr.com/ru/post/1665016/


All Articles