Kubernetes kubectl convert 命令详解

kubectl convert

转换配置文件为不同的API版本,支持YAML和JSON格式。

该命令将配置文件名,目录或URL作为输入,并将其转换为指定的版本格式,如果目标版本未指定或不支持,则转换为最新版本。

默认输出将以YAML格式打印出来,可以使用- o选项改变输出格式。

语法

$ convert -f FILENAME

示例

将“pod.yaml”转换为最新版本并打印到stdout。

kubectl convert -f pod.yaml

将“pod.yaml”指定的资源的实时状态转换为最新版本#,并以json格式打印到stdout。

kubectl convert -f pod.yaml --local -o json

将当前目录下的所有文件转换为最新版本,并将其全部创建。

kubectl convert -f . | kubectl create -f -

Flags

Name Shorthand Default Usage
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.
filename f [] Filename, directory, or URL to files to need to get converted.
include-extended-apis true If true, include definitions of new APIs via calls to the API server. [default true]
local true If true, convert will NOT try to contact api-server but run locally.
no-headers false When using the default or custom-column output format, don't print headers (default print headers).
output o Output format. One of: json|yaml|wide|name|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See custom columns [http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns], golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://kubernetes.io/docs/user-guide/jsonpath].
output-version Output the formatted object with the given group version (for ex: 'extensions/v1beta1').)
recursive R false Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
schema-cache-dir ~/.kube/schema If non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema'
show-all a false When printing, show all resources (default hide terminated pods.)
show-labels false When printing, show all labels as the last column (default hide labels column)
sort-by If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. '{.metadata.name}'). The field in the API resource specified by this JSONPath expression must be an integer or a string.
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