What would you like to be added?
Add a command that prints the container names defined in a Pod:
$ kubectl containers checkout-7b9884d7cf-4tz9k
checkout
istio-proxy
The initial implementation should:
- Accept one Pod name and standard namespace/context flags.
- Print one name per line.
- Include regular, init, and ephemeral containers.
- Preserve their order in the Pod spec.
- Avoid additional columns or output formats.
Why is this needed?
Commands such as logs, exec, and attach accept -c/--container, but kubectl has no direct way to discover its possible values.
Default-container selection does not help when targeting a specific sidecar:
$ kubectl containers checkout-7b9884d7cf-4tz9k
checkout
istio-proxy
$ kubectl logs checkout-7b9884d7cf-4tz9k -c istio-proxy
Currently, users must inspect kubectl describe, write a JSONPath expression, rely on shell completion, or intentionally provide an invalid container name.
Alternatives considered
Shell completion and improved error messages are useful, but they are not explicit discovery operations and are unsuitable for some environments and scripts. Adding --list-containers separately to logs, exec, and attach would duplicate the same functionality across commands.
Related: kubectl#1768, kubernetes#136973, KEP-2227.
What would you like to be added?
Add a command that prints the container names defined in a Pod:
The initial implementation should:
Why is this needed?
Commands such as
logs,exec, andattachaccept-c/--container, but kubectl has no direct way to discover its possible values.Default-container selection does not help when targeting a specific sidecar:
Currently, users must inspect
kubectl describe, write a JSONPath expression, rely on shell completion, or intentionally provide an invalid container name.Alternatives considered
Shell completion and improved error messages are useful, but they are not explicit discovery operations and are unsuitable for some environments and scripts. Adding
--list-containersseparately tologs,exec, andattachwould duplicate the same functionality across commands.Related: kubectl#1768, kubernetes#136973, KEP-2227.