LinuxCommandLibrary

kubectl-explain

Describe Kubernetes API resource fields

TLDR

Show documentation for a resource

$ kubectl explain [pods|nodes|deployments|...]
copy

Show documentation for a sub-resource or field of an object
$ kubectl explain [pod.spec.containers]
copy

Show documentation for a specific versioned resource
$ kubectl explain [ingress.v1.networking.k8s.io]
copy

Show all fields recursively for a resource
$ kubectl explain [[po|pods]] --recursive
copy

Display help
$ kubectl explain --help
copy

SYNOPSIS

kubectl explain <RESOURCE> [<FIELD_PATH>...] [--recursive] [--subresource=<name>] [--raw]

PARAMETERS

--recursive, -R
    Recursively print fields of fields

--raw
    Print the raw OpenAPI schema in JSON format

--subresource=<name>
    Print fields of a subresource (e.g., status, scale)

-f, --filename=<file>
    Identify resource from filename, directory, or URL

--api-version=<version>
    Specify API version (deprecated)

DESCRIPTION

kubectl explain provides detailed documentation for Kubernetes API resources and their fields directly from the cluster's schema. It outputs human-readable descriptions, types, required status, and validation rules for specified resources like pods, deployments, or services.

Usage is straightforward: specify a resource type (e.g., pod) or drill down into nested fields (e.g., pod.spec.containers). This tool is invaluable for developers and operators learning Kubernetes manifests, troubleshooting YAML errors, or exploring API changes without external docs.

It fetches the OpenAPI schema from the API server, ensuring accuracy to the cluster version. Supports recursive expansion for deep hierarchies and raw JSON output for scripting. Ideal during interactive sessions or CI/CD validation.

CAVEATS

Outputs cluster-specific schema; requires read access to API server. No offline mode. Field paths are case-sensitive.

EXAMPLES

Basic: kubectl explain pod
Nested: kubectl explain pod.spec.containers.resources
Recursive: kubectl explain pod.spec --recursive
Raw: kubectl explain deployment.spec --raw

OUTPUT FIELDS

Each field shows: KIND, VERSION, DESCRIPTION, TYPE, REQUIRED, and validation details.

HISTORY

Introduced in Kubernetes v1.3 (2016). Enhanced in v1.14+ with raw schema support and better recursion.

SEE ALSO

Copied to clipboard