From ffc0c0b4c136e8e91d3fe824619979de51eb7d9e Mon Sep 17 00:00:00 2001 From: Jerzy Szczepkowski Date: Tue, 27 Oct 2015 15:31:02 +0100 Subject: [PATCH] Updated HPA example to use kubectl commands. Updated HPA example to use kubectl commands. --- .../horizontal-pod-autoscaling/README.md | 20 ++++++++++++---- .../rc-php-apache.yaml | 23 ------------------- 2 files changed, 15 insertions(+), 28 deletions(-) delete mode 100644 docs/user-guide/horizontal-pod-autoscaling/rc-php-apache.yaml diff --git a/docs/user-guide/horizontal-pod-autoscaling/README.md b/docs/user-guide/horizontal-pod-autoscaling/README.md index cb62b0e5a9..1dee5046fe 100644 --- a/docs/user-guide/horizontal-pod-autoscaling/README.md +++ b/docs/user-guide/horizontal-pod-autoscaling/README.md @@ -51,9 +51,11 @@ It defines [index.php](image/index.php) page which performs some CPU intensive c First, we will start a replication controller running the image and expose it as an external service: + + ```console -$ kubectl create -f docs/user-guide/horizontal-pod-autoscaling/rc-php-apache.yaml -replicationcontrollers/php-apache +$ kubectl run php-apache --image=gcr.io/google_containers/hpa-example --requests=cpu=200m +replicationcontroller "php-apache" created $ kubectl expose rc php-apache --port=80 --type=LoadBalancer service "php-apache" exposed @@ -116,10 +118,10 @@ spec: ``` This defines a horizontal pod autoscaler that maintains between 1 and 10 replicas of the Pods -controlled by the php-apache replication controller you created in the first step of these instructions. +controlled by the php-apache replication controller we created in the first step of these instructions. Roughly speaking, the horizontal autoscaler will increase and decrease the number of replicas (via the replication controller) so as to maintain an average CPU utilization across all Pods of 50% -(since each pod requests 200 milli-cores in [rc-php-apache.yaml](rc-php-apache.yaml), this means average CPU utilization of 100 milli-cores). +(since each pod requests 200 milli-cores by [kubectl run](#kubectl-run), this means average CPU utilization of 100 milli-cores). See [here](../../../docs/design/horizontal-pod-autoscaler.md#autoscaling-algorithm) for more details on the algorithm. We will create the autoscaler by executing the following command: @@ -129,6 +131,14 @@ $ kubectl create -f docs/user-guide/horizontal-pod-autoscaling/hpa-php-apache.ya horizontalpodautoscaler "php-apache" created ``` +Alternatively, we can create the autoscaler using [kubectl autoscale](../kubectl/kubectl_autoscale.md). +The following command will create the equivalent autoscaler as defined in the [hpa-php-apache.yaml](hpa-php-apache.yaml) file: + +``` +$ kubectl autoscale rc php-apache --cpu-percent=50 --min=1 --max=10 +replicationcontroller "php-apache" autoscaled +``` + We may check the current status of autoscaler by running: ```console @@ -149,7 +159,7 @@ We will start an infinite loop of queries to our server (please run it in a diff $ while true; do curl http://146.148.6.244; done ``` -We may examine, how CPU load was increased (the results should be visible after about 2 minutes) by executing: +We may examine, how CPU load was increased (the results should be visible after about 3-4 minutes) by executing: ```console $ kubectl get hpa diff --git a/docs/user-guide/horizontal-pod-autoscaling/rc-php-apache.yaml b/docs/user-guide/horizontal-pod-autoscaling/rc-php-apache.yaml deleted file mode 100644 index cc2668ff47..0000000000 --- a/docs/user-guide/horizontal-pod-autoscaling/rc-php-apache.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: v1 -kind: ReplicationController -metadata: - labels: - run: php-apache - name: php-apache - namespace: default -spec: - replicas: 1 - selector: - run: php-apache - template: - metadata: - labels: - run: php-apache - spec: - containers: - - image: gcr.io/google_containers/hpa-example - name: php-apache - resources: - requests: - cpu: 200m - restartPolicy: Always