Kubernetes - How to know latest supported API version
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
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.
For getting a list of all the resource types and their latest supported 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