Skip to content

Add kubectl containers POD to list container names #1873

Description

@santiagobarrazas

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions