I have multiple questions for getting taint information.I know Taint info can be taken from here: (View existing taints on which Taints exist on current nodes.)
kubectl get nodes -o='custom columns=NodeName:.metadata.name,TaintKey:.spec.taints[].key,TaintValue:.spec.taints[].value,TaintEffect:.spec.taints[*].effect'
Above is as per documentation given in this link, but where is this being referenced from ? Where is this listed?
https://kubernetes.io/docs/reference/kubectl/cheatsheet/but how do I find that taint is under Spec. As per kubectl commands, "Taint" value only comes under "kubectl describe node" and not "kubectl get node -o yaml".
I can only find this documentation : (nothing here.)
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#nodespec-v1-corehow do I find out(proof) that spec contains "taints", either some documentation , or some "--help" style documentation , or output for "-o yaml ", or output for "-o json"?
I have tried using kubectl "get" and "describe".I have also tried understanding YAML structure, but it is not listed there, or I might be missing something.
CodePudding user response:
A good way to understand the structure of Kubernetes' Resources is through the one-page Kubernetes API Reference
- Find the Node Resource
- Then per your example, look under
specwhich is typeNodeSpec - See that
taintsis an array ofTaint
Then, knowing that you can kubectl get {resource} --output various flavors (I prefer jsonpath), you can use e.g. the JSONPath implementation used by Kubernetes (not the same as JSONPath elsewhere) to filter the output.
If the JSONPath filtering is insufficient, you can pipe the results into other tools e.g. jq.
If you'd prefer to use YAML, you'll want to --output=yaml but kubectl includes no built-in processing of YAML output and so you'll want to use a tool like yq.
You can also add --v (log level verbosity) to any kubectl command. --v=6 (or above) should include the underlying Kubernetes API calls being made to effect the command.
CodePudding user response:
I will start by answering your second bullet point,
- The values of
taintsare visible in both the described output and get YAML output.
FYI, in the describe output, it will show the field as
Taintsand in the yamls, it shows astaints
. To see that, run the following commands :
# This is the YAML of node
kubectl get node <node-name> -oyaml > node-get-output.yaml
# This is the describe output of node
kubectl describe node <node-name> > node-describe-output.yaml
Now, In the output of get, you will notice: (pasting a demo YAML)
spec:
podCIDR: ....
podCIDRs:
- ...
providerID: gce://.../us-central1-f/...
taints:
- effect: NoSchedule
key: demo
value: StackOverflow
And the describe output will look something like this:
Name: ...
Roles: ...
Labels: beta.kubernetes.io/arch=amd64
Annotations: container.googleapis.com/instance_id: ...
CreationTimestamp: ...
Taints: demo=StackOverflow:NoSchedule
Unschedulable: false
- It is a concept of the kubernetes that for every Kubernetes object all the configuration stuff will go under
specsection of the YAML, you can refer the documentation as well, taints also comes under it. You can also see it using the kubectl utility, its output contains all the attributes which comes underspec:
kubectl explain node.spec
