Kubernetes - How to know latest supported API version

10/8/2018

Is there a table that will tell me which set of API versions I should be using, given a k8s cluster version? Kubernetes docs always assume I always have a nice, up-to-date cluster (1.12 at time of writing) but platform providers don't always live on this bleeding edge so it can get frustrating quite quickly.

Better yet, is there a kubectl command I can run that will let me cluster tell me each resource type and its latest supported API version?

-- s g
kubectl
kubernetes

5 Answers

5/8/2020

You can use a tool - kubepug as a pre-upgrade check to find out what changed in a given Kubernetes version if you were to upgrade your cluster to that version. Link - https://github.com/rikatz/kubepug

-- randhir singh
Source: StackOverflow

2/9/2020

For kubernetes-1.17.x (different format from what posted above)

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

will show api for each kind

-- Yossi Schwartz
Source: StackOverflow

10/9/2018

For getting a list of all the resource types and their associated version, run the following:

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

It should produce output like

KIND:     Binding
VERSION:  v1
KIND:     ComponentStatus
VERSION:  v1
KIND:     ConfigMap
VERSION:  v1
KIND:     Endpoints
VERSION:  v1
KIND:     Event
VERSION:  v1
...

As @Rico mentioned, they key is in the kubectl explain command. This may be a little fragile since it depends on the format of the printed output, but it works for kubernetes 1.9.6

Also, the information can be gathered in a less efficient way from the kubernetes API docs (with links for each version) found here - https://kubernetes.io/docs/reference/#api-reference

-- s g
Source: StackOverflow

8/30/2019

I think kubectl api-versions is a simpler alternative:

 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
-- Chandana De Silva
Source: StackOverflow

10/9/2018

That would be the kubectl explain <resource> command. For example for pods:

$ 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

...

Similarly for deployments:

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

Also, here's the v1.12 API reference for example.

-- Rico
Source: StackOverflow