mirror of
https://github.com/kubevela/kubevela.git
synced 2026-04-21 10:07:26 +00:00
Merge pull request #500 from zzxwill/docs-scale
Add Autoscaler docs and support cli and appfile
This commit is contained in:
49
charts/vela-core/templates/defwithtemplate/autoscale.yaml
Normal file
49
charts/vela-core/templates/defwithtemplate/autoscale.yaml
Normal file
@@ -0,0 +1,49 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
name: autoscale
|
||||
annotations:
|
||||
definition.oam.dev/apiVersion: standard.oam.dev/v1alpha1
|
||||
definition.oam.dev/kind: Autoscaler
|
||||
definition.oam.dev/description: "Automatically scale workloads by cron or resource utilization"
|
||||
spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- backend
|
||||
- deployments.apps
|
||||
- podspecworkload
|
||||
workloadRefPath: spec.workloadRef
|
||||
definitionRef:
|
||||
name: autoscalers.standard.oam.dev
|
||||
extension:
|
||||
template: |
|
||||
output: {
|
||||
apiVersion: "standard.oam.dev/v1alpha1"
|
||||
kind: "Autoscaler"
|
||||
spec: {
|
||||
minReplicas: parameter.minReplicas
|
||||
maxReplicas: parameter.maxReplicas
|
||||
triggers: [{
|
||||
name: parameter.name
|
||||
type: parameter.type
|
||||
condition: {
|
||||
startAt: parameter.startAt
|
||||
duration: parameter.duration
|
||||
days: parameter.days
|
||||
replicas: parameter.replicas
|
||||
timezone: parameter.timezone
|
||||
}
|
||||
}, ...]
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
@@ -19,4 +19,12 @@ data:
|
||||
"name": "flagger",
|
||||
"namespace": "vela-system",
|
||||
"version": "1.2.0"
|
||||
}
|
||||
}
|
||||
keda: |
|
||||
{
|
||||
"repo": "kedacore",
|
||||
"urL": "https://kedacore.github.io/charts",
|
||||
"name": "keda",
|
||||
"namespace": "keda",
|
||||
"version": "2.0.0-beta1.2"
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ Learn and use KubeVela with tutorials and user stories.
|
||||
- [Setting Up Deployment Environment](developers/config-enviroments.md)
|
||||
- [Initializing Application](developers/app-init.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
docs/developers/set-autoscale.md
Normal file
65
docs/developers/set-autoscale.md
Normal 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.
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# Setting Auto-scaling Policy
|
||||
|
||||
> TODO
|
||||
30
hack/vela-templates/cue/autoscale.cue
Normal file
30
hack/vela-templates/cue/autoscale.cue
Normal file
@@ -0,0 +1,30 @@
|
||||
output: {
|
||||
apiVersion: "standard.oam.dev/v1alpha1"
|
||||
kind: "Autoscaler"
|
||||
spec: {
|
||||
minReplicas: parameter.minReplicas
|
||||
maxReplicas: parameter.maxReplicas
|
||||
triggers: [{
|
||||
name: parameter.name
|
||||
type: parameter.type
|
||||
condition: {
|
||||
startAt: parameter.startAt
|
||||
duration: parameter.duration
|
||||
days: parameter.days
|
||||
replicas: parameter.replicas
|
||||
timezone: parameter.timezone
|
||||
}
|
||||
}, ...]
|
||||
}
|
||||
}
|
||||
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,15 +1,19 @@
|
||||
apiVersion: core.oam.dev/v1alpha2
|
||||
kind: TraitDefinition
|
||||
metadata:
|
||||
name: autoscalers.standard.oam.dev
|
||||
name: autoscale
|
||||
annotations:
|
||||
definition.oam.dev/apiVersion: standard.oam.dev/v1alpha1
|
||||
definition.oam.dev/kind: Autoscaler
|
||||
definition.oam.dev/description: "Automatically scale workloads by cron or resource utilization"
|
||||
spec:
|
||||
appliesToWorkloads:
|
||||
- webservice
|
||||
- backend
|
||||
- deployments.apps
|
||||
- podspecworkload
|
||||
workloadRefPath: spec.workloadRef
|
||||
definitionRef:
|
||||
name: autoscalers.standard.oam.dev
|
||||
name: autoscalers.standard.oam.dev
|
||||
extension:
|
||||
template: |
|
||||
@@ -192,7 +192,7 @@ func printComponentStatus(ctx context.Context, c client.Client, ioStreams cmduti
|
||||
ioStreams.Infof(" %s %s\n", healthColor.Sprint(healthStatus), healthColor.Sprint(healthInfo))
|
||||
|
||||
// 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)
|
||||
|
||||
Reference in New Issue
Block a user