kubectl-explain
Describe Kubernetes API resource fields
TLDR
Show documentation for a resource
Show documentation for a sub-resource or field of an object
Show documentation for a specific versioned resource
Show all fields recursively for a resource
Display help
SYNOPSIS
kubectl explain [RESOURCE.FIELD...] [options]
PARAMETERS
--api-version=group/version
Specify the API version to use for the resource. For example, use apps/v1 for Deployments if you need to explain a specific version.
--recursive
Prints the fields of a resource recursively. This option can generate very verbose output, listing all nested fields and their descriptions.
--output-sections=sections
Defines which sections to include in the output. Valid values are description, fields, properties, notes, examples, or all. Multiple sections can be specified separated by commas.
--help
Provides help information for the explain command.
DESCRIPTION
The kubectl explain command provides detailed documentation about Kubernetes resources directly from the terminal. It leverages the OpenAPI schema exposed by the Kubernetes API server to describe the structure, fields, and types of various API objects. Users can explore top-level resources like pod or deployment, or drill down into nested fields such as pod.spec.containers to understand specific attributes.
This command is invaluable for developers and operators constructing Kubernetes manifests, helping them create valid YAML configurations without constantly referring to external documentation. It ensures consistency with the currently running API server's version and capabilities, making it a reliable source of truth for your cluster's API definitions.
CAVEATS
Key limitations and considerations:
1. API Server Dependency: The command relies on the OpenAPI schema from the Kubernetes API server; it will not function if the API server is unreachable.
2. Version Specificity: The output reflects the specific Kubernetes version the API server is running, which might differ from your local kubectl client.
3. Nuance Misses: While comprehensive, it might not always highlight every nuance like deprecation warnings or immutability rules for fields as explicitly as official external documentation.
4. Verbose Output: The --recursive option can produce extremely large outputs for complex resources, potentially overwhelming the terminal.
SCHEMA SOURCE
The information provided by kubectl explain is fetched directly from the OpenAPI schema served by the Kubernetes API server. This ensures the documentation is always up-to-date with the specific version of Kubernetes you are interacting with, including any custom resource definitions (CRDs) you may have installed.
NAVIGATING THE SCHEMA
Users can navigate the schema by specifying dot-separated paths (e.g., pod.spec.containers.ports). This allows for targeted exploration of specific parts of an API object without needing to sift through the entire schema definition, making it highly efficient for pinpointing information.
HISTORY
The kubectl explain command was introduced early in the development of kubectl as a core utility to provide on-demand, accurate schema documentation. Its development has closely tracked the evolution of the Kubernetes API and the improvements in how the API server exposes its OpenAPI schema. Over time, it has become an indispensable tool for developers and operators, evolving with added features like --recursive and --output-sections to enhance its utility for navigating complex Kubernetes object definitions directly from the command line.
SEE ALSO
kubectl get(1), kubectl apply(1), kubectl describe(1), man kubectl


