kubectl convert
kubectl convert
command updates the apiVersion
in resource yaml or json file to latest or provided version.
kubectl convert -f nginx.yaml --output-version apps/v1
This command is not present with the default installation of kubectl
. It has to be installed separately.
Installation
- Download
kubectl-convert
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert"
- Install the command
install -o <user> -g <group> -m 0755 kubectl-convert /home/<user>/bin/kubectl-convert
- Verify
➤ kubectl convert -h
Convert config files between different API versions. Both YAML and JSON formats are accepted.
...
Usage:
convert -f FILENAME
Examples:
# Convert 'pod.yaml' to latest version and print to stdout.
kubectl convert -f pod.yaml
# Convert the live state of the resource specified by 'pod.yaml' to the latest version
# and print to stdout in JSON format.
kubectl convert -f pod.yaml --local -o json
# Convert all files under current directory to latest version and create them all.
kubectl convert -f . | kubectl create -f -
...