Full lesson
Explore the full explanation, examples, and visuals at your own pace.
kubectl explain: field docs straight from your cluster
Kubernetes has a built-in manual. Most people never open it. It's the command kubectl explain, and kubectl is the Kubernetes command-line tool.
Five tabs vs one command
You're editing a Deployment and need the fields under strategy. So you open five tabs of docs and forum answers, and you're still unsure which match your version. On the other side, one terminal command, kubectl explain deployment.spec.strategy, reads the answer from your running cluster.
Terminal: ask about one field
Here's the command, and here's what comes back. First, a description of strategy, how Deployments replace old pods with new ones. Then its child fields, type and rollingUpdate. This comes from your cluster's own schema, so it matches your running version. Layout can vary slightly between kubectl versions.
$ kubectl explain deployment.spec.strategy
KIND: Deployment
VERSION: apps/v1
FIELD: strategy <DeploymentStrategy>
DESCRIPTION:
The deployment strategy to use to replace
existing pods with new ones.
FIELDS:
rollingUpdate <RollingUpdateDeployment>
type <string>
"Recreate" or "RollingUpdate". Default RollingUpdate.Drill deeper with a dotted path
A dotted path is just resource, field, subfield, the same nesting you write in YAML. Add .rollingUpdate to the path and you land on maxSurge and maxUnavailable. Want the whole tree at once? Add --recursive. And this works the same way for any resource.
$ kubectl explain deployment.spec.strategy.rollingUpdate
FIELDS:
maxSurge <IntOrString>
maxUnavailable <IntOrString>
# see the whole tree at once
$ kubectl explain deployment.spec --recursiveStop searching. Ask your cluster.
Your cluster already publishes its own field documentation. Next time you're unsure about a field, run kubectl explain before opening a tab. Stop searching. Ask your cluster.
