-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for horizontal pod autoscaling
- Loading branch information
Showing
9 changed files
with
289 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
docs/user-guide/advanced-configuration/horizontal-pod-autoscaler.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
### Horizontal Pod Autoscaler (HPA) | ||
|
||
The Horizontal Pod Autoscaler feature allows the operator to configure | ||
HPA resources for the web and task deployments. | ||
|
||
The configuration for HPA is cluster and use case specific. Limits, | ||
requests, and health probes should be configured for deployments | ||
associated with a HPA configuration. | ||
|
||
**Note:** Any examples provided in this document are for demonstration purposes only | ||
|
||
| Name | Description | Default | | ||
| ------------------| ---------------------------------------------- | ------- | | ||
| task_replicas | Mininum number of replicas of the task pod | 1 | | ||
| task_max_replicas | Maximum number of replicas the HPA can create | | | ||
| | Set this option to be greater than replicas to | | | ||
| | activate the HPA feature. | | | ||
| task_hpa_metrics | See 'Metrics' section below | | | ||
| task_hpa_behavior | See 'Behavior' section below | | | ||
|
||
| Name | Description | Default | | ||
| ------------------| ---------------------------------------------- | ------- | | ||
| web_replicas | Mininum number of replicas of the web pod | 1 | | ||
| web_max_replicas | Maximum number of replicas the HPA can create | | | ||
| | Set this option to be greater than replicas to | | | ||
| | activate the HPA feature. | | | ||
| web_hpa_metrics | See 'Metrics' section below | | | ||
| web_hpa_behavior | See 'Behavior' section below | | | ||
|
||
##### Metrics | ||
|
||
The metrics option allows configuration of the rules to evaluate when the HPA should | ||
adjust the number of replicas. This option currently doesn't support external or | ||
custom metrics. | ||
|
||
Additional information on the options available can be found in the Kubernetes documentation on HPAs. | ||
|
||
```yaml | ||
spec: | ||
task_hpa_metrics: | ||
- type: Resource | ||
resource: | ||
name: memory | ||
target: | ||
type: Utilization | ||
averageUtilization: 90 | ||
``` | ||
##### Behavior | ||
The behavior option allows configuration of the rules to modify how quickly or | ||
slowly the HPA acts on the metrics rules. Additional information on the options | ||
available can be found in the Kubernetes documentation on HPAs. | ||
```yaml | ||
spec: | ||
scaleDown: | ||
stabilizationWindowSeconds: 300 | ||
policies: | ||
- type: Percent | ||
value: 50 | ||
periodSeconds: 15 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
- name: Create horizontal pod autoscaler for task pod | ||
k8s: | ||
apply: yes | ||
definition: "{{ lookup('template', 'hpa/task.yaml.j2') }}" | ||
when: | ||
- task_max_replicas is defined | ||
- ( task_max_replicas | int > replicas ) or ( task_max_replicas | int > task_replicas ) | ||
|
||
- name: Create horizontal pod autoscaler for web pod | ||
k8s: | ||
apply: yes | ||
definition: "{{ lookup('template', 'hpa/web.yaml.j2') }}" | ||
when: | ||
- web_max_replicas is defined | ||
- ( web_max_replicas | int > replicas ) or ( web_max_replicas | int > web_replicas ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: autoscaling/v2 | ||
kind: HorizontalPodAutoscaler | ||
metadata: | ||
name: '{{ ansible_operator_meta.name }}-task' | ||
namespace: '{{ ansible_operator_meta.namespace }}' | ||
labels: | ||
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }} | ||
{{ lookup("template", "../common/templates/labels/version.yaml.j2") | indent(width=4) | trim }} | ||
spec: | ||
{% if task_replicas != '' and task_replicas | int > 0 %} | ||
minReplicas: {{ task_replicas }} | ||
{% elif replicas != '' and task_replicas | int > 0 %} | ||
minReplicas: {{ replicas }} | ||
{% endif %} | ||
maxReplicas: {{ task_max_replicas }} | ||
metrics: | ||
{% if task_hpa_metrics is defined %} | ||
metrics: | ||
{{ task_hpa_metrics | to_nice_yaml | indent(width=4) }} | ||
{% endif %} | ||
{% if task_hpa_behavior is defined %} | ||
behavior: | ||
{{ task_hpa_behavior | to_nice_yaml | indent(width=4) }} | ||
{% endif %} | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: '{{ ansible_operator_meta.name }}-task' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: autoscaling/v2 | ||
kind: HorizontalPodAutoscaler | ||
metadata: | ||
name: '{{ ansible_operator_meta.name }}-web' | ||
namespace: '{{ ansible_operator_meta.namespace }}' | ||
labels: | ||
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }} | ||
{{ lookup("template", "../common/templates/labels/version.yaml.j2") | indent(width=4) | trim }} | ||
spec: | ||
{% if web_replicas != '' and web_replicas | int > 0 %} | ||
minReplicas: {{ web_replicas }} | ||
{% elif replicas != '' and web_replicas | int > 0 %} | ||
minReplicas: {{ replicas }} | ||
{% endif %} | ||
maxReplicas: {{ web_max_replicas }} | ||
metrics: | ||
{% if web_hpa_metrics is defined %} | ||
metrics: | ||
{{ web_hpa_metrics | to_nice_yaml | indent(width=4) }} | ||
{% endif %} | ||
{% if web_hpa_behavior is defined %} | ||
behavior: | ||
{{ web_hpa_behavior | to_nice_yaml | indent(width=4) }} | ||
{% endif %} | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: '{{ ansible_operator_meta.name }}-web' |