Merge pull request #566 from zzxwill/docs-autoscale

Revise autoscaler doc with appfile focused
This commit is contained in:
Jianbo Sun
2020-11-13 11:08:50 +08:00
committed by GitHub
71 changed files with 389 additions and 649 deletions
@@ -8,26 +8,26 @@ spec:
appliesToWorkloads:
- webservice
- backend
- deployments.apps
- podspecworkload
workloadRefPath: spec.workloadRef
definitionRef:
name: autoscalers.standard.oam.dev
extension:
template: |
import "strconv"
output: {
apiVersion: "standard.oam.dev/v1alpha1"
kind: "Autoscaler"
spec: {
minReplicas: parameter.min
maxReplicas: parameter.max
if parameter["cpu"] != _|_ && parameter["cron"] != _|_ {
if parameter["cpuPercent"] != _|_ && parameter["cron"] != _|_ {
triggers: [cpuScaler, cronScaler]
}
if parameter["cpu"] != _|_ && parameter["cron"] == _|_ {
if parameter["cpuPercent"] != _|_ && parameter["cron"] == _|_ {
triggers: [cpuScaler]
}
if parameter["cpu"] == _|_ && parameter["cron"] != _|_ {
if parameter["cpuPercent"] == _|_ && parameter["cron"] != _|_ {
triggers: [cronScaler]
}
}
@@ -37,16 +37,22 @@ spec:
type: "cpu"
condition: {
type: "Utilization"
if parameter["cpu"] != _|_ {
value: parameter.cpu
if parameter["cpuPercent"] != _|_ {
value: strconv.FormatInt(parameter.cpuPercent, 10)
}
}
}
cronScaler: {
type: "cron"
if parameter["cron"] != _|_ {
condition: parameter.cron
if parameter["cron"] != _|_ && parameter.cron["replicas"] != _|_ {
condition: {
startAt: parameter.cron.startAt
duration: parameter.cron.duration
days: parameter.cron.days
replicas: strconv.FormatInt(parameter.cron.replicas, 10)
timezone: parameter.cron.timezone
}
}
}
@@ -56,15 +62,19 @@ spec:
// +usage=maximal replicas of the workload
max: int
// +usage=specify the value for CPU utilization, like 80, which means 80%
cpu?: string
// +alias=cpu-percent
cpuPercent?: int
// +usage=just for `appfile`, not available for Cli usage
cron?: {
startAt: string
// +usage=the time to start scaling, like `08:00`
startAt: string
// +usage=for how long the scaling will last
duration: string
// +usage=several workdays or weekends, like "Monday, Tuesday"
days: string
replicas: string
// +usage=timezone, like "America/Seattle"
days: string
// +usage=the target replicas to be scaled to
replicas: int
// +usage=timezone, like "America/Los_Angeles"
timezone: string
}
}
@@ -48,12 +48,12 @@ spec:
containerPort: parameter.port
}]
if parameter["cpuRequests"] != _|_ {
if parameter["cpu"] != _|_ {
resources: {
limits:
cpu: parameter.cpuRequests
cpu: parameter.cpu
requests:
cpu: parameter.cpuRequests
cpu: parameter.cpu
}
}
}]
@@ -82,8 +82,7 @@ spec:
}
}
}]
// +usage=CPU core requests for the workload, specify like '0.5', '1'.
// +alias=cpu-requests
cpuRequests?: string
// +usage=Number of CPU units for the service, like `500m` (0.5 CPU core), `1` (1 CPU core)
cpu?: string
}
+1 -1
View File
@@ -46,4 +46,4 @@ vela [flags]
* [vela version](vela_version.md) - Prints out build version information
* [vela workloads](vela_workloads.md) - List workloads
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+8 -14
View File
@@ -19,19 +19,13 @@ vela autoscale frontend
### Options
```
--days string
--detach detach trait from service
--duration string
-h, --help help for autoscale
--maxReplicas int (default 4)
--minReplicas int (default 1)
--name string
--replicas string (default "2")
-s, --staging only save changes locally without real update application
--startAt string
--svc string specify one service belonging to the application
--timezone string (default "Asia/Shanghai")
--type string (default "cron")
--cpuPercent int specify the value for CPU utilization, like 80, which means 80%
--detach detach trait from service
-h, --help help for autoscale
--max int maximal replicas of the workload
--min int minimal replicas of the workload
-s, --staging only save changes locally without real update application
--svc string specify one service belonging to the application
```
### Options inherited from parent commands
@@ -44,4 +38,4 @@ vela autoscale frontend
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -26,4 +26,4 @@ Capability Management with config, list, add, remove capabilities
* [vela cap ls](vela_cap_ls.md) - List capabilities from cap-center
* [vela cap uninstall](vela_cap_uninstall.md) - Uninstall capability from cluster
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -26,4 +26,4 @@ Manage Capability Center with config, sync, list
* [vela cap center remove](vela_cap_center_remove.md) - Remove specified capability center
* [vela cap center sync](vela_cap_center_sync.md) - Sync capabilities from remote center, default to sync all centers
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -33,4 +33,4 @@ vela cap center config mycenter https://github.com/oam-dev/catalog/cap-center
* [vela cap center](vela_cap_center.md) - Manage Capability Center
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela cap center ls
* [vela cap center](vela_cap_center.md) - Manage Capability Center
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela cap center remove mycenter
* [vela cap center](vela_cap_center.md) - Manage Capability Center
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela cap center sync mycenter
* [vela cap center](vela_cap_center.md) - Manage Capability Center
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -33,4 +33,4 @@ vela cap install mycenter/route
* [vela cap](vela_cap.md) - Capability Management
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela cap ls
* [vela cap](vela_cap.md) - Capability Management
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -33,4 +33,4 @@ vela cap uninstall route
* [vela cap](vela_cap.md) - Capability Management
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -27,4 +27,4 @@ of vela commands.
* [vela completion bash](vela_completion_bash.md) - generate autocompletions script for bash
* [vela completion zsh](vela_completion_zsh.md) - generate autocompletions script for zsh
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -36,4 +36,4 @@ vela completion bash
* [vela completion](vela_completion.md) - Output shell completion code for the specified shell (bash or zsh)
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -33,4 +33,4 @@ vela completion zsh
* [vela completion](vela_completion.md) - Output shell completion code for the specified shell (bash or zsh)
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -26,4 +26,4 @@ Manage application configurations under given env
* [vela config ls](vela_config_ls.md) - List configs
* [vela config set](vela_config_set.md) - Set data for a config
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela config del <config-name>
* [vela config](vela_config.md) - Manage application configurations
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela config get <config-name>
* [vela config](vela_config.md) - Manage application configurations
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela config ls
* [vela config](vela_config.md) - Manage application configurations
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela config set <config-name> KEY=VALUE K2=V2
* [vela config](vela_config.md) - Manage application configurations
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -38,4 +38,4 @@ dashboard
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -33,4 +33,4 @@ vela delete frontend
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -26,4 +26,4 @@ Manage application environments
* [vela env ls](vela_env_ls.md) - List environments
* [vela env set](vela_env_set.md) - Set an environment
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela env delete test
* [vela env](vela_env.md) - Manage application environments
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -36,4 +36,4 @@ vela env init test --namespace test --email my@email.com
* [vela env](vela_env.md) - Manage application environments
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela env ls [env-name]
* [vela env](vela_env.md) - Manage application environments
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela env set test
* [vela env](vela_env.md) - Manage application environments
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -29,4 +29,4 @@ vela exec [flags] AppName -- COMMAND [args...]
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -33,4 +33,4 @@ vela init
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -31,4 +31,4 @@ vela install [flags]
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -27,4 +27,4 @@ vela logs [flags]
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -33,4 +33,4 @@ vela ls
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -40,4 +40,4 @@ vela metric frontend
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -28,4 +28,4 @@ vela port-forward APP_NAME [options] [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -38,4 +38,4 @@ vela rollout frontend
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -37,4 +37,4 @@ vela route frontend
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -36,4 +36,4 @@ vela scaler frontend
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -33,4 +33,4 @@ vela show <APPLICATION-NAME>
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -33,4 +33,4 @@ vela status <APPLICATION-NAME>
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -24,4 +24,4 @@ Manage services
* [vela](vela.md) -
* [vela svc deploy](vela_svc_deploy.md) - Initialize and run a service
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -35,4 +35,4 @@ vela svc deploy -t <SERVICE_TYPE>
* [vela svc](vela_svc.md) - Manage services
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -23,4 +23,4 @@ System management utilities
* [vela](vela.md) -
* [vela system info](vela_system_info.md) - Show vela client and cluster chartPath
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -26,4 +26,4 @@ vela system info [flags]
* [vela system](vela_system.md) - System management utilities
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -23,4 +23,4 @@ Manage templates
* [vela](vela.md) -
* [vela template context](vela_template_context.md) - Show context parameters
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -32,4 +32,4 @@ vela template context
* [vela template](vela_template.md) - Manage templates
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -34,4 +34,4 @@ vela traits
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -27,4 +27,4 @@ vela up
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -26,4 +26,4 @@ vela version [flags]
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+1 -1
View File
@@ -33,4 +33,4 @@ vela workloads
* [vela](vela.md) -
###### Auto generated by spf13/cobra on 10-Nov-2020
###### Auto generated by spf13/cobra on 12-Nov-2020
+35 -14
View File
@@ -142,21 +142,42 @@ Last Deployment:
## `vela autoscale`
A shortcut to autoscale the service.
Currently, Cli only supports setting CPU resource utilization auto-scaling policy. To configure cron auto-scaling policy,
please refer to [autoscale in Appfile](/en/developers/set-autoscale.md).
```console
$ vela autoscale helloworld --svc frontend --min 1 --max 5 --cpu 5
Adding autoscale for app frontend
⠋ Checking Status ...
✅ Application Deployed Successfully!
- Name: frontend
Type: webservice
HEALTHY Ready: 1/1
Traits:
- ✅ autoscale: type: cpu cpu-utilization(target/current): 5%/0% replicas(min/max/current): 1/5/0
Last Deployment:
Created at: 2020-11-06 16:10:54 +0800 CST
Updated at: 2020-11-06T16:19:04+08:0
```
- Deploy an application
Run the following command to deploy application `helloworld`.
```
$ vela svc deploy frontend -t webservice -a helloworld --image nginx:1.9.2 --port 80 --cpu=0.05
App helloworld deployed
```
By default, the replicas of the workload webservice `helloworld` is one.
- Scale the application by CPU utilization metrics
```
$ vela autoscale helloworld --svc frontend --min 1 --max 5 --cpu-percent 5
Adding autoscale for app frontend
⠋ Checking Status ...
✅ Application Deployed Successfully!
- Name: frontend
Type: webservice
HEALTHY Ready: 1/1
Traits:
- ✅ autoscale: type: cpu cpu-utilization(target/current): 5%/0% replicas(min/max/current): 1/5/0
Last Deployment:
Created at: 2020-11-06 16:10:54 +0800 CST
Updated at: 2020-11-06T16:19:04+08:0
```
- Monitor the replicas changing when the application becomes overloaded
Continue to monitor the replicas changing when the application becoming overloaded. You can use Apache HTTP server
benchmarking tool `ab` to mock many requests to the application as we did in [Autoscalig in Appfile](/en/developers/set-autoscale.md).
With more and more requests to the application, the replicas gradually increase from one to four.
## `vela metric`
@@ -0,0 +1,45 @@
## Description
`Autoscale` is used to automatically scale workloads by resource utilization metrics and cron
## Specification
List of all available properties for a `Autoscale` trait.
```yaml
name: testapp
services:
express-server:
autoscale:
min: 1
max: 4
cron:
startAt: "14:00"
duration: "2h"
days: "Monday, Thursday"
replicas: 2
timezone: "America/Los_Angeles"
cpuPercent: 10
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
min | int | minimal replicas of the workload | required
max | int | maximal replicas of the workload | required
cpuPercent | int | specify the value for CPU utilization, like 80, which means 80% |
cron | [{Cron}](#Cron) | just for `appfile`, not available for Cli usage |
### Cron
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
startAt | string | the time to start scaling, like `08:00` |
duration | string | for how long the scaling will last |
days | string | several workdays or weekends, like "Monday, Tuesday" |
replicas | int | the target replicas to be scaled to |
timezone | string | timezone, like "America/Los_Angeles" |
@@ -19,6 +19,7 @@ services:
image: oamdev/testapp:v1
cmd: ["node", "server.js"]
port: 8080
cpu: "0.1"
env:
- name: FOO
value: bar
@@ -37,7 +38,7 @@ Name | Type | Description | Notes
**Env** | [**[]WebserviceEnv**](#webserviceenv) | | [optional]
**Image** | **string** | Which image would you like to use for your service |
**Port** | **int32** | Which port do you want customer traffic sent to | [default to 80]
**CpuRequests** | **string** | CPU core requests for the workload, specify like &#39;0.5&#39;, &#39;1&#39 | [optional]
**cpu** | **string** | Number of CPU units for the service, like `500m` (0.5 CPU core), `1` (1 CPU core) | [optional]
### WebserviceEnv
+186 -140
View File
@@ -1,162 +1,208 @@
# Automatically scale workloads by resource utilization metrics and cron
## Scale by CPU resource utilization metrics
## Setting cron auto-scaling policy
Introduce how to automatically scale workloads by cron.
1. Prepare Appfile:
1. Prepare Appfile
```bash
$ cat <<EOF > vela.yaml
name: testapp
services:
express-server:
image: nginx:1.9.2
port: 80
cpuRequests: 0.05
autoscale:
min: 1
max: 5
cpu: 5
EOF
```yaml
name: testapp
services:
express-server:
# this image will be used in both build and deploy steps
image: oamdev/testapp:v1
cmd: ["node", "server.js"]
port: 8080
autoscale:
min: 1
max: 4
cron:
startAt: "14:00"
duration: "2h"
days: "Monday, Thursday"
replicas: 2
timezone: "America/Los_Angeles"
```
2. Deploy the application:
```bash
$ vela up
```
3. Access the application with heavy requests
2. Deploy an application
```
$ vela port-forward helloworld 80
Forwarding from 127.0.0.1:80 -> 80
Forwarding from [::1]:80 -> 80
$ vela up
Parsing vela.yaml ...
Loading templates ...
Forward successfully! Opening browser ...
Handling connection for 80
Rendering configs for service (express-server)...
Writing deploy config to (.vela/deploy.yaml)
Applying deploy configs ...
Checking if app has been deployed...
App has not been deployed, creating a new deployment...
✅ App has been deployed 🚀🚀🚀
Port forward: vela port-forward testapp
SSH: vela exec testapp
Logging: vela logs testapp
App status: vela status testapp
Service status: vela status testapp --svc express-server
```
3. Check the replicas and wait for the scaling to take effect
Check the replicas of the application, there is one replica.
```
$ vela status testapp
About:
On your macOS, you might need to add `sudo` ahead of the command.
Name: testapp
Namespace: default
Created at: 2020-11-05 17:09:02.426632 +0800 CST
Updated at: 2020-11-05 17:09:02.426632 +0800 CST
4. Use Apache HTTP server benchmarking tool `ab` to access the application.
Services:
```
$ ab -n 10000 -c 200 http://127.0.0.1/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
```
5. Monitor the replicas of the workload, and see its replicas increase from one to four.
```
$ vela status helloworld --svc frontend
About:
Name: helloworld
Namespace: default
Created at: 2020-11-05 20:07:21.830118 +0800 CST
Updated at: 2020-11-05 20:50:42.664725 +0800 CST
Services:
- Name: frontend
Type: webservice
HEALTHY Ready: 1/1
Traits:
- ✅ autoscale: type: cpu cpu-utilization(target/current): 5%/14% replicas(min/max/current): 1/5/4
Last Deployment:
Created at: 2020-11-05 20:07:23 +0800 CST
Updated at: 2020-11-05T20:50:42+08:00
```
Stop `ab` tool, and the replicas will decrease to one eventually.
## Scale workload by cron
1. Prepare Appfile:
```bash
$ cat <<EOF > vela.yaml
name: testapp
services:
express-server:
image: zzxwill/kubevela-appfile-demo:v1
cmd: ["node", "server.js"]
port: 8080
autoscale:
min: 1
max: 4
cron:
startAt: "14:00"
duration: "2h"
days: "Monday, Thursday"
replicas: "2"
timezone: "America/Seattle"
EOF
```
2. Deploy the application:
```bash
$ vela up
```
3. Check the replicas and wait for the scaling to take effect:
```
$ vela status testapp
About:
Name: testapp
Namespace: default
Created at: 2020-11-05 17:09:02.426632 +0800 CST
Updated at: 2020-11-05 17:09:02.426632 +0800 CST
Services:
- Name: express-server
Type: webservice
HEALTHY Ready: 1/1
Traits:
- ✅ autoscale: type: cron replicas(min/max/current): 1/4/1
Last Deployment:
Created at: 2020-11-05 17:09:03 +0800 CST
Updated at: 2020-11-05T17:09:02+08:00
- Name: express-server
Type: webservice
HEALTHY Ready: 1/1
Traits:
- ✅ autoscale: type: cron replicas(min/max/current): 1/4/1
Last Deployment:
Created at: 2020-11-05 17:09:03 +0800 CST
Updated at: 2020-11-05T17:09:02+08:00
```
Wait till the time clocks `startAt`, and check again. The replicas become to two, which is specified as
`replicas` in `vela.yaml`.
```
$ vela status testapp
About:
Name: testapp
Namespace: default
Created at: 2020-11-10 10:18:59.498079 +0800 CST
Updated at: 2020-11-10 10:18:59.49808 +0800 CST
Services:
- Name: express-server
Type: webservice
HEALTHY Ready: 2/2
Traits:
- ✅ autoscale: type: cron replicas(min/max/current): 1/4/2
Last Deployment:
Created at: 2020-11-10 10:18:59 +0800 CST
Updated at: 2020-11-10T10:18:59+08:00
$ vela status testapp
About:
Name: testapp
Namespace: default
Created at: 2020-11-10 10:18:59.498079 +0800 CST
Updated at: 2020-11-10 10:18:59.49808 +0800 CST
Services:
- Name: express-server
Type: webservice
HEALTHY Ready: 2/2
Traits:
- ✅ autoscale: type: cron replicas(min/max/current): 1/4/2
Last Deployment:
Created at: 2020-11-10 10:18:59 +0800 CST
Updated at: 2020-11-10T10:18:59+08:00
```
Wait after the period ends, the replicas will be one eventually.
## Setting auto-scaling policy of CPU resource utilization
Introduce how to automatically scale workloads by CPU resource utilization.
1. Prepare Appfile
Modify `vela.yaml` as below. We add field `services.express-server.cpu` and change the auto-scaling policy
from cron to cpu utilization by updating filed `services.express-server.autoscale`.
```yaml
name: testapp
services:
express-server:
image: oamdev/testapp:v1
cmd: ["node", "server.js"]
port: 8080
cpu: "0.01"
autoscale:
min: 1
max: 5
cpuPercent: 10
```
2. Deploy an application
```bash
$ vela up
```
3. Expose the service entrypoint of the application
```
$ vela port-forward helloworld 80
Forwarding from 127.0.0.1:80 -> 80
Forwarding from [::1]:80 -> 80
Forward successfully! Opening browser ...
Handling connection for 80
Handling connection for 80
Handling connection for 80
Handling connection for 80
```
On your macOS, you might need to add `sudo` ahead of the command.
4. Monitor the replicas changing
Continue to monitor the replicas changing when the application becomes overloaded. You can use Apache HTTP server
benchmarking tool `ab` to mock many requests to the application.
```
$ ab -n 10000 -c 200 http://127.0.0.1/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
```
The replicas gradually increase from one to four.
```
$ vela status helloworld --svc frontend
About:
Name: helloworld
Namespace: default
Created at: 2020-11-05 20:07:21.830118 +0800 CST
Updated at: 2020-11-05 20:50:42.664725 +0800 CST
Services:
- Name: frontend
Type: webservice
HEALTHY Ready: 1/1
Traits:
- ✅ autoscale: type: cpu cpu-utilization(target/current): 5%/10% replicas(min/max/current): 1/5/2
Last Deployment:
Created at: 2020-11-05 20:07:23 +0800 CST
Updated at: 2020-11-05T20:50:42+08:00
```
```
$ vela status helloworld --svc frontend
About:
Name: helloworld
Namespace: default
Created at: 2020-11-05 20:07:21.830118 +0800 CST
Updated at: 2020-11-05 20:50:42.664725 +0800 CST
Services:
- Name: frontend
Type: webservice
HEALTHY Ready: 1/1
Traits:
- ✅ autoscale: type: cpu cpu-utilization(target/current): 5%/14% replicas(min/max/current): 1/5/4
Last Deployment:
Created at: 2020-11-05 20:07:23 +0800 CST
Updated at: 2020-11-05T20:50:42+08:00
```
Stop `ab` tool, and the replicas will decrease to one eventually.
+2 -2
View File
@@ -43,8 +43,8 @@ services:
# startAt: "14:00"
# duration: "2h"
# days: "Monday, Thursday"
# replicas: "2"
# timezone: "America/Seattle"
# replicas: 2
# timezone: "America/Los_Angeles"
# pi:
# image: perl
+1 -1
View File
@@ -286,7 +286,7 @@ var (
a: "8080",
},
{
q: "CPU core requests for the workload, specify like '0.5', '1'. (optional):",
q: "Number of CPU units for the service, like `500m` (0.5 CPU core), `1` (1 CPU core) (optional):",
a: "0.5",
},
}
@@ -1,106 +0,0 @@
# Scaling PodSpecWorkload with cron and cpu utilization metrics
## Prerequisites
- [ ] HPA with metrics-server enabled
- [ ] [KEDA](https://keda.sh/docs/2.0/deploy/) v2.0 Beta
## Deploy deployment and KEDA
- Apply these manifests to deploy PodSpecWorkload with Trait Autoscaler
```
$ kubectl apply -f .
```
- Check the replicas of the Deployment generated by PodSpecWorkload
```
$ kubectl get deployment --watch
NAME READY UP-TO-DATE AVAILABLE AGE
component-scaler 0/1 0 0 0s
component-scaler 0/1 0 0 0s
component-scaler 0/1 0 0 0s
component-scaler 0/1 0 0 0s
component-scaler 0/1 1 0 0s
component-scaler 1/1 1 1 1s
component-scaler 1/1 1 1 28s
component-scaler 1/2 1 1 40s
component-scaler 1/2 1 1 40s
component-scaler 1/2 1 1 40s
component-scaler 1/2 2 1 40s
component-scaler 2/2 2 2 41s
```
- Wait `ScaledObject` to take effect
```
$ kubectl get scaledobject.keda.sh --watch
trait-scaler component-scaler cron Unknown Unknown 0s
trait-scaler component-scaler cron Unknown Unknown 0s
trait-scaler apps/v1.Deployment component-scaler cron Unknown Unknown 0s
trait-scaler apps/v1.Deployment component-scaler cron Unknown Unknown 0s
trait-scaler apps/v1.Deployment component-scaler cron True Unknown 0s
trait-scaler apps/v1.Deployment component-scaler cron True Unknown 0s
trait-scaler apps/v1.Deployment component-scaler cron True True 1s
trait-scaler apps/v1.Deployment component-scaler cron True True 31s
```
The replicas of Deployment will change to 4.
```shell
$ kubectl get deployment --watch
component-scaler 2/4 2 2 5m47s
component-scaler 2/4 2 2 5m47s
component-scaler 2/4 2 2 5m47s
component-scaler 2/4 4 2 5m47s
component-scaler 3/4 4 3 5m59s
component-scaler 4/4 4 4 5m59s
```
- Visit the Deployment with a heavy load.
```
$ sudo k port-forward deploy/component-scaler 80
$ ab -n 10000 -c 100 http://127.0.0.1/
```
- Monitor the Deployment
The replicas of the Deployment changes from 4 to 8, and to 10 at last. And after stopping ab, it will be scaled down
to 4.
```shell
component-scaler 4/8 4 4 7m5s
component-scaler 4/8 4 4 7m5s
component-scaler 4/8 4 4 7m5s
component-scaler 4/8 8 4 7m6s
component-scaler 5/8 8 5 7m16s
component-scaler 6/8 8 6 7m16s
component-scaler 7/8 8 7 7m16s
component-scaler 8/8 8 8 7m16s
component-scaler 8/10 8 8 7m20s
component-scaler 8/10 8 8 7m20s
component-scaler 8/10 8 8 7m20s
component-scaler 8/10 10 8 7m20s
component-scaler 9/10 10 9 7m22s
component-scaler 10/10 10 10 7m22s
component-scaler 10/4 10 10 12m
component-scaler 10/4 10 10 12m
component-scaler 8/4 8 8 12m
component-scaler 4/4 4 4 12m
```
# Debug
- KEDA ScaledObject won't be ready
```
$ kubectl get scaledobject.keda.sh
NAME SCALETARGETKIND SCALETARGETNAME TRIGGERS AUTHENTICATION READY ACTIVE AGE
trait-scaler component-scaler cron 3m49s
```
Please check those Pods of Keda.
```
$ kubectl get pods -n keda
NAME READY STATUS RESTARTS AGE
keda-operator-6d89f67964-smksp 0/1 CrashLoopBackOff 8 22m
keda-operator-metrics-apiserver-77598644dd-w7th5 1/1 Running 0 22m
```
Try to fix the issue, and those Pods will become `READY`.
```
k get pods -n keda
NAME READY STATUS RESTARTS AGE
keda-operator-695d978ddb-w5qct 1/1 Running 0 7m53s
keda-operator-metrics-apiserver-77598644dd-f4fjq 1/1 Running 0 7m53s
```
@@ -1,32 +0,0 @@
apiVersion: core.oam.dev/v1alpha2
kind: ApplicationConfiguration
metadata:
name: appconfig-scaler
spec:
components:
- componentName: component-scaler
traits:
- trait:
apiVersion: standard.oam.dev/v1alpha1
kind: Autoscaler
metadata:
name: trait-scaler
spec:
minReplicas: 1
maxReplicas: 10
triggers:
- name: weekday-cron
enabled: true
type: cron
condition:
startAt: "22:47"
duration: 1m
days: "Monday, Tuesday"
replicas: "3"
timezone: Asia/Shanghai
- type: cpu
name: my-cpu-con
enabled: true
condition:
type: Utilization
value: "70"
@@ -1,21 +0,0 @@
apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
name: component-scaler
spec:
workload:
apiVersion: standard.oam.dev/v1alpha1
kind: PodSpecWorkload
spec:
podSpec:
containers:
- name: nginx-scaler
image: nginx:1.9.4
ports:
- containerPort: 80
name: nginx
resources:
limits:
cpu: "1"
requests:
cpu: "0.1"
@@ -1,35 +0,0 @@
apiVersion: core.oam.dev/v1alpha2
kind: ApplicationConfiguration
metadata:
name: appconfig-scaler
spec:
components:
- componentName: component-scaler
traits:
- trait:
apiVersion: standard.oam.dev/v1alpha1
kind: Autoscaler
metadata:
name: trait-scaler
spec:
minReplicas: 1
maxReplicas: 10
triggers:
- name: weekday-cron
enabled: true
type: cron
condition:
startAt: "22:47"
duration: 1m
days: "Monday, Tuesday"
replicas: "3"
timezone: Asia/Shanghai
- name: weekday-cron-2
enabled: true
type: cron
condition:
startAt: "22:49"
duration: 2m
days: "Monday"
replicas: "1"
timezone: Asia/Shanghai
@@ -1,16 +0,0 @@
apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
name: component-scaler
spec:
workload:
apiVersion: standard.oam.dev/v1alpha1
kind: PodSpecWorkload
spec:
podSpec:
containers:
- name: nginx-scaler
image: nginx:1.9.4
ports:
- containerPort: 80
name: nginx
@@ -1,97 +0,0 @@
# cron type Autoscaler
- Apply manifest
```
$ kubectl apply -f standard_v1alpha2_autoscaler.yaml
$ kubectl describe scaledobjects.keda.sh example-scaler
Name: example-scaler
Namespace: default
Labels: scaledObjectName=example-scaler
Annotations: <none>
API Version: keda.sh/v1alpha1
Kind: ScaledObject
Metadata:
Creation Timestamp: 2020-09-28T09:47:11Z
Finalizers:
finalizer.keda.sh
Generation: 1
Owner References:
API Version: standard.oam.dev/v1alpha1
Block Owner Deletion: true
Controller: true
Kind: Autoscaler
Name: example-scaler
UID: 8ae85eb2-6f1c-4d9e-892c-6af22fa2fac5
Resource Version: 478397
Self Link: /apis/keda.sh/v1alpha1/namespaces/default/scaledobjects/example-scaler
UID: 6c02a685-92e4-4667-84f5-c9d781385cbf
Spec:
Max Replica Count: 4
Min Replica Count: 2
Scale Target Ref:
Name: php-apache
Triggers:
Metadata:
Desired Replicas: 4
End: 48 19 * * 1
Start: 48 17 * * 1
Timezone: Asia/Shanghai
Name: weekend-cron
Type: cron
Metadata:
Desired Replicas: 4
End: 48 19 * * 6
Start: 48 17 * * 6
Timezone: Asia/Shanghai
Name: weekend-cron
Type: cron
Status:
Conditions:
Message: ScaledObject is defined correctly and is ready for scaling
Reason: ScaledObjectReady
Status: True
Type: Ready
Message: Scaling is not performed because triggers are not active
Reason: ScalerNotActive
Status: False
Type: Active
External Metric Names:
cron-Asia-Shanghai-4817xx1-4819xx1
cron-Asia-Shanghai-4817xx6-4819xx6
Original Replica Count: 3
Scale Target GVKR:
Group: apps
Kind: Deployment
Resource: deployments
Version: v1
Scale Target Kind: apps/v1.Deployment
Events: <none>
```
- Monitor KEDA ScaledObject and target deployment
```
$ kubectl get scaledobjects.keda.sh --watch
NAME SCALETARGETKIND SCALETARGETNAME TRIGGERS AUTHENTICATION READY ACTIVE AGE
example-scaler php-apache cron 0s
example-scaler php-apache cron 0s
example-scaler php-apache cron Unknown Unknown 0s
example-scaler php-apache cron Unknown Unknown 0s
example-scaler apps/v1.Deployment php-apache cron Unknown Unknown 0s
example-scaler apps/v1.Deployment php-apache cron Unknown Unknown 0s
example-scaler apps/v1.Deployment php-apache cron True Unknown 0s
example-scaler apps/v1.Deployment php-apache cron True False 0s
example-scaler apps/v1.Deployment php-apache cron True False 60s
example-scaler apps/v1.Deployment php-apache cron True True 60s
```
```
$ kubectl get deploy php-apache --watch
NAME READY UP-TO-DATE AVAILABLE AGE
php-apache 3/3 3 3 4m41s
php-apache 3/4 3 3 7m11s
php-apache 3/4 3 3 7m11s
php-apache 3/4 3 3 7m11s
php-apache 3/4 4 3 7m11s
php-apache 4/4 4 4 7m12s
```
@@ -1,22 +0,0 @@
apiVersion: standard.oam.dev/v1alpha1
kind: Autoscaler
metadata:
name: example-scaler
spec:
minReplicas: 2 # optional, Defaults: 1
maxReplicas: 6 # optional, cannot be less that minReplicas
triggers:
- name: weekend-cron
enabled: true
type: cron # cron scaler. 表明 scaler 是 KEDA
condition:
startAt: "10:14" # required. "HHMM"
duration: 2h # required. 持续时长;start hour + duration < 24
days: "Monday,Saturday" # optional. In which days the condition will take effect
replicas: "5" # optional.
timezone: Asia/Shanghai # optional. time zone
targetWorkload: # workloadRef # set by users or be auto-patched by outsiders, like OAM
name: "php-apache"
apiVersion: "extensions/v1beta1" # optional
kind: "Deployment" # optional
@@ -1,26 +0,0 @@
apiVersion: core.oam.dev/v1alpha2
kind: ApplicationConfiguration
metadata:
name: appconfig-scaler
spec:
components:
- componentName: component-scaler
traits:
- trait:
apiVersion: standard.oam.dev/v1alpha1
kind: Autoscaler
metadata:
name: trait-scaler
spec:
minReplicas: 2
maxReplicas: 8
triggers:
- name: weekend-cron
enabled: true
type: cron
condition:
startAt: "16:30"
duration: 2h
days: "Friday,Saturday"
replicas: "4"
timezone: "Asia/Shanghai"
@@ -1,23 +0,0 @@
apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
name: component-scaler
spec:
workload:
apiVersion: apps/v1
kind: Deployment
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx-scaler
image: nginx:1.9.4
ports:
- containerPort: 80
name: nginx
@@ -1,7 +0,0 @@
apiVersion: core.oam.dev/v1alpha2
kind: WorkloadDefinition
metadata:
name: deployments.apps
spec:
definitionRef:
name: deployments.apps
+24 -12
View File
@@ -1,16 +1,18 @@
import "strconv"
output: {
apiVersion: "standard.oam.dev/v1alpha1"
kind: "Autoscaler"
spec: {
minReplicas: parameter.min
maxReplicas: parameter.max
if parameter["cpu"] != _|_ && parameter["cron"] != _|_ {
if parameter["cpuPercent"] != _|_ && parameter["cron"] != _|_ {
triggers: [cpuScaler, cronScaler]
}
if parameter["cpu"] != _|_ && parameter["cron"] == _|_ {
if parameter["cpuPercent"] != _|_ && parameter["cron"] == _|_ {
triggers: [cpuScaler]
}
if parameter["cpu"] == _|_ && parameter["cron"] != _|_ {
if parameter["cpuPercent"] == _|_ && parameter["cron"] != _|_ {
triggers: [cronScaler]
}
}
@@ -20,16 +22,22 @@ cpuScaler: {
type: "cpu"
condition: {
type: "Utilization"
if parameter["cpu"] != _|_ {
value: parameter.cpu
if parameter["cpuPercent"] != _|_ {
value: strconv.FormatInt(parameter.cpuPercent, 10)
}
}
}
cronScaler: {
type: "cron"
if parameter["cron"] != _|_ {
condition: parameter.cron
if parameter["cron"] != _|_ && parameter.cron["replicas"] != _|_ {
condition: {
startAt: parameter.cron.startAt
duration: parameter.cron.duration
days: parameter.cron.days
replicas: strconv.FormatInt(parameter.cron.replicas, 10)
timezone: parameter.cron.timezone
}
}
}
@@ -39,15 +47,19 @@ parameter: {
// +usage=maximal replicas of the workload
max: int
// +usage=specify the value for CPU utilization, like 80, which means 80%
cpu?: string
// +alias=cpu-percent
cpuPercent?: int
// +usage=just for `appfile`, not available for Cli usage
cron?: {
startAt: string
// +usage=the time to start scaling, like `08:00`
startAt: string
// +usage=for how long the scaling will last
duration: string
// +usage=several workdays or weekends, like "Monday, Tuesday"
days: string
replicas: string
// +usage=timezone, like "America/Seattle"
days: string
// +usage=the target replicas to be scaled to
replicas: int
// +usage=timezone, like "America/Los_Angeles"
timezone: string
}
}
+5 -6
View File
@@ -37,12 +37,12 @@ output: {
containerPort: parameter.port
}]
if parameter["cpuRequests"] != _|_ {
if parameter["cpu"] != _|_ {
resources: {
limits:
cpu: parameter.cpuRequests
cpu: parameter.cpu
requests:
cpu: parameter.cpuRequests
cpu: parameter.cpu
}
}
}]
@@ -71,7 +71,6 @@ parameter: {
}
}
}]
// +usage=CPU core requests for the workload, specify like '0.5', '1'.
// +alias=cpu-requests
cpuRequests?: string
// +usage=Number of CPU units for the service, like `500m` (0.5 CPU core), `1` (1 CPU core)
cpu?: string
}
@@ -8,8 +8,6 @@ spec:
appliesToWorkloads:
- webservice
- backend
- deployments.apps
- podspecworkload
workloadRefPath: spec.workloadRef
definitionRef:
name: autoscalers.standard.oam.dev
+1 -1
View File
@@ -73,7 +73,7 @@ func TestGetParameter(t *testing.T) {
{Name: "image", Short: "i", Required: true, Usage: "Which image would you like to use for your service", Default: "", Type: cue.StringKind},
{Name: "port", Short: "p", Required: false, Usage: "Which port do you want customer traffic sent to", Default: int64(8080),
Type: cue.IntKind},
{Name: "cpuRequests", Short: "", Required: false, Usage: "", Default: "", Type: cue.StringKind}},
{Name: "cpu", Short: "", Required: false, Usage: "", Default: "", Type: cue.StringKind}},
params)
params, err = GetParameters("testdata/workloads/test-param.cue")
+4 -4
View File
@@ -10,7 +10,7 @@
name: string
value: string
}]
cpuRequests?: string
cpu?: string
}
output: {
apiVersion: "apps/v1"
@@ -33,12 +33,12 @@ output: {
protocol: "TCP"
name: "default"
}]
if parameter["cpuRequests"] != _|_ {
if parameter["cpu"] != _|_ {
resources: {
limits:
cpu: parameter.cpuRequests
cpu: parameter.cpu
requests:
cpu: parameter.cpuRequests
cpu: parameter.cpu
}
}
}]