Wrongly rebased newly merged requests from comments, fixed it.

co-authored-by: 天元 <jianbo.sjb@alibaba-inc.com>
This commit is contained in:
zzxwill
2020-11-04 11:39:05 +08:00
co-authored by 天元
parent d082502406
commit 81d40a2f51
8 changed files with 90 additions and 30 deletions
@@ -16,14 +16,14 @@ spec:
definitionRef:
name: autoscalers.standard.oam.dev
extension:
template: |-
template: |
output: {
apiVersion: "standard.oam.dev/v1alpha1"
kind: "Autoscaler"
spec: {
minReplicas: parameter.minReplicas
maxReplicas: parameter.maxReplicas
triggers: [...{
triggers: [{
name: parameter.name
type: parameter.type
condition: {
@@ -33,18 +33,17 @@ spec:
replicas: parameter.replicas
timezone: parameter.timezone
}
}]
}, ...]
}
}
parameter: {
minReplicas: *1 | int
maxReplicas: *4 | int
name: *"" | string
type: *"cron" | string
startAt: *"00:01" | string
duration: *"" | string
days: *"Monday, Tuesday" | string
replicas: *"2" | string
timezone: *"Asia/Shanghai" | string
}
parameter: {
minReplicas: *1 | int
maxReplicas: *4 | int
name: *"" | string
type: *"cron" | string
startAt: string
duration: string
days: string
replicas: *"2" | string
timezone: *"Asia/Shanghai" | string
}
+1 -1
View File
@@ -12,7 +12,7 @@ Learn and use KubeVela with tutorials and user stories.
- [Setting Up Deployment Environment](developers/config-enviroments.md)
- [Deploying Application](developers/deploy-app.md)
- [Setting Routes](developers/set-route.md)
- [Setting Auto-scaling Policy](developers/set-autoscaling.md)
- [Setting Auto-scaling Policy](developers/set-autoscale.md)
- [Setting Rollout Strategy](developers/set-rollout.md)
- [Monitoring Application](developers/set-metrics.md)
- [Using Appfile](developers/devex/appfile.md)
+65
View File
@@ -0,0 +1,65 @@
# Automatically scale workload by cron or resource utilization
## Prerequisites
- [ ] [KEDA v2.0 Beta](https://keda.sh/blog/keda-2.0-beta/)
KEDA will be automatically deployed during vela installation, so just run the following command.
```shell
$ vela install
```
## Scale an application
- 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
App helloworld deployed
```
Check the replicas of Deployment `frontend` which is deployed by workload webservice `helloworld` and there is one replica.
(TODO: The command below needs to be replaced with `vela show` to check the replicas.)
```
$ kubectl get deploy frontend
NAME READY UP-TO-DATE AVAILABLE AGE
frontend 1/1 1 1 2m52s
```
- Scale the application by `cron`
```
$ vela autoscale helloworld --svc frontend --minReplicas 1 --maxReplicas 4 --replicas 2 --name cron-test --startAt 21:00 --duration 2h --days "Monday, Tuesday"
Adding autoscale for app frontend
⠋ Deploying ...
✅ Application Deployed Successfully!
- Name: frontend
Type: webservice
HEALTHY Ready: 1/1
Last Deployment:
Created at: 2020-11-03 20:53:50 +0800 CST
Updated at: 2020-11-03T21:01:20+08:00
Traits:
- autoscale:
maxReplicas=4
minReplicas=1
replicas=2
startAt=21:00
timezone=Asia/Shanghai
days=Monday, Tuesday
name=cron-test
type=cron
duration=2h
```
The time is `21:07` which is in the active period of the trait which started at `21:00` and the duration is two hours.
Check the replicas of Deployment `frontend` again, it has been scaled to 2.
```
$ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
frontend 2/2 2 2 8m42s
```
Wait after the period ends, the replicas will be one eventually.
-3
View File
@@ -1,3 +0,0 @@
# Setting Auto-scaling Policy
> TODO
+5 -5
View File
@@ -4,7 +4,7 @@ output: {
spec: {
minReplicas: parameter.minReplicas
maxReplicas: parameter.maxReplicas
triggers: [...{
triggers: [{
name: parameter.name
type: parameter.type
condition: {
@@ -14,7 +14,7 @@ output: {
replicas: parameter.replicas
timezone: parameter.timezone
}
}]
}, ...]
}
}
parameter: {
@@ -22,9 +22,9 @@ parameter: {
maxReplicas: *4 | int
name: *"" | string
type: *"cron" | string
startAt: *"00:01" | string
duration: *"" | string
days: *"Monday, Tuesday" | string
startAt: string
duration: string
days: string
replicas: *"2" | string
timezone: *"Asia/Shanghai" | string
}
+1 -1
View File
@@ -196,7 +196,7 @@ func printComponentStatus(ctx context.Context, c client.Client, ioStreams cmduti
ioStreams.Infof(" Updated at: %v\n", app.UpdateTime.Format(time.RFC3339))
// workload Must found
ioStreams.Infof(" Routes:\n")
ioStreams.Infof(" Traits:\n")
workloadStatus, _ := getWorkloadStatusFromAppConfig(appConfig, compName)
for _, tr := range workloadStatus.Traits {
traitType, traitInfo, err := traitCheckLoop(ctx, c, tr.Reference, compName, appConfig, app, 60*time.Second)
@@ -21,21 +21,19 @@ import (
"fmt"
"time"
"github.com/crossplane/oam-kubernetes-runtime/pkg/oam/discoverymapper"
cpv1alpha1 "github.com/crossplane/crossplane-runtime/apis/core/v1alpha1"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/oam-kubernetes-runtime/pkg/oam/discoverymapper"
"github.com/crossplane/oam-kubernetes-runtime/pkg/oam/util"
oamutil "github.com/crossplane/oam-kubernetes-runtime/pkg/oam/util"
"github.com/go-logr/logr"
"github.com/oam-dev/kubevela/api/v1alpha1"
"github.com/oam-dev/kubevela/pkg/controller/common"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"github.com/oam-dev/kubevela/api/v1alpha1"
"github.com/oam-dev/kubevela/pkg/controller/common"
)
const (
@@ -69,6 +67,7 @@ func (r *AutoscalerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
ctx := context.Background()
var scaler v1alpha1.Autoscaler
if err := r.Get(ctx, req.NamespacedName, &scaler); err != nil {
log.Error(err, "Failed to get trait", "traitName", scaler.Name)
return ReconcileWaitResult, client.IgnoreNotFound(err)
}
log.Info("Retrieved trait Autoscaler", "APIVersion", scaler.APIVersion, "Kind", scaler.Kind)