What does the --selector option do in a kubectl get command?

Study for the Kubernetes Cloud Native Associate (KCNA) Certification. Prepare with flashcards and multiple choice questions. Ensure success with detailed explanations. Ready for your exam!

Multiple Choice

What does the --selector option do in a kubectl get command?

Explanation:
Label selectors filter the resources you list by their labels. When you use the --selector option with kubectl get, Kubernetes only returns resources whose label expressions match what you provide. For example, kubectl get pods -l app=frontend will show only pods labeled with app=frontend, and you can combine multiple requirements like -l app=frontend,env=prod. The -l shorthand works the same as --selector. This filtering is about labels, not about YAML output or field-based filtering (which uses --field-selector).

Label selectors filter the resources you list by their labels. When you use the --selector option with kubectl get, Kubernetes only returns resources whose label expressions match what you provide. For example, kubectl get pods -l app=frontend will show only pods labeled with app=frontend, and you can combine multiple requirements like -l app=frontend,env=prod. The -l shorthand works the same as --selector. This filtering is about labels, not about YAML output or field-based filtering (which uses --field-selector).

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy