For a quick test of horizontal autoscaling of an NginX deployment, we need the following ingredients:

  • a metrics server installation to be able to measure the POD’s CPU
  • an nginx deployment with a CPU reservation
  • an auto scaler configuration
  • a process that causes high CPU

This can be tested on: https://killercoda.com/playgrounds/scenario/kubernetes

Install Metrics (quick&insecure way)

curl -s -L https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml | sed 's_\(--cert-dir=/tmp\)_\1\n\ \ \ \ \ \ \ \ - --kubelet-insecure-tls_g' | k apply -f -

Create an NginX Deployment…

…with CPU resource request of 0.1

k create deploy nginx --image=nginx --dry-run=client -o yaml | sed 's_\(resources: \){}_resources:\n\ \ \ \ \ \ \ \ \ \ requests:\n\ \ \ \ \ \ \ \ \ \ \ \ cpu: 0.1_' > nginx.deploy.yaml;
k apply -f nginx.deploy.yaml

Create a horizontal Autoscaler

kubectl autoscale deployment nginx --cpu-percent=50 --min=1 --max=4

Run a high CPU Process

k exec -it deploy/nginx -- bash -c 'while true; do echo -n . >/dev/null; done'

Scaling up Result:

k get hpa --watch
NAME    REFERENCE          TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
nginx   Deployment/nginx   0%/50%    1         4         1          51s
nginx   Deployment/nginx   721%/50%   1         4         1          60s
nginx   Deployment/nginx   942%/50%   1         4         4          75s
nginx   Deployment/nginx   228%/50%   1         4         4          90s

Scaling down Result

After stopping the while loop, we see:

k get hpa --watch
NAME    REFERENCE          TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
nginx   Deployment/nginx   0%/50%    1         4         4          6m47s
nginx   Deployment/nginx   0%/50%    1         4         4          8m15s
nginx   Deployment/nginx   0%/50%    1         4         1          8m30s

Appendix: A. 1: Next Generation (v2) Autoscaling with Default Behavior

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  creationTimestamp: null
  name: nginx
spec:
  maxReplicas: 4
  minReplicas: 1
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300
      policies:
      - type: Percent
        value: 100
        periodSeconds: 15
    scaleUp:
      stabilizationWindowSeconds: 0
      policies:
      - type: Percent
        value: 100
        periodSeconds: 15
      - type: Pods
        value: 4
        periodSeconds: 15
      selectPolicy: Max
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx

Appendix: A. 2: Next Generation (v2) Autoscaling with Custom Behavior

The target here is:

  • scale down quickly, if there is no high CPU anymore (stabilizationWindowSeconds set to 0)
  • scale up one by one every 60 seconds: Pods value 1 and periodSeconds 60
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  creationTimestamp: null
  name: nginx
spec:
  maxReplicas: 4
  minReplicas: 1
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 0
      policies:
      - type: Percent
        value: 100
        periodSeconds: 15
    scaleUp:
      stabilizationWindowSeconds: 0
      policies:
      - type: Pods
        value: 1
        periodSeconds: 60
      selectPolicy: Max
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx

we can see that the number of replicas rises one by one from 1 to 4, while the load is high, and the number of replicas goes down quickly if the CPU is below its threshold:

controlplane $ k get hpa --watch
NAME    REFERENCE          TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
nginx   Deployment/nginx   0%/80%    1         4         1          32m
nginx   Deployment/nginx   517%/80%   1         4         1          32m
nginx   Deployment/nginx   816%/80%   1         4         2          33m
nginx   Deployment/nginx   414%/80%   1         4         2          33m
nginx   Deployment/nginx   428%/80%   1         4         2          33m
nginx   Deployment/nginx   428%/80%   1         4         2          34m
nginx   Deployment/nginx   419%/80%   1         4         3          34m
nginx   Deployment/nginx   274%/80%   1         4         3          34m
nginx   Deployment/nginx   275%/80%   1         4         3          35m
nginx   Deployment/nginx   279%/80%   1         4         4          35m
nginx   Deployment/nginx   236%/80%   1         4         4          35m
nginx   Deployment/nginx   214%/80%   1         4         4          35m
nginx   Deployment/nginx   204%/80%   1         4         4          36m
nginx   Deployment/nginx   134%/80%   1         4         4          36m
nginx   Deployment/nginx   0%/80%     1         4         4          36m
nginx   Deployment/nginx   0%/80%     1         4         1          36m

More Information:

Next Generation Autoscaling with Behavior Control

 

126 comments

  1. Hello i think that i saw you visited my weblog so i came to Return the favore Im trying to find things to improve my web siteI suppose its ok to use some of your ideas

  2. The unique set of Professional-Data-Engineer dumps is the easiest and the most rewarding content, you ever found on any web page. Your success is guaranteed! The questions and answers format of our dumps is rich with information and provides you also Google Professional Data Engineer Exam latest lab help, enhancing your exam skills. The content is approved by the most distinguished professionals and revised and updated by our experts on regular basis. With these brilliant features it is rated as the most worthwhile, informative and highly exam relevant. In all respects, you will find the Professional-Data-Engineer dumps compatible to your actual preparatory needs. The language is simple and the content is engaging and easy. No more, Professional-Data-Engineer exam is a nightmare.

  3. Somebody essentially lend a hand to make significantly posts I might state That is the very first time I frequented your web page and up to now I surprised with the research you made to create this particular put up amazing Excellent job.

  4. Its like you read my mind You appear to know so much about this like you wrote the book in it or something I think that you can do with a few pics to drive the message home a little bit but other than that this is fantastic blog A great read Ill certainly be back.

  5. I just could not depart your web site prior to suggesting that I really loved the usual info an individual supply in your visitors Is gonna be back regularly to check up on new posts

  6. obviously like your website but you need to test the spelling on quite a few of your posts Several of them are rife with spelling problems and I to find it very troublesome to inform the reality on the other hand Ill certainly come back again

  7. Somebody essentially lend a hand to make significantly articles Id state That is the very first time I frequented your website page and up to now I surprised with the research you made to make this actual submit amazing Wonderful task.

  8. I truly enjoyed what you’ve achieved here. The design is stylish, your written content fashionable, yet you appear to have acquired some apprehension regarding what you intend to present going forward. Undoubtedly, I’ll return more frequently, similar to I have almost constantly, in the event you sustain this ascent.

  9. I truly savored what you’ve accomplished here. The sketch is elegant, your authored material trendy, however, you seem to have developed some trepidation about what you aim to offer next. Certainly, I shall revisit more regularly, just as I have been doing nearly all the time, in case you uphold this ascension.

  10. I truly relished the effort you’ve invested here. The design is tasteful, your authored material fashionable, however, you seem to have acquired some unease about what you intend to present henceforth. Undoubtedly, I’ll revisit more regularly, similar to I have nearly all the time, in the event you sustain this rise.

  11. I genuinely enjoyed the work you’ve put in here. The outline is refined, your written content stylish, yet you appear to have obtained some apprehension regarding what you wish to deliver thereafter. Assuredly, I will return more frequently, akin to I have almost constantly, provided you maintain this climb.

  12. I sincerely enjoyed what you’ve accomplished here. The sketch is fashionable, your written content chic, yet you appear to have developed some apprehension regarding what you aim to offer thereafter. Certainly, I shall return more frequently, just as I have been doing almost constantly, should you uphold this upswing.

  13. I sincerely appreciated the effort you’ve invested here. The sketch is tasteful, your authored material chic, however, you seem to have developed some uneasiness about what you aim to offer henceforth. Certainly, I shall revisit more regularly, just as I have been doing nearly all the time, should you uphold this climb.

  14. Thanks I have recently been looking for info about this subject for a while and yours is the greatest I have discovered so far However what in regards to the bottom line Are you certain in regards to the supply

  15. I truly appreciated the work you’ve put forth here. The sketch is tasteful, your authored material stylish, yet you appear to have developed some nervousness regarding what you intend to deliver next. Rest assured, I’ll return more regularly, much like I’ve done almost constantly, should you maintain this upward trajectory.

  16. I do believe all the ideas youve presented for your post They are really convincing and will certainly work Nonetheless the posts are too short for novices May just you please lengthen them a little from subsequent time Thanks for the post

  17. Thank you I have just been searching for information approximately this topic for a while and yours is the best I have found out so far However what in regards to the bottom line Are you certain concerning the supply

  18. I’ve been visiting this site for years, and it never fails to impress me with its fresh perspectives and wealth of knowledge. The attention to detail and commitment to quality is evident. This is a true asset for anyone seeking to learn and grow.

  19. Thank you I have just been searching for information approximately this topic for a while and yours is the best I have found out so far However what in regards to the bottom line Are you certain concerning the supply

  20. Thank you for the auspicious writeup It in fact was a amusement account it Look advanced to more added agreeable from you By the way how could we communicate

  21. Thank you I have just been searching for information approximately this topic for a while and yours is the best I have found out so far However what in regards to the bottom line Are you certain concerning the supply

  22. What i dont understood is in reality how youre now not really a lot more smartlyfavored than you might be now Youre very intelligent You understand therefore significantly in terms of this topic produced me personally believe it from a lot of numerous angles Its like women and men are not interested except it is one thing to accomplish with Woman gaga Your own stuffs outstanding Always care for it up

  23. I was recommended this website by my cousin I am not sure whether this post is written by him as nobody else know such detailed about my difficulty You are wonderful Thanks

  24. you are truly a just right webmaster The site loading speed is incredible It kind of feels that youre doing any distinctive trick In addition The contents are masterwork you have done a great activity in this matter

  25. Hi i think that i saw you visited my web site thus i came to Return the favore Im attempting to find things to enhance my siteI suppose its ok to use a few of your ideas

  26. I do trust all the ideas youve presented in your post They are really convincing and will definitely work Nonetheless the posts are too short for newbies May just you please lengthen them a bit from next time Thank you for the post

  27. These ISA Cybersecurity ISA-IEC-62443 questions and answers not only help you in your preparation but also familiarize you with the Cybersecurity exam situation. By attempting our ISA-IEC-62443 Cybersecurity practice exam questions, you will also learn time management. The best thing is that most questions in our exam dumps are those questions that can be included in upcoming ISA-IEC-62443 ISA Cybersecurity exam dumps. Get access to our test engine so that you can get more updated exam dumps.

  28. you are in reality a just right webmaster The site loading velocity is incredible It seems that you are doing any unique trick In addition The contents are masterwork you have performed a wonderful task on this topic

  29. What i do not understood is in truth how you are not actually a lot more smartlyliked than you may be now You are very intelligent You realize therefore significantly in the case of this topic produced me individually imagine it from numerous numerous angles Its like men and women dont seem to be fascinated until it is one thing to do with Woman gaga Your own stuffs nice All the time care for it up

  30. certainly like your website but you need to take a look at the spelling on quite a few of your posts Many of them are rife with spelling problems and I find it very troublesome to inform the reality nevertheless I will definitely come back again

  31. Fantastic beat I would like to apprentice while you amend your web site how could i subscribe for a blog site The account helped me a acceptable deal I had been a little bit acquainted of this your broadcast offered bright clear concept

  32. certainly like your website but you need to take a look at the spelling on quite a few of your posts Many of them are rife with spelling problems and I find it very troublesome to inform the reality nevertheless I will definitely come back again

  33. Meu primo me recomendou este site, não tenho certeza se este post foi escrito por ele, pois ninguém mais sabe tão detalhadamente sobre meu problema. Você é incrível, obrigado

  34. Obrigado, recentemente estive procurando informações sobre este assunto há algum tempo e a sua é a maior que descobri até agora. Mas e em relação aos resultados financeiros Você tem certeza em relação ao fornecimento

  35. fun88 is a reputable official website dedicated to the Vietnamese market. fun88 opens the door to exciting betting competitions. The website not only continuously updates information about events, promotions and new betting opportunities, but also provides easy deposit and withdrawal, with step-by-step instructions for your funds.

  36. Eu amei o quanto você será realizado aqui O esboço é atraente, seu material de autoria elegante, mas você fica impaciente por desejar entregar o seguinte mal, inquestionavelmente, volte mais cedo, já que exatamente o mesmo quase muitas vezes dentro caso você proteja esta caminhada

  37. Obrigado, estou procurando informações sobre esse tópico há algum tempo e a sua é a melhor que descobri até agora. Mas e em relação aos resultados financeiros? Você tem certeza sobre o fornecimento

  38. I loved as much as youll receive carried out right here The sketch is attractive your authored material stylish nonetheless you command get bought an nervousness over that you wish be delivering the following unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case you shield this hike

  39. I do agree with all the ideas you have introduced on your post They are very convincing and will definitely work Still the posts are very short for newbies May just you please prolong them a little from subsequent time Thank you for the post

  40. Somebody essentially lend a hand to make significantly posts I might state That is the very first time I frequented your web page and up to now I surprised with the research you made to create this particular put up amazing Excellent job

  41. Thanks I have just been looking for information about this subject for a long time and yours is the best Ive discovered till now However what in regards to the bottom line Are you certain in regards to the supply

  42. Its like you read my mind You appear to know so much about this like you wrote the book in it or something I think that you can do with a few pics to drive the message home a little bit but other than that this is fantastic blog A great read Ill certainly be back

  43. Great article! I really appreciate the clear and detailed insights you’ve provided on this topic. It’s always refreshing to read content that breaks things down so well, making it easy for readers to grasp even complex ideas. I also found the practical tips you’ve shared to be very helpful. Looking forward to more informative posts like this! Keep up the good work!

  44. naturally like your web site however you need to take a look at the spelling on several of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth on the other hand I will surely come again again.

  45. I have been surfing online more than 3 hours today yet I never found any interesting article like yours It is pretty worth enough for me In my opinion if all web owners and bloggers made good content as you did the web will be much more useful than ever before

  46. Hi my family member I want to say that this post is awesome nice written and come with approximately all significant infos I would like to peer extra posts like this

  47. Your writing has a way of resonating with me on a deep level. I appreciate the honesty and authenticity you bring to every post. Thank you for sharing your journey with us.

  48. Your blog is a constant source of inspiration for me. Your passion for your subject matter is palpable, and it’s clear that you pour your heart and soul into every post. Keep up the incredible work!

  49. hiI like your writing so much share we be in contact more approximately your article on AOL I need a specialist in this area to resolve my problem Maybe that is you Looking ahead to see you

Comments

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.