Kubernetes-如何知道最新支持的API版本

时间:2018-10-08 23:25:54

标签: kubernetes kubectl

如果有k8s集群版本,是否有一张表可以告诉我应该使用哪一组API版本? Kubernetes文档始终假设我始终拥有一个不错的,最新的集群(在撰写本文时为1.12),但是平台提供商并不总是生活在这个前沿,因此它可能很快就令人沮丧。

更好的是,有没有我可以运行的kubectl命令,可以让我通过集群告诉我每种资源类型及其最新支持的API版本?

6 个答案:

答案 0 :(得分:4)

这将是kubectl explain <resource>命令。例如,吊舱:

$ kubectl explain pod
KIND:     Pod
VERSION:  v1   <==  API version

DESCRIPTION:
     Pod is a collection of containers that can run on a host. This resource is
     created by clients and scheduled onto hosts.

FIELDS:
   apiVersion   <string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#resources

...

类似地用于部署:

$ kubectl explain deploy
KIND:     Deployment
VERSION:  extensions/v1beta1 <== API Version

DESCRIPTION:
     DEPRECATED - This group version of Deployment is deprecated by
     apps/v1beta2/Deployment. See the release notes for more information.
     Deployment enables declarative updates for Pods and ReplicaSets.

FIELDS:
   apiVersion   <string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
...

此外,例如,这里是v1.12 API reference

答案 1 :(得分:4)

我认为kubectl api-versions是一个更简单的选择:

 kubectl api-versions
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
apps/v1beta1
apps/v1beta2
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
coordination.k8s.io/v1
coordination.k8s.io/v1beta1
events.k8s.io/v1beta1
extensions/v1beta1
networking.k8s.io/v1
networking.k8s.io/v1beta1
node.k8s.io/v1beta1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
scheduling.k8s.io/v1
scheduling.k8s.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1

答案 2 :(得分:3)

要获取所有资源类型及其关联版本的列表,请运行以下命令:

for kind in `kubectl api-resources | tail +2 | awk '{ print $1 }'`; do kubectl explain $kind; done | grep -e "KIND:" -e "VERSION:"

它应该产生类似

的输出
KIND:     Binding
VERSION:  v1
KIND:     ComponentStatus
VERSION:  v1
KIND:     ConfigMap
VERSION:  v1
KIND:     Endpoints
VERSION:  v1
KIND:     Event
VERSION:  v1
...

如@Rico所述,它们的键位于kubectl explain命令中。这可能有点脆弱,因为它取决于打印输出的格式,但是它适用于kubernetes 1.9.6

此外,可以从此处找到的Kubernetes API文档(每个版本都有链接)中以较低效率的方式收集信息-https://kubernetes.io/docs/reference/#api-reference

答案 3 :(得分:1)

对于kubernetes-1.17.x(与上面发布的格式不同)

for i in `kubectl api-resources | grep -v KIND | awk '{print $NF}'`;do kubectl explain ${i} | grep -e "KIND:" -e "VERSION:"; echo '----'; done

将显示每种类型的api

答案 4 :(得分:0)

如果要将集群升级到该版本,则可以使用工具kubepug作为升级前检查来找出给定Kubernetes版本中的更改。链接-https://github.com/rikatz/kubepug

答案 5 :(得分:0)

您可以在上下文中对 Kubernetes 集群使用 Move2Kube 并执行 Theta(n log(log(n))) 以获得集群支持的所有种类版本。它以从最新到最旧的顺序给出了一个种类支持的所有版本的有序列表。

它将为您提供以下信息:

move2kube collect