Kubernetes and Cloud Native Associate (KCNA)Kubernetes FundamentalsEasy
A platform engineer wants to understand the current state of all Pods across a Kubernetes cluster, including their status, IP addresses, and the node they are running on. Which `kubectl` command, when executed without additional arguments, provides a concise summary of these details for all Pods?
- A`kubectl exec --all-pods`
- B`kubectl describe pods`
- C`kubectl get pods`
- D`kubectl logs --all-namespaces`
Show answer & explanationAnswer & explanation
Correct answer: C. `kubectl get pods`
The `kubectl get pods` command is used to list Pods and provides a concise overview including their name, ready status, current status, restarts, and age, which helps in quickly understanding their state.
Why the other options are wrong
- A. `kubectl exec` is for running commands inside containers, and `--all-pods` is not a valid argument for it.
- B. `kubectl describe pods` provides very detailed information for each Pod, which is not a 'concise summary'.
- D. `kubectl logs` is for retrieving logs from containers, not for listing Pod status.
`kubectl get` command
A fundamental `kubectl` command used to retrieve and display information about Kubernetes resources.
- Provides a quick, tabular summary by default.
- Can be used with various resource types (pods, services, deployments, nodes, etc.).
- Supports output formats like YAML, JSON, and wide (`-o wide`) for more details.
Memory trick: To 'get' a quick 'list', use `kubectl get` to 'see' everything.