Manifest HPA file Api version is automatically changed to autoscaling/v1, is this expected?

Viewed 392

We recently started upgrading our EKS clusters from 1.18 version to 1.19. One change that we did was to change our HPA manifest files to have apiVersion as autoscaling/v2beta2. I can see all three api versions are available in my cluster

kubectl api-versions | grep autoscaling
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2

once the HPA file is applied autoscaling/v2beta2 is changed to autoscaling/v1. In the annotation block, I see the last applied changes showing, apiversion as autoscaling/v2beta2. Autoscaling is working fine and I don't see any errors in events. I am getting edgy to see the apiversion getting changed automatically and don't see any document explaining why is this happening and if this is expected behavior. Any inputs or explanation of this will be appreciated

2 Answers

This command show which versions are supported by your cluster

kubectl api-versions | grep autoscaling
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2

however, we mainly focus on which ApiVersion is getting stored in etcd database.

Based on my understanding, there could be chances kubectl get the resource using one ApiVersion: autoscaling/v1 but you have created the resource with autoscaling/v1 in that case if you are getting your resource using kubectl CLI, it will show the change in API version.

kubectl get uses the server prefer API version, you can check it out using :

kubectl explain hpa

KIND:     HorizontalPodAutoscaler
VERSION:  autoscaling/v1

The differences between API versions are things like default values and field names. Because API versions are round-trippable, you can safely get the same deployment object with different API version endpoints.

This is working as intended. v1 is the default version of HPA so that's what you get if you don't request a specific version. You can get autoscaling/v2beta1 representation of your HPA by running kubectl get hpa.v2beta1.autoscaling -o yaml hpa-demo

A bit of explanaition: Internally all HPA objects are stored in the same way, regardless which version of API you used to create them. When you get HPA Kubernetes API server converts this internal representation to the version you requested.

https://github.com/kubernetes/kubernetes/issues/71556#issuecomment-442854276

Related