James's Ramblings

kubectl

Created: December 31, 2024

Quickly create YAML template for a resource

kubectl create KIND NAME --dry-run=client -oyaml
  • KIND: The type of resource to create (e.g. deployment or service).

    • This doesn’t work for all resources, (e.g. pod).
  • NAME: The name of the resource.

kubectl explain can be used to get more information about the resource and its fields. Examples:

# Get the documentation of the resource and its fields
kubectl explain pods

# Get all the fields in the resource
kubectl explain pods --recursive

# Get the explanation for deployment in supported api versions
kubectl explain deployments --api-version=apps/v1

# Get the documentation of a specific field of a resource
kubectl explain pods.spec.containers

# Get the documentation of resources in different format
kubectl explain deployment --output=plaintext-openapiv2