Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.
Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.
kubectl-slice: split Kubernetes YAMLs into fileskubectl-slice is a tool that allows you to split a single multi-YAML Kubernetes manifest (with --input-file or -f), or a folder containing multiple manifests files (with --input-folder or -d, optionally with --recursive), into multiple subfiles using a naming convention you choose. This is done by parsing the YAML code and allowing you to access any key from the YAML object using Go Templates.
By default, kubectl-slice will split your files into multiple subfiles following this naming convention that you can configure to your liking:
{{.kind | lower}}-{{.metadata.name}}.yamlThat is, the Kubernetes kind -- in this case, the value Namespace -- lowercased, followed by a dash, followed by the resource name -- in this case, the value production:
namespace-production.yamlIf your YAML includes multiple files, for example:
apiVersion: v1
kind: Pod
metadata:
name: nginx-ingress
---
apiVersion: v1
kind: Namespace
metadata:
name: productionThen the following files will be created:
$ kubectl-slice --input-file=input.yaml --output-dir=.
Wrote pod-nginx-ingress.yaml -- 58 bytes.
Wrote namespace-production.yaml -- 61 bytes.
2 files generated.You can customize the file name to your liking, by using the --template flag.
kubectl-slice can be used as a standalone tool or through kubectl, as a plugin.
krewkubectl-slice is available as a krew plugin.
To install, use the following command:
kubectl krew install slicekubectl-slice is available as a Homebrew tap for both macOS and Linux:
brew install patrickdappollonio/tap/kubectl-sliceDownload the latest release for your platform from the Releases page, then extract and move the kubectl-slice binary to any place in your $PATH. If you have kubectl installed, you can use both kubectl-slice and kubectl slice (note in the later the absence of the -).
…kubectl-slice?See why kubectl-slice? for more information.
kubectl-sliceBesides command-line flags, you can also use environment variables and a YAML configuration file to pass options to kubectl-slice. See the documentation for configuration options for details about both, including precedence.
Including or excluding manifests from the output via metadata.name or kind is possible. Globs are supported in both cases. See the documentation for including and excluding items for more information.
See examples for more information.
Pull requests are welcomed! So far, looking for help with the following items, which are also part of the roadmap:
brewenhancementNo open issues yet, or sync has not completed.