mirror of https://github.com/k3s-io/k3s
Merge pull request #16366 from jszczepkowski/autoscaling-example
Auto commit by PR queue botpull/6/head
commit
47b15c8896
|
@ -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:
|
First, we will start a replication controller running the image and expose it as an external service:
|
||||||
|
|
||||||
|
<a name="kubectl-run"></a>
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ kubectl create -f docs/user-guide/horizontal-pod-autoscaling/rc-php-apache.yaml
|
$ kubectl run php-apache --image=gcr.io/google_containers/hpa-example --requests=cpu=200m
|
||||||
replicationcontrollers/php-apache
|
replicationcontroller "php-apache" created
|
||||||
|
|
||||||
$ kubectl expose rc php-apache --port=80 --type=LoadBalancer
|
$ kubectl expose rc php-apache --port=80 --type=LoadBalancer
|
||||||
service "php-apache" exposed
|
service "php-apache" exposed
|
||||||
|
@ -115,10 +117,10 @@ spec:
|
||||||
```
|
```
|
||||||
|
|
||||||
This defines a horizontal pod autoscaler that maintains between 1 and 10 replicas of the Pods
|
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
|
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%
|
(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.
|
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:
|
We will create the autoscaler by executing the following command:
|
||||||
|
@ -128,6 +130,14 @@ $ kubectl create -f docs/user-guide/horizontal-pod-autoscaling/hpa-php-apache.ya
|
||||||
horizontalpodautoscaler "php-apache" created
|
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:
|
We may check the current status of autoscaler by running:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
|
@ -148,7 +158,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
|
$ 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
|
```console
|
||||||
$ kubectl get hpa
|
$ kubectl get hpa
|
||||||
|
|
|
@ -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
|
|
Loading…
Reference in New Issue