{"id":5556,"date":"2018-10-30T13:08:26","date_gmt":"2018-10-30T13:08:26","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=5556"},"modified":"2021-11-17T09:40:06","modified_gmt":"2021-11-17T09:40:06","slug":"how-to-autoscale-pods-based-on-cpu-memory-in-kubernetes","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-autoscale-pods-based-on-cpu-memory-in-kubernetes\/","title":{"rendered":"How to Autoscale pods based on CPU\/Memory in Kubernetes?"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5581\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/10\/How-to-Auto-Scale-copy.jpg\" alt=\"\" width=\"600\" height=\"315\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/10\/How-to-Auto-Scale-copy.jpg 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/10\/How-to-Auto-Scale-copy-300x158.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><strong>CPU Based Scaling<\/strong><br>\nWith Horizontal Pod Autoscaling, Kubernetes automatically scales the number of pods in a replication controller, deployment or replica set based on observed CPU utilisation.<\/p>\n<p>[code]$ kubectl get deployment<br>\n$ kubectl autoscale deployment &lt;deployment-name&gt; &#8211;min=2 &#8211;max=5 &#8211;cpu-percent=80<\/p>\n<p>$ kubectl get hpa[\/code]<\/p>\n<p>So, now we have a hpa running for our deployment \u201ctomcat02\u201d. It compares the arithmetic mean of the pods\u2019 CPU utilization with the target defined in Spec.<\/p>\n<ul>\n<li>https:\/\/blog.powerupcloud.com\/autoscaling-based-on-cpu-memory-in-kubernetes-part-ii-fe2e495bddd4<\/li>\n<li>https:\/\/blog.justinwflory.com\/2018\/03\/kubernetes-horizontal-pod-autoscaling\/<\/li>\n<\/ul>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_25527\"><iframe loading=\"lazy\"  id=\"_ytid_21759\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_25527\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>CPU Based Scaling With Horizontal Pod Autoscaling, Kubernetes automatically scales the number of pods in a replication controller, deployment or replica set based on observed CPU utilisation. [code]$ kubectl get&#8230; <\/p>\n","protected":false},"author":1,"featured_media":5581,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4859],"tags":[5116,5118,4860,5117,5115],"class_list":["post-5556","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kubernetes","tag-autoscale","tag-hpa","tag-kubernetes","tag-pods","tag-scaling"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=5556"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5556\/revisions"}],"predecessor-version":[{"id":25566,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5556\/revisions\/25566"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/5581"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=5556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=5556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=5556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}