text: (window.webpackJsonp=window.webpackJsonp||[]).push([[32],{295:function(e,t,a){"use strict";a.r(t);var s=a(0),n=Object(s.a)({},function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("div",{staticClass:"content"},[e._m(0),e._v(" "),e._m(1),e._v(" "),a("ul",[e._m(2),e._v(" "),e._m(3),e._v(" "),e._m(4),e._v(" "),a("li",[e._v("Install "),a("code",[e._v("metrics-server")]),e._v(" as shown in "),a("router-link",{attrs:{to:"./../blog/install-metrics-server.html"}},[e._v("../blog/install-metrics-server.html")])],1)]),e._v(" "),e._m(5),e._v(" "),a("p",[e._v("The Horizontal Pod Autoscaler automatically scales the number of pods in a deployment or replica set based on the observed CPU utilization.")]),e._v(" "),e._m(6),e._v(" "),e._m(7),e._v(" "),e._m(8),e._v(" "),e._m(9),e._v(" "),e._m(10),e._v(" "),a("p",[e._v("CPU is always requested as an absolute quantity, never as a relative quantity; 0.1 is the same amount of CPU on a single-core,dual-core, or 48-core machine.")]),e._v(" "),e._m(11),e._v(" "),a("p",[e._v("To demonstrate the Horizontal Pod Autoscaler, we will serve up a single PHP page that performs a compute-intensive workload:")]),e._v(" "),e._m(12),e._m(13),e._v(" "),e._m(14),a("p",[e._v('Evert time the index page is accessed, the computation will be performed and the message "OK!" will be returned to the client.')]),e._v(" "),e._m(15),e._v(" "),e._m(16),e._v(" "),e._m(17),a("p",[e._v("In a separate terminal, you can set up a watch for the pods, deployments and replica sets that are created:")]),e._v(" "),e._m(18),e._m(19),e._v(" "),e._m(20),e._m(21),e._v(" "),e._m(22),e._m(23),e._v(" "),a("p",[e._v("By default, the service that has been generated is assigned a ClusterIP. It can be convenient to use a NodePort to expose the service.")]),e._v(" "),e._m(24),e._m(25),e._v(" "),e._m(26),a("p",[e._v("Now, when you inspect the service, you will see that it can be accessed through any node in the cluster, on the specified port. You will use this when generating a load on the service.")]),e._v(" "),e._m(27),e._m(28),e._v(" "),e._m(29),e._v(" "),e._m(30),e._m(31),e._v(" "),e._m(32),e._v(" "),e._m(33),e._m(34),e._v(" "),a("p",[e._v("In another terminal, run a simple shell script to repeatedly access the index page, using any of the nodes in the cluster and\nthe specified port number.")]),e._v(" "),e._m(35),e._m(36),e._v(" "),e._m(37),e._v(" "),e._m(38),e._m(39),e._v(" "),e._m(40),e._m(41),e._v(" "),e._m(42),e._v(" "),e._m(43),e._m(44),e._v(" "),e._m(45),e._m(46),e._v(" "),e._m(47),e._v(" "),e._m(48),e._m(49),e._v(" "),e._m(50),e._m(51),e._v(" "),a("p",[e._v("As the thresholds are still being exceeded, another round of scaling takes place, this time from 4 to 8 pods.")]),e._v(" "),e._m(52),e._m(53),e._v(" "),e._m(54),e._m(55),e._v(" "),e._m(56),e._v(" "),e._m(57),e._m(58),e._v(" "),e._m(59),e._m(60),e._v(" "),e._m(61),e._v(" "),e._m(62),e._v(" "),e._m(63),e._v(" "),e._m(64),a("p",[e._v("In time, the pods will be scaled down to one, as shown below:")]),e._v(" "),e._m(65),e._m(66),e._v(" "),e._m(67),e._m(68),e._v(" "),a("p",[e._v("Run the following commands to clean up:")]),e._v(" "),e._m(69),e._m(70),e._v(" "),a("p",[e._v("Video:")]),e._v(" "),a("iframe",{attrs:{src:"https://player.vimeo.com/video/320716536",width:"640",height:"359",frameborder:"0",webkitallowfullscreen:"",mozallowfullscreen:"",allowfullscreen:""}}),e._v(" "),e._m(71),e._v(" "),a("p",[e._v("Introduction to HPA at "),a("a",{attrs:{href:"https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/",target:"_blank",rel:"noopener noreferrer"}},[e._v("https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/"),a("OutboundLink")],1)]),e._v(" "),a("p",[e._v("Example is based on "),a("a",{attrs:{href:"https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/",target:"_blank",rel:"noopener noreferrer"}},[e._v("https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/"),a("OutboundLink")],1)]),e._v(" "),a("p",[e._v("Assigning CPU resources: "),a("a",{attrs:{href:"https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/",target:"_blank",rel:"noopener noreferrer"}},[e._v("https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/"),a("OutboundLink")],1)])])},[function(){var e=this.$createElement,t=this._self._c||e;return t("h1",{attrs:{id:"horizontal-pod-autoscaling"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#horizontal-pod-autoscaling","aria-hidden":"true"}},[this._v("#")]),this._v(" Horizontal pod autoscaling")])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"prerequisites"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#prerequisites","aria-hidden":"true"}},[this._v("#")]),this._v(" Prerequisites")])},function(){var e=this.$createElement,t=this._self._c||e;return t("li",[this._v("Install the "),t("code",[this._v("kubectl")]),this._v(" binary on your Ansible box")])},function(){var e=this.$createElement,t=this._self._c||e;return t("li",[this._v("Install the UCP Client bundle for the "),t("code",[this._v("admin")]),this._v(" user")])},function(){var e=this.$createElement,t=this._self._c||e;return t("li",[this._v("Confirm that you can connect to the cluster by running a test command, for example, "),t("code",[this._v("kubectl get nodes")])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"introduction"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#introduction","aria-hidden":"true"}},[this._v("#")]),this._v(" Introduction")])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"assigning-cpu-resources-to-containers-and-pods"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#assigning-cpu-resources-to-containers-and-pods","aria-hidden":"true"}},[this._v("#")]),this._v(" Assigning CPU Resources to Containers and Pods")])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("It is possible to "),t("code",[this._v("request")]),this._v(" the minimum amount of CPU that a container requires. If the cluster has this amount available, the container will be allowed to start. However, the container will not be scheduled if the requested CPU resource is not\navailable. You can also specify a CPU "),t("code",[this._v("limit")]),this._v(" to set a maximum amount of CPU resources the container is allowed.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("A Container is guaranteed to have as much CPU as specified in its "),t("code",[this._v("request")]),this._v(", but is not allowed to use more CPU than its "),t("code",[this._v("limit")]),this._v(". The CPU resource is measured in CPU units. One CPU, in Kubernetes, is equivalent to:")])},function(){var e=this.$createElement,t=this._self._c||e;return t("ul",[t("li",[this._v("One AWS vCPU")]),this._v(" "),t("li",[this._v("One GCP Core")]),this._v(" "),t("li",[this._v("One Azure vCore")]),this._v(" "),t("li",[this._v("One Hyperthread on a bare-metal Intel processor with Hyperthreading")])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("Fractional values are allowed. A Container that requests 0.5 CPU is guaranteed half as much CPU as a Container that requests 1 CPU. You can use the suffix "),t("code",[this._v("m")]),this._v(" to mean "),t("code",[this._v("milli")]),this._v(" or one thousandth of a CPU. For example, 100m CPU and 0.1 CPU are the same.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"workload"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#workload","aria-hidden":"true"}},[this._v("#")]),this._v(" Workload")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v('<?php\n  $x = 0.0001;\n  for ($i = 0; $i <= 1000000; $i++) {\n    $x += sqrt($x);\n  }\n  echo "OK!";\n?>\n')])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("This file is used as the index page for a web server that is deployed using a custom docker image. A Dockerfile  based on the "),t("code",[this._v("php-apache")]),this._v(" image is used to containerize our worload:")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("FROM php:5-apache\nADD index.php /var/www/html/index.php\nRUN chmod a+rx index.php\n\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"deploying-the-service"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#deploying-the-service","aria-hidden":"true"}},[this._v("#")]),this._v(" Deploying the service")])},function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("p",[e._v("First, we will start a deployment running the image and expose it as a service. We set the CPU request to "),a("code",[e._v("200m")]),e._v(" or "),a("code",[e._v("200/1000")]),e._v(" equals "),a("code",[e._v("0.2")]),e._v(" CPU. Note that, in this instance, we do not set an upper "),a("code",[e._v("limit")]),e._v(" and so the container can use as much CPU as is available on the node.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("$ kubectl run php-apache --image=k8s.gcr.io/hpa-example --requests=cpu=200m --expose --port=80\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("# watch -n 10 kubectl get pods,deploy,rs\n\nEvery 10.0s: kubectl get pods,deploy,rs                    Fri Mar  1 14:43:14 2019\n\nNAME                             READY     STATUS    RESTARTS   AGE\npod/php-apache-7bf9f4b44-lmzfl   1/1       Running   0          37s\n\nNAME                               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE\ndeployment.extensions/php-apache   1         1         1            1           38s\n\nNAME                                         DESIRED   CURRENT   READY     AGE\nreplicaset.extensions/php-apache-7bf9f4b44   1         1         1         37s\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("In another terminal, you can use "),t("code",[this._v("kubectl top")]),this._v(" to monitor the CPU usage. Here, you can see that the single pod is using minimal CPU and memory resources ("),t("code",[this._v("1m")]),this._v(" equals 1/1000th CPU, '7Mi' equals 7MB memory).")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("# watch -n 10 kubectl top pods\n\nEvery 10.0s: kubectl top pods | grep php-apache    Fri Mar  1 14:43:26 2019\n\nphp-apache-7bf9f4b44-lmzfl   1m           7Mi\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("You can use the "),t("code",[this._v("kubectl describe")]),this._v(" command to see details of the deployment. You can see the CPU "),t("code",[this._v("request")]),this._v(" of "),t("code",[this._v("200m")]),this._v(" and that,\nfor now, only one replica is deployed.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("# kubectl describe deploy php-apache\n\nName:                   php-apache\nNamespace:              default\nCreationTimestamp:      Fri, 01 Mar 2019 14:41:45 +0000\nLabels:                 run=php-apache\nAnnotations:            deployment.kubernetes.io/revision=1\nSelector:               run=php-apache\nReplicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable\nStrategyType:           RollingUpdate\nMinReadySeconds:        0\nRollingUpdateStrategy:  25% max unavailable, 25% max surge\nPod Template:\n  Labels:  run=php-apache\n  Containers:\n   php-apache:\n    Image:      k8s.gcr.io/hpa-example\n    Port:       80/TCP\n    Host Port:  0/TCP\n    Requests:\n      cpu:        200m\n    Environment:  <none>\n    Mounts:       <none>\n  Volumes:        <none>\nConditions:\n  Type           Status  Reason\n  ----           ------  ------\n  Available      True    MinimumReplicasAvailable\n  Progressing    True    NewReplicaSetAvailable\nOldReplicaSets:  <none>\nNewReplicaSet:   php-apache-7bf9f4b44 (1/1 replicas created)\nEvents:\n  Type    Reason             Age   From                   Message\n  ----    ------             ----  ----                   -------\n  Normal  ScalingReplicaSet  8m    deployment-controller  Scaled up replica set php-apache-7bf9f4b44 to 1\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"expose-nodeport"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#expose-nodeport","aria-hidden":"true"}},[this._v("#")]),this._v(" Expose NodePort")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("# kubectl get svc php-apache\nNAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE\nphp-apache   ClusterIP   10.96.103.118   <none>        80/TCP    1m\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("Use the "),t("code",[this._v("kubectl patch")]),this._v(" command to change the service type to "),t("code",[this._v("NodePort")]),this._v(" and to set an explicit port, in this instance "),t("code",[this._v("33999")]),this._v(".")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v('# kubectl patch svc php-apache --type=\'json\' -p \'[{"op":"replace","path":"/spec/type","value":"NodePort"}]\'\n\n# kubectl patch svc php-apache --type=\'json\' -p \'[{"op": "add", "path":"/spec/ports/0/nodePort", "value":33999}]\'\n')])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("# kubectl get svc php-apache\n\nNAME         TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE\nphp-apache   NodePort   10.96.103.118   <none>        80:33999/TCP   2m\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"create-autoscaler"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#create-autoscaler","aria-hidden":"true"}},[this._v("#")]),this._v(" Create autoscaler")])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("Use the "),t("code",[this._v("kubectl autoscale")]),this._v(" command to generate the autoscaler.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("# kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10\n\nhorizontalpodautoscaler.autoscaling/php-apache autoscaled\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("In this instance, you specify that when the CPU hits 50% utilization, another pod should be deployed. (In reality, you may want to set this threshold higher, for example, to 70% or 80%). Remember that you set the CPU "),t("code",[this._v("request")]),this._v(" to "),t("code",[this._v("200m")]),this._v(", so  you should see a new pod being created when CPU utilization rises above "),t("code",[this._v("100m")]),this._v(" in absolute terms. You also specifiy that, at most, 10 pods should be deployed.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("In a separate terminal, run a watch on the "),t("code",[this._v("hpa")]),this._v(" resource. Note that, as there is still no load on the web server, the target utilization shows "),t("code",[this._v("0%/50%")]),this._v(".")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("# watch -n 10 kubectl get hpa\n\nEvery 10.0s: kubectl get hpa                        Fri Mar  1 14:47:07 2019\n\nNAME         REFERENCE               TARGETS   MINPODS   MAXPODS   REPLICAS   AGE\nphp-apache   Deployment/php-apache   0%/50%    1         10        1          1m\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"generate-load"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#generate-load","aria-hidden":"true"}},[this._v("#")]),this._v(" Generate load")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("# while true; do wget -q -O- http://hpe2-ucp01.am2.cloudra.local:33999; done\n\nOK!OK!OK!OK!OK!OK!OK!OK!OK!OK!OK!OK!OK...\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"wait-for-scaling"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#wait-for-scaling","aria-hidden":"true"}},[this._v("#")]),this._v(" Wait for scaling")])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("After a slight delay, "),t("code",[this._v("kubectl top pods")]),this._v(" will report that the single pod is consuming significant CPU resources - recall that you did not specify a "),t("code",[this._v("limit")]),this._v(" to set an upper boundary on the CPU utilization. In this instance, it is consuming more than 8 times the target threshold (50% of 200m or 100m), so new pods should be deployed shortly.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("Every 10.0s: kubectl top pods                      Fri Mar  1 14:52:34 2019\n\nNAME                         CPU(cores)   MEMORY(bytes)\nphp-apache-7bf9f4b44-lmzfl   887m         10Mi\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("The "),t("code",[this._v("hpa")]),this._v(" resource also indicates that the target is being exceeded (443%/50%).")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("Every 10.0s: kubectl get hpa                        Fri Mar  1 14:52:43 2019\n\nNAME         REFERENCE               TARGETS    MINPODS   MAXPODS   REPLICAS\n   AGE\nphp-apache   Deployment/php-apache   443%/50%   1         10        1\n   6m\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"scaling-to-4-pods"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#scaling-to-4-pods","aria-hidden":"true"}},[this._v("#")]),this._v(" Scaling to 4 pods")])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("After a certain amount of time, the "),t("code",[this._v("watch")]),this._v(" on pods, deployments and replica sets will show new pods being deployed:")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("Every 10.0s: kubectl get pods,deploy,rs                    Fri Mar  1 14:53:00 2019\n\nNAME                             READY     STATUS    RESTARTS   AGE\npod/php-apache-7bf9f4b44-4q9xb   1/1       Running   0          26s\npod/php-apache-7bf9f4b44-6jmg4   1/1       Running   0          26s\npod/php-apache-7bf9f4b44-jsrlh   1/1       Running   0          26s\npod/php-apache-7bf9f4b44-lmzfl   1/1       Running   0          10m\n\nNAME                               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE\ndeployment.extensions/php-apache   4         4         4            4           10m\nNAME                                         DESIRED   CURRENT   READY     AGE\nreplicaset.extensions/php-apache-7bf9f4b44   4         4         4         10m\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("Use "),t("code",[this._v("kubectl describe")]),this._v(" on the deployment to see details of the scaling event.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("# kubectl describe deploy php-apache\nName:                   php-apache\n...\nNewReplicaSet:   php-apache-7bf9f4b44 (4/4 replicas created)\nEvents:\n  Type    Reason             Age   From                   Message\n  ----    ------             ----  ----                   -------\n  Normal  ScalingReplicaSet  11m   deployment-controller  Scaled up replica set php-apache-7bf9f4b44 to 1\n  Normal  ScalingReplicaSet  1m    deployment-controller  Scaled up replica set php-apache-7bf9f4b44 to 4\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"impact-of-scaling-to-4"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#impact-of-scaling-to-4","aria-hidden":"true"}},[this._v("#")]),this._v(" Impact of scaling to 4")])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("After a while, "),t("code",[this._v("kubectl top pods")]),this._v(" will show that the 4 pods are coping better than one, but they are still exceeding the target, in this instance, 50% of 200m or 100m.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("Every 10.0s: kubectl top pods                      Fri Mar  1 14:55:28 2019\n\nNAME                         CPU(cores)   MEMORY(bytes)\nphp-apache-7bf9f4b44-4q9xb   232m         10Mi\nphp-apache-7bf9f4b44-6jmg4   236m         10Mi\nphp-apache-7bf9f4b44-jsrlh   226m         9Mi\nphp-apache-7bf9f4b44-lmzfl   199m         10Mi\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("Similarly, the "),t("code",[this._v("hpa")]),this._v(" resource  shows that the overall target threshold is still being missed (111%/50%).")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("Every 10.0s: kubectl get hpa                        Fri Mar  1 14:55:48 2019\n\nNAME         REFERENCE               TARGETS    MINPODS   MAXPODS   REPLICAS    AGE\nphp-apache   Deployment/php-apache   111%/50%   1         10        4           10m\n\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"scaling-to-8-pods"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#scaling-to-8-pods","aria-hidden":"true"}},[this._v("#")]),this._v(" Scaling to 8 pods")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("Every 10.0s: kubectl get pods,deploy,rs                    Fri Mar  1 14:58:40 2019\n\nNAME                             READY     STATUS    RESTARTS   AGE\npod/php-apache-7bf9f4b44-2bcc9   1/1       Running   0          3s\npod/php-apache-7bf9f4b44-4q9xb   1/1       Running   0          6m\npod/php-apache-7bf9f4b44-6jmg4   1/1       Running   0          6m\npod/php-apache-7bf9f4b44-7r7lp   1/1       Running   0          3s\npod/php-apache-7bf9f4b44-bpw8s   1/1       Running   0          3s\npod/php-apache-7bf9f4b44-d5jp7   1/1       Running   0          3s\npod/php-apache-7bf9f4b44-jsrlh   1/1       Running   0          6m\npod/php-apache-7bf9f4b44-lmzfl   1/1       Running   0          16m\n\nNAME                               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE\ndeployment.extensions/php-apache   8         8         8            8           16m\nNAME                                         DESIRED   CURRENT   READY     AGE\nreplicaset.extensions/php-apache-7bf9f4b44   8         8         8         16m\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("Again, you can use "),t("code",[this._v("kubectl describe")]),this._v(" on the deployment for confirmation of the scaling event.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("# kubectl describe deploy php-apache\nName:                   php-apache\n...\nNewReplicaSet:   php-apache-7bf9f4b44 (8/8 replicas created)\nEvents:\n  Type    Reason             Age   From                   Message\n  ----    ------             ----  ----                   -------\n  Normal  ScalingReplicaSet  17m   deployment-controller  Scaled up replica set php-apache-7bf9f4b44 to 1\n  Normal  ScalingReplicaSet  7m    deployment-controller  Scaled up replica set php-apache-7bf9f4b44 to 4\n  Normal  ScalingReplicaSet  1m    deployment-controller  Scaled up replica set php-apache-7bf9f4b44 to 8\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"impact-of-scaling-to-8"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#impact-of-scaling-to-8","aria-hidden":"true"}},[this._v("#")]),this._v(" Impact of scaling to 8")])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("After a while, "),t("code",[this._v("kubectl top pods")]),this._v(" will show that the 8 pods are almost sufficient to achieve the required threshold. On average, it would seem that most pods are close to the "),t("code",[this._v("100m")]),this._v(" requirement.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("Every 10.0s: kubectl top pods                      Fri Mar  1 15:01:37 2019\n\nNAME                         CPU(cores)   MEMORY(bytes)\nphp-apache-7bf9f4b44-2bcc9   83m          9Mi\nphp-apache-7bf9f4b44-4q9xb   98m          10Mi\nphp-apache-7bf9f4b44-6jmg4   143m         10Mi\nphp-apache-7bf9f4b44-7r7lp   80m          9Mi\nphp-apache-7bf9f4b44-bpw8s   111m         10Mi\nphp-apache-7bf9f4b44-d5jp7   157m         10Mi\nphp-apache-7bf9f4b44-jsrlh   108m         9Mi\nphp-apache-7bf9f4b44-lmzfl   96m          10Mi\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("Similarly, the "),t("code",[this._v("hpa")]),this._v(" resource  shows that the overall target threshold is close to being achieved (54%/50%).")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("Every 10.0s: kubectl get hpa                        Fri Mar  1 15:01:55 2019\n\nNAME         REFERENCE               TARGETS   MINPODS   MAXPODS   REPLICAS\n  AGE\nphp-apache   Deployment/php-apache   54%/50%   1         10        8\n  16m\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"further-scaling-and-tolerance"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#further-scaling-and-tolerance","aria-hidden":"true"}},[this._v("#")]),this._v(" Further scaling and tolerance")])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("Given this particular workload and your environment, the exact number of pods deployed is not certain. In this instance, another two pods were subsequently deployed, but then one was removed to leave a steady-state of 9 pods required to meet the CPU requirements. Tolerance levels are deployed to stop "),t("code",[this._v("thrashing")]),this._v(", where pods are added and removed repeatedly.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"scaling-down"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#scaling-down","aria-hidden":"true"}},[this._v("#")]),this._v(" Scaling down")])},function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("p",[e._v("Stop the shell script that is generating the workload. The CPU usage reported by "),a("code",[e._v("kubectl top pods")]),e._v(" will drop to a minimal level ("),a("code",[e._v("1m")]),e._v(") while the "),a("code",[e._v("hpa")]),e._v(" resouce will show a target of "),a("code",[e._v("0%/50%")]),e._v(".")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("Every 10.0s: kubectl top pods                      Fri Mar  1 15:15:28 2019\n\nNAME                         CPU(cores)   MEMORY(bytes)\nphp-apache-7bf9f4b44-2bcc9   1m           9Mi\nphp-apache-7bf9f4b44-4q9xb   1m           10Mi\nphp-apache-7bf9f4b44-6jmg4   1m           10Mi\nphp-apache-7bf9f4b44-7r7lp   1m           9Mi\nphp-apache-7bf9f4b44-bpw8s   1m           10Mi\nphp-apache-7bf9f4b44-d5jp7   1m           10Mi\nphp-apache-7bf9f4b44-jsrlh   1m           9Mi\nphp-apache-7bf9f4b44-lmzfl   1m           10Mi\nphp-apache-7bf9f4b44-q6qcf   1m           10Mi\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("Every 10.0s: kubectl get pods,deploy,rs                    Fri Mar  1 15:16:41 2019\n\nNAME                             READY     STATUS        RESTARTS   AGE\npod/php-apache-7bf9f4b44-2bcc9   0/1       Terminating   0          18m\npod/php-apache-7bf9f4b44-4q9xb   0/1       Terminating   0          24m\npod/php-apache-7bf9f4b44-d5jp7   0/1       Terminating   0          18m\npod/php-apache-7bf9f4b44-lmzfl   1/1       Running       0          34m\n\nNAME                               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE\ndeployment.extensions/php-apache   1         1         1            1           34m\nNAME                                         DESIRED   CURRENT   READY     AGE\nreplicaset.extensions/php-apache-7bf9f4b44   1         1         1         34m\n\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[this._v("You can again run "),t("code",[this._v("kubectl describe")]),this._v(" on the deployment, to see the scaling event.")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v("# kubectl describe deploy php-apache\nName:                   php-apache\n...\nNewReplicaSet:   php-apache-7bf9f4b44 (1/1 replicas created)\nEvents:\n  Type    Reason             Age   From                   Message\n  ----    ------             ----  ----                   -------\n  Normal  ScalingReplicaSet  35m   deployment-controller  Scaled up replica set php-apache-7bf9f4b44 to 1\n  Normal  ScalingReplicaSet  25m   deployment-controller  Scaled up replica set php-apache-7bf9f4b44 to 4\n  Normal  ScalingReplicaSet  19m   deployment-controller  Scaled up replica set php-apache-7bf9f4b44 to 8\n  Normal  ScalingReplicaSet  12m   deployment-controller  Scaled up replica set php-apache-7bf9f4b44 to 10\n  Normal  ScalingReplicaSet  6m    deployment-controller  Scaled down replica set php-apache-7bf9f4b44 to 9\n  Normal  ScalingReplicaSet  1m    deployment-controller  Scaled down replica set php-apache-7bf9f4b44 to 1\n")])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"teardown"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#teardown","aria-hidden":"true"}},[this._v("#")]),this._v(" Teardown")])},function(){var e=this.$createElement,t=this._self._c||e;return t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[this._v('# kubectl delete deploy php-apache\ndeployment.extensions "php-apache" deleted\n\n# kubectl delete service php-apache\nservice "php-apache" deleted\n\n# kubectl delete hpa php-apache\nhorizontalpodautoscaler.autoscaling "php-apache" deleted\n')])])])},function(){var e=this.$createElement,t=this._self._c||e;return t("h2",{attrs:{id:"resources"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#resources","aria-hidden":"true"}},[this._v("#")]),this._v(" Resources")])},function(){var e=this.$createElement,t=this._self._c||e;return t("p",[t("a",{attrs:{href:"https://vimeo.com/320716536"}},[this._v("Horizontal pod autoscaling walkthrough")]),this._v("  on "),t("a",{attrs:{href:"https://vimeo.com"}},[this._v("Vimeo")]),this._v(".")])}],!1,null,null,null);n.options.__file="horizontal-pod-autoscaling.md";t.default=n.exports}}]);