Question 33
Domain 3: Services & NetworkingWhich kubectl command lists Services in the default namespace sorted by name?
Correct answer: A
Explanation
`kubectl get services` lists Service objects, and `-n default` targets the default namespace. The `--sort-by=.metadata.name` flag sorts the output by each object’s metadata name, so this command returns Services in the default namespace ordered by name.
Why each option is right or wrong
A. kubectl get services -n default --sort-by=.metadata.name
`kubectl get` accepts a resource type plus namespace scoping with `-n`/`--namespace`, so `-n default` restricts the query to the default namespace rather than all namespaces. The `--sort-by` flag takes a JSONPath expression; `.metadata.name` is the object field used for alphabetical ordering, so the resulting Service list is sorted by each Service’s name value.
B. kubectl get services --all-namespaces --sort-by=.spec.name
C. kubectl describe services -n default --sort-by=.metadata.name
D. kubectl get service default --sort-by=.metadata.name