Kubectl get field-selector Support: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
* https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#get
=Internal=
=Internal=
* [[Kubectl#--fieldSelector|kubectl]]
* [[Kubectl#--fieldSelector|kubectl]]


=Overview=
=Overview=


<syntaxhighlight lang='bash'>
kubectl get ... --field-selector <expression>
</syntaxhighlight>


field-selector Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The server only supports a limited number of field queries per type.
<code>--field-selector</code> specifies a selector (field query) to filter the result on. It supports the expressions containing '=', '==', and '!=', which can be applied to multiple fields.
 


<syntaxhighlight lang='bash'>
--field-selector key1=value1,key2=value2,key3!=value3
</syntaxhighlight>


The server only supports a limited number of field queries per each resource type. Supported fields vary per type. For example, attempting to query a PV for <code>spec.claimRef.name</code> fails with:
<syntaxhighlight lang='text'>
Error from server (BadRequest): Unable to find "/v1, Resource=persistentvolumes" that match label selector "", field selector "spec.claimRef.name=something": "spec.claimRef.name" is not a known field selector: only "metadata.name", "metadata.namespace"
</syntaxhighlight>


Note that you may be able to obtain the results expected from a field selector by using JSONPath filter expressions. For more details, see: {{Internal|Kubectl_get_JSONPath_Support#Filter_Expressions|kubectl get JSONPath Filter Expressions}}


=Supported Fields for Field Selectors=
* PVs: <code>metadata.name</code>, <code>metadata.namespace</code>.


=Usage Examples=


<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=<node>
kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=<node>
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 18:21, 17 May 2021

External

Internal

Overview

kubectl get ... --field-selector <expression>

--field-selector specifies a selector (field query) to filter the result on. It supports the expressions containing '=', '==', and '!=', which can be applied to multiple fields.

--field-selector key1=value1,key2=value2,key3!=value3

The server only supports a limited number of field queries per each resource type. Supported fields vary per type. For example, attempting to query a PV for spec.claimRef.name fails with:

Error from server (BadRequest): Unable to find "/v1, Resource=persistentvolumes" that match label selector "", field selector "spec.claimRef.name=something": "spec.claimRef.name" is not a known field selector: only "metadata.name", "metadata.namespace"

Note that you may be able to obtain the results expected from a field selector by using JSONPath filter expressions. For more details, see:

kubectl get JSONPath Filter Expressions

Supported Fields for Field Selectors

  • PVs: metadata.name, metadata.namespace.

Usage Examples

kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=<node>