kubernetes - 如何转换 Kubernetes 对象的 apiVersion?

标签 kubernetes

由于 kubectl convert 自 v1.14 起已弃用,并将在 v1.17 中删除,您如何转换 Kubernetes 对象的 API 版本?

还有其他简单安全的解决方案吗?

最佳答案

这正在 https://github.com/kubernetes/kubectl/issues/725 中讨论.目前此命令没有其他选择。

计划是在 1.17 上删除它,但我正在运行 1.18,并且该命令仍在运行。

我要说的是,目前您无需担心替代方案,因为它仍然有效。

$ 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).

关于kubernetes - 如何转换 Kubernetes 对象的 apiVersion?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62283277/

相关文章:

kubernetes - 让领事和注册人在Kubernetes中工作

amazon-web-services - EKS 工作程序节点未准备好且 ECR 无法访问

kubernetes - 在 kubernetes 上持续部署有状态的 apache flink 应用程序

kubernetes - 容器化Kubernetes主流程的优势

nginx - Kubernetes 在哪里拉取镜像以及我如何浏览它们/更改它们的拉取源?

nginx - 使用Skydns的Kubernetes的Nginx解析器

Kubernetes 水平 Pod 自动缩放器 (HPA) 测试

kubernetes - 如何将 GKE 连接到 AWS RDS 实例?

kubernetes - 运算符(operator)获取部署配置的最佳实践

kubernetes - 如何在 Kubernetes 上使用 WebRTC 和 RTCPeerConnection?