List Kubernetes resources by apiVersion
Asked Answered
K

3

7

Is there a easy way to list all kubernetes objects related to an API version? Lets say, API version apps/v1beta1 is getting deprecated and I want to know if I have any objects in my cluster using this version, how can I find such objects?

Kioto answered 7/5, 2020 at 16:55 Comment(0)
K
4

The reason I asked this question was that I was upgrading my kubernetes cluster from v1.15 to v1.16 and this brings a lot of breaking changes

The kubepug tool allowed me to easily find a list of resources that I need to change to be able to upgrade seamlessly from 1.15 to 1.16

Edit: Another alternative is pluto command line tool to get information about resources which might have deprecated or removed API versions. This is helpful specially if you use helm extensively since pluto can look at helm state.

Kioto answered 11/5, 2020 at 22:40 Comment(0)
O
4

you can do something similar like this

kubectl get pod -o=custom-columns=NAME:.metadata.name,API-version:.metadata.owner_references[].api_version

by using kubectl just print respective data and api version

Ovoid answered 8/5, 2020 at 5:26 Comment(4)
No, I'm not really looking for pods but any objects, for example, there could be deployments with multiple versions in the apiVersion field such as apps/v1beta1 or apps/v1beta2 so the query should catch other object types as well, not just pods.Kioto
yes but in that you can use kubectl command and filter json response as per need. instead of pod you can use deployment. however, if you are looking for a searching method you can use Kubernetes api and write custom code which check each and every object in cluster.Ovoid
Yep, thats what it looks like, there is no method at the moment which will allow me to talk to etcd and find how many objects of a particular APIVersion are present on my cluster.Kioto
I found this worked better kubectl get Ingress -A -o=custom-columns=NAME:.metadata.name,API-Version:.apiVersionTideland
K
4

The reason I asked this question was that I was upgrading my kubernetes cluster from v1.15 to v1.16 and this brings a lot of breaking changes

The kubepug tool allowed me to easily find a list of resources that I need to change to be able to upgrade seamlessly from 1.15 to 1.16

Edit: Another alternative is pluto command line tool to get information about resources which might have deprecated or removed API versions. This is helpful specially if you use helm extensively since pluto can look at helm state.

Kioto answered 11/5, 2020 at 22:40 Comment(0)
K
2

To list Kubernetes resource versions use this command:

kubectl api-resources

And if the you know what resource you are searching for then just filter it from the list using grep:

kubectl api-resources | grep the_resource_name_you_want

In the below example we search for the api version of 'persistentvolumes' resource:

kubectl api-resources | grep persistentvolumes

Result:

deployments     deploy    apps/v1     true         Deployment

There are additional options to get the resource version:

Use the official documentation:

The official and updated with the newest versions is in the Kubernetes API documentation

The left navigation bar lists the resources, click on one & the version is the first row of the page.

Karachi answered 26/1, 2022 at 13:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.