How to use kubectl explain to view Kubernetes resource kinds, field types, nested fields, and API versions from the terminal with examples and command tips
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.
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:
kubectl explain pods
Example output (top-level fields for a Pod):
$ kubectl explain podsKIND: PodVERSION: v1FIELDS: apiVersion <string> APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and kind <string> Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits. metadata <ObjectMeta> Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata spec <PodSpec> Specification of the desired behavior of the pod. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status status <PodStatus> Most recently observed status of the pod. This data may not be up to date.
To drill into nested fields, append the field path using dot notation:
kubectl explain pods.spec
Example output (some spec fields):
$ kubectl explain pods.specKIND: PodVERSION: v1FIELD: spec <PodSpec>DESCRIPTION: Specification of the desired behavior of the pod. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status PodSpec is a description of a pod.FIELDS: activeDeadlineSeconds <integer> Optional duration in seconds the pod may be active on the node relative to StartTime before the system will actively try to mark it failed and kill associated containers. Value must be a positive integer. affinity <Affinity> If specified, the pod's scheduling constraints. automountServiceAccountToken <boolean> AutomountServiceAccountToken indicates whether a service account token should be automatically mounted.
Use dot notation to traverse as deep as you need, for example: kubectl explain deployment.spec.template.spec.containers.
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.