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

Prepare for the KCNA Certification Test. Study with flashcards, multiple-choice questions, and detailed explanations to enhance your understanding of Kubernetes Cloud Native concepts. Ace your 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