This is the documentation for version 0.39. For documentation on the latest version of kpt, please see


Format configuration files

Format formats the field ordering in YAML configuration files.

Inputs may be directories, files or STDIN. Formatted resources must include both apiVersion and kind fields.

  • Stdin inputs are formatted and written to stdout
  • File inputs (args) are formatted and written back to the file
  • Directory inputs (args) are walked, each encountered .yaml and .yml file acts as an input

For inputs which contain multiple yaml documents separated by \n—\n, each document will be formatted and written back to the file in the original order.

Field ordering roughly follows the ordering defined in the source Kubernetes resource definitions (i.e. go structures), falling back on lexicographical sorting for unrecognized fields.

Unordered list item ordering is defined for specific Resource types and field paths.

  • .spec.template.spec.containers (by element name)
  • .webhooks.rules.operations (by element value)


# format file1.yaml and file2.yml
kpt cfg fmt file1.yaml file2.yml
# format all *.yaml and *.yml recursively traversing directories
kpt cfg fmt my-dir/
# format kubectl output
kubectl get -o yaml deployments | kpt cfg fmt
# format kustomize output
kustomize build | kpt cfg fmt


kpt cfg fmt [DIR]

  Path to a package directory.  Reads from STDIN if not provided.

  if true, keep index and filename annotations set on Resources.

  if true, override existing filepath annotations.

--pattern string
  pattern to use for generating filenames for resources -- may contain the following
  formatting substitution verbs {'%n': '', '%s': 'metadata.namespace', '%k': 'kind'}
  (default "%n_%k.yaml")

--recurse-subpackages, -R
  formats resource files recursively in all the nested subpackages

  if true, set default filenames on Resources without them

  if true, uses openapi resource schema to format resources.

Last modified September 10, 2020: docs: Guides For Composite Packages (7716e112)