Is there any pitfalls to use different pods with different autoscaler APIs in the same cluster

Viewed 75

We have the pods running with the Autoscaling/v2beta1 API. In order to leverage the custom metrics based HPA, we'd like to use Autoscaling/v2beta2 for some pods. As there are some other pods that are not rush to be upgraded, we would like to leave them with Autoscaling/v2beta1 in the yaml in the same cluster. I assume there should be no problem for this. Is there any pitfall when using it like this?

2 Answers

Yes, there won't be any issue but creating the different HPA on the same deployment or on for the same PODs might create the issue in judgment.

Otherwise using the different API versions of HPA will work if custom metrics requirements are there.

Generally Harsh Manvar has answered your question. I'll add more details and concerns.

Answer on your question: yes, you can use different HorizontalPodAutoscaler API versions in your yamls. However there is a big chance it will end up in inefficient support and higher chances of mistakes. I'd suggest moving everything to v2beta2 (also last point is about deprecation and removing v2beta1 in the future).

Next point is if for example by mistake you apply different HPAs to one deployment, they will work in parallel and will react in the same way (this is when targets for CPU were set identical). Please see example below. (However keep in mind that it's a simple example and if it has a lot of metrics, it may work unpredictably)

hpa.yaml

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: php-apache2
  namespace: default
spec:
  maxReplicas: 10
  metrics:
  - resource:
      name: cpu
      targetAverageUtilization: 50
    type: Resource
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: php-apache 
  namespace: default
spec:
  maxReplicas: 10
  metrics:
  - resource:
      name: cpu
      target:
        averageUtilization: 50
        type: Utilization  
    type: Resource
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache

Output by kubectl get hpa --watch:

NAME          REFERENCE               TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
php-apache    Deployment/php-apache   0%/50%    1         10        1          2m28s
php-apache2   Deployment/php-apache   0%/50%    1         10        1          2m28s
php-apache2   Deployment/php-apache   251%/50%   1         10        1          4m16s
php-apache    Deployment/php-apache   251%/50%   1         10        4          4m16s
php-apache2   Deployment/php-apache   251%/50%   1         10        6          4m31s
php-apache    Deployment/php-apache   251%/50%   1         10        6          4m31s
php-apache2   Deployment/php-apache   52%/50%    1         10        6          5m16s
php-apache    Deployment/php-apache   52%/50%    1         10        6          5m16s
php-apache2   Deployment/php-apache   54%/50%    1         10        6          6m16s
php-apache    Deployment/php-apache   54%/50%    1         10        6          6m16s
php-apache2   Deployment/php-apache   56%/50%    1         10        6          7m16s
php-apache    Deployment/php-apache   56%/50%    1         10        7          7m16s
php-apache2   Deployment/php-apache   56%/50%    1         10        7          7m31s
php-apache2   Deployment/php-apache   46%/50%    1         10        7          8m16s
php-apache    Deployment/php-apache   46%/50%    1         10        7          8m16s
php-apache2   Deployment/php-apache   43%/50%    1         10        7          9m17s
php-apache    Deployment/php-apache   43%/50%    1         10        7          9m17s
php-apache2   Deployment/php-apache   36%/50%    1         10        7          10m
php-apache    Deployment/php-apache   36%/50%    1         10        7          10m
php-apache2   Deployment/php-apache   0%/50%     1         10        7          11m
php-apache    Deployment/php-apache   0%/50%     1         10        7          11m
php-apache2   Deployment/php-apache   0%/50%     1         10        7          15m
php-apache    Deployment/php-apache   0%/50%     1         10        6          15m
php-apache2   Deployment/php-apache   0%/50%     1         10        6          15m
php-apache    Deployment/php-apache   0%/50%    1         10        1          17m
php-apache2   Deployment/php-apache   0%/50%    1         10        1          17m

And last point is v2beta1 was scheduled to be depricated in 1.19 in favor of v2beta2. Now it's rescheduled to be removed in 1.25. You can check it in this pull request

Related