What is the difference between the -l and --selector options in Kubernetes commands?

Study for the Kubernetes Cloud Native Associate (KCNA) Certification 1 Test. Master the core concepts of Kubernetes with multiple-choice questions and detailed explanations. Prepare and boost your confidence for the KCNA certification exam!

Multiple Choice

What is the difference between the -l and --selector options in Kubernetes commands?

Explanation:
Both options are used to filter resources by their labels. The short form (-l) is just a convenient alias for the long form (--selector). They behave the same way and can be used interchangeably. Label selectors filter based on the labels that are attached to Kubernetes objects, not by their names or by annotations. If you want to filter by field values (such as metadata.name or status), you’d use a different flag, typically --field-selector. Example: kubectl get pods -l app=nginx is equivalent to kubectl get pods --selector app=nginx. You can combine more complex expressions as well, like -l app in (frontend,backend) or -l environment=prod,tier=web, and so on.

Both options are used to filter resources by their labels. The short form (-l) is just a convenient alias for the long form (--selector). They behave the same way and can be used interchangeably.

Label selectors filter based on the labels that are attached to Kubernetes objects, not by their names or by annotations. If you want to filter by field values (such as metadata.name or status), you’d use a different flag, typically --field-selector.

Example: kubectl get pods -l app=nginx is equivalent to kubectl get pods --selector app=nginx. You can combine more complex expressions as well, like -l app in (frontend,backend) or -l environment=prod,tier=web, and so on.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy