Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert apiVersion of Kubernetes objects?

Tags:

kubernetes

As kubectl convert is deprecated since v1.14 and will be removed in v1.17, how do you convert Kubernetes object's API versions?

Are there other easy and safe solutions for doing that?

like image 599
Ivan Aracki Avatar asked Nov 14 '25 17:11

Ivan Aracki


2 Answers

This is being discussed in https://github.com/kubernetes/kubectl/issues/725. At the moment there is no alternative for this command.

The plan was to remove it on 1.17 but I have 1.18 running and the command is still working.

I would say that for now you don't need to worry about alternatives as it still works.

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-04-16T11:56:40Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-04-16T11:48:36Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
$ kubectl convert --help
Convert config files between different API versions. Both YAML and JSON formats are accepted.

 The command takes filename, directory, or URL as input, and convert it into format of version specified by
--output-version flag. If target version is not specified or not supported, convert to latest version.

 The default output will be printed to stdout in YAML format. One can use -o option to change to output destination.

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 -

Options:
      --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in
the template. Only applies to golang and jsonpath output formats.
  -f, --filename=[]: Filename, directory, or URL to files to need to get converted.
  -k, --kustomize='': Process the kustomization directory. This flag can't be used together with -f or -R.
      --local=true: If true, convert will NOT try to contact api-server but run locally.
  -o, --output='yaml': Output format. One of:
json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
      --output-version='': Output the formatted object with the given group version (for ex: 'extensions/v1beta1').
  -R, --recursive=false: Process the directory used in -f, --filename recursively. Useful when you want to manage
related manifests organized within the same directory.
      --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The
template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
      --validate=true: If true, use a schema to validate the input before sending it

Usage:
  kubectl convert -f FILENAME [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).
like image 74
Mark Watney Avatar answered Nov 17 '25 08:11

Mark Watney


kubectl apply -f pod.yaml --dry-run=client -o json
like image 31
Rakesh Avatar answered Nov 17 '25 09:11

Rakesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!