Skip to main content
In this lesson we cover how to use kubectl explain to discover Kubernetes resource kinds and their fields directly from your terminal. kubectl explain reads the Kubernetes API schema (OpenAPI) exposed to kubectl and prints documentation for resource kinds and their fields — a fast way to confirm exact field names, types, and API versions when authoring manifests. Why use kubectl explain?
  • Quick, terminal-first lookup without opening external docs.
  • Confirms resource name, API group/version, and field types.
  • Helpful for validating YAML manifests and discovering nested fields for complex resources.

Quick command reference


1) Discover resource kinds

If you need to list available resources, short names, and their API versions, run:
Sample output:
Tip: If a CRD (CustomResourceDefinition) is installed in the cluster, it will also appear in kubectl api-resources with its API group/version.

2) Inspect top-level fields for a resource

After identifying the resource name, run kubectl explain <resource> to view the top-level fields exposed by the API for that resource. Example for pods:
Example output (top-level fields for a Pod):

3) Inspect nested fields (dot notation)

To drill into nested fields, append the field path using dot notation:
Example output (some spec fields):
Use dot notation to traverse as deep as you need, for example: kubectl explain deployment.spec.template.spec.containers.

4) Expand every field recursively

To see a comprehensive listing of all nested fields (helpful when authoring a complete manifest), use:
This expands all nested fields and shows their types. Example (truncated):

kubectl explain consults the API schema available to your kubectl (usually the cluster’s OpenAPI schema). If you are offline or not connected to a cluster, the results may not reflect server-side CRDs or custom API versions.

Field types and YAML mapping

Understanding the type labels in kubectl explain helps construct correct YAML values.

Practical tips

  • Use kubectl api-resources to find the canonical resource name and shortnames.
  • Use kubectl explain <resource> for top-level fields and kubectl explain <resource>.<field> to inspect nested fields.
  • Use --recursive to export full schemas when building manifests from scratch.
  • The field types you see (e.g., <string>, <integer>, <boolean>, <ObjectMeta>) guide how to format values in YAML.
  • If a field appears optional, check the resource’s CRD or API documentation for server-side defaults or validation.

Watch Video

Practice Lab