vela up support url, fix scale/rollout/metrics to focus on appfile, fix reference doc

Signed-off-by: Hongchao Deng <hongchaodeng1@gmail.com>
This commit is contained in:
Hongchao Deng
2020-11-11 17:13:24 -08:00
parent 49e8aca2bd
commit 4b609e0fff
17 changed files with 233 additions and 281 deletions
+1
View File
@@ -7,6 +7,7 @@ on:
branches: [master]
paths-ignore:
- 'docs/**'
- 'resources/**'
defaults:
run:
working-directory: ./dashboard
+1
View File
@@ -7,6 +7,7 @@ on:
branches: [master]
paths-ignore:
- 'docs/**'
- 'resources/**'
jobs:
build:
+1
View File
@@ -7,6 +7,7 @@ on:
branches: [master]
paths-ignore:
- 'docs/**'
- 'resources/**'
jobs:
build:
+1 -1
View File
@@ -6,7 +6,6 @@
- Appfile
- [Learning Appfile](/en/developers/devex/appfile.md)
- Operating
- [Port Forwarding](/en/developers/port-forward.md)
- [Setting Routes](/en/developers/set-route.md)
- [Setting Auto-scaling Policy](/en/developers/set-autoscale.md)
- [Setting Rollout Strategy](/en/developers/set-rollout.md)
@@ -14,6 +13,7 @@
- Debugging
- [Check Application Logs](/en/developers/check-logs.md)
- [Execute Commands in Container](/en/developers/exec-cmd.md)
- [Port Forwarding](/en/developers/port-forward.md)
- Extensibility
- [Managing Capabilities](/en/developers/cap-center.md)
- Configuring
+1 -1
View File
@@ -1,4 +1,4 @@
# Alternatives Commands
# Alternative Commands
Besides Appfile, KubeVela also provides a set of alternatives commands to deploy the application. Think about "shortcuts" that could generate and apply Appfile without the need to write YAML file manually.
+7 -10
View File
@@ -2,35 +2,32 @@
Appfile is the main user interface to configure application deployment on Vela.
In this tutorial, we will build and deploy an example NodeJS app under [examples/testapp/](https://github.com/oam-dev/kubevela.io/tree/master/examples/testapp).
In this tutorial, we will build and deploy an example NodeJS app under [examples/testapp/](https://github.com/oam-dev/kubevela/tree/master/docs/examples/testapp).
## Prerequisites
- [docker](https://docs.docker.com/get-docker/) installed on the host
- [vela](../../install.md) installed and configured
## 1. Download test app code
git clone and go to the testapp directory:
```bash
$ git clone https://github.com/oam-dev/kubevela.io.git
$ cd kubevela.io/examples/testapp
$ git clone https://github.com/oam-dev/kubevela.git
$ cd kubevela/docs/examples/testapp
```
The example contains NodeJS app code, Dockerfile to build the app.
## 2. Deploy app in one command
In the directory there is a [vela.yaml](https://github.com/oam-dev/kubevela.io/tree/master/examples/testapp/vela.yaml) which follows Appfile format supported by Vela.
In the directory there is a [vela.yaml](https://github.com/oam-dev/kubevela/tree/master/docs/examples/testapp/vela.yaml) which follows Appfile format supported by Vela.
We are going to use it to build and deploy the app.
ATTENTION: change the image field in vela.yaml to something you can push to on your host:
> Or you may try the local testing option introduced in the following section.
**ATTENTION**: change the image field in vela.yaml to something you can push to:
```yaml
image: oamdev/testapp:v1
image: oamdev/testapp:v1 # change this to your image
```
Run the following command:
@@ -169,7 +166,7 @@ Then deploy appfile again to update the application:
$ vela up
```
> Interested in the design of Appfile? A detailed design doc could be found [here](https://github.com/oam-dev/kubevela/blob/master/docs/design/appfile-design.md).
> Interested in the design of Appfile? A detailed design doc could be found [here](https://github.com/oam-dev/kubevela/blob/master/design/vela-core/appfile-design.md).
## What's Next?
@@ -7,8 +7,8 @@ Name | Type | Description | Notes
**Cmd** | **[]string** | | [optional]
**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 6379]
**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]
### WebserviceEnv
+120 -193
View File
@@ -1,235 +1,162 @@
# Automatically scale workloads by resource utilization metrics and cron
Contents:
- [Scale by CPU resource utilization metrics](#Scale by CPU resource utilization metrics)
- [Scale workload by cron](#Scale workload by cron)
## Scale by CPU resource utilization metrics
Introduce how to automatically scale workloads by resource utilization metrics in Cli. Currently, only cpu utilization
is supported.
- 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-requests=0.05
App helloworld deployed
```
By default, the replicas of the workload webservice `helloworld` is.
1. Prepare Appfile:
- Scale the application by CPU utilization metrics
```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
```
$ 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
2. Deploy the application:
```bash
$ vela up
```
- Access the application with heavy requests
3. Access the application with heavy requests
```
$ 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
$ 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
```
On your macOS, you might need to add `sudo` ahead of the command.
- Use Apache HTTP server benchmarking tool `ab` to access the application.
4. Use Apache HTTP server benchmarking tool `ab` to access 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
$ 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
```
Monitor the replicas of the workload, and its replicas gradually increase from one to four.
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%/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
$ 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
Introduce how to automatically scale workloads by cron in Appfile.
- Prepare Appfile
Follow the instructions of [appfile](./devex/appfile.md) to prepare the `vela.yaml` as below.
```yaml
name: testapp
services:
express-server:
# this image will be used in both build and deploy steps
image: zzxwill/kubevela-appfile-demo:v1
build:
# Here more runtime specific build templates will be supported, like NodeJS, Go, Python, Ruby.
docker:
file: Dockerfile
context: .
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"
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
```
- Deploy an application
Run the following command to deploy the application defined in `vela.yaml`.
2. Deploy the application:
```
$ vela up
Parsing vela.yaml ...
Loading templates ...
Building service (express-server)...
#2 [internal] load build definition from Dockerfile
#2 sha256:c25a03ff9861be1da16a316055d11b83778efa23c655d0e69a902487bbf3c303
#2 transferring dockerfile: 37B 0.0s done
#2 DONE 0.1s
...
pushing image (zzxwill/kubevela-appfile-demo:v1)...
The push refers to repository [docker.io/zzxwill/kubevela-appfile-demo]
1893e9ad9204: Preparing
b60a6f0fd043: Preparing
...
89ae5c4ee501: Layer already exists
b60a6f0fd043: Layer already exists
1893e9ad9204: Pushed
v1: digest: sha256:11e48ce2205a1d92c1c920b3a3f41d3ee357fa2794261dc0d0e8010068e68da6 size: 1365
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
```bash
$ vela up
```
- Check the replicas and wait for the scaling to take effect
Check the replicas of the application, there is one replica.
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
$ 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
```
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.
+50 -19
View File
@@ -6,26 +6,55 @@ with the help of `metric` capability.
Let's run [`christianhxc/gorandom:1.0`](https://github.com/christianhxc/prometheus-tutorial) as an example app.
The app will emit random latencies as metrics.
```bash
$ vela svc deploy metricapp -t webservice --image christianhxc/gorandom:1.0 --port 8080
```
Then add metric by:
1. Prepare Appfile:
```bash
$ vela metric metricapp
Adding metric for app metricapp
⠋ Deploying ...
✅ Application Deployed Successfully!
- Name: metricapp
Type: webservice
HEALTHY Ready: 1/1
Routes:
- ✅ metric: Monitoring port: 8080, path: /metrics, format: prometheus, schema: http.
Last Deployment:
Created at: 2020-11-02 14:31:56 +0800 CST
Updated at: 2020-11-02T14:32:00+08:00
```
```bash
$ cat <<EOF > vela.yaml
name: metricapp
services:
metricapp:
type: webservice
image: christianhxc/gorandom:1.0
port: 8080
metric:
enabled: true
format: prometheus
path: /metrics
port: 0
scheme: http
EOF
```
2. Deploy the application:
```bash
$ vela up
```
3. Check status:
```bash
$ vela status metricapp
About:
Name: metricapp
Namespace: default
Created at: 2020-11-11 17:00:59.436347573 -0800 PST
Updated at: 2020-11-11 17:01:06.511064661 -0800 PST
Services:
- Name: metricapp
Type: webservice
HEALTHY Ready: 1/1
Traits:
- ✅ metric: Monitoring port: 8080, path: /metrics, format: prometheus, schema: http.
Last Deployment:
Created at: 2020-11-11 17:00:59 -0800 PST
Updated at: 2020-11-11T17:01:06-08:00
```
The metrics trait will automatically discover port and label to monitor if no parameters specified.
If more than one ports found, it will choose the first one by default.
@@ -34,7 +63,9 @@ If more than one ports found, it will choose the first one by default.
## Verify that the metrics are collected on prometheus
```bash
kubectl --namespace monitoring port-forward `k -n monitoring get pods -l prometheus=oam -o name` 9090
kubectl --namespace monitoring port-forward `kubectl -n monitoring get pods -l prometheus=oam -o name` 9090
```
Then access the prometheus dashboard via http://localhost:9090/targets
![Prometheus Dashboard](../../../resources/metrics.jpg)
+5 -5
View File
@@ -29,8 +29,8 @@ About:
Name: testapp
Namespace: default
Created at: ...
Updated at: ...
Created at: 2020-11-04 16:34:43.762730145 -0800 PST
Updated at: 2020-11-11 16:21:37.761158941 -0800 PST
Services:
@@ -38,15 +38,15 @@ Services:
Type: webservice
HEALTHY Ready: 1/1
Last Deployment:
Created at: ...
Updated at: ...
Created at: 2020-11-11 16:21:37 -0800 PST
Updated at: 2020-11-11T16:21:37-08:00
Routes:
- route: Visiting URL: http://example.com IP: <ingress-IP-address>
```
**In [kind cluster setup](../../install.md#kind)**, you can visit the service via localhost:
> If not in kind cluster, replace localhost with ingress address
> If not in kind cluster, replace 'localhost' with ingress address
```
$ curl -H "Host:example.com" http://localhost/testapp
+1
View File
@@ -116,6 +116,7 @@ This will install KubeVela server component and its dependency components.
- [Prometheus Stack](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack)
- [Cert-manager](https://cert-manager.io/)
- [Flagger](https://flagger.app/)
- [KEDA](https://keda.sh/)
The config has been saved in a ConfigMap in "vela-system/vela-config":
+2 -2
View File
@@ -8,7 +8,7 @@ In this tutorial, we use Crossplane as the cloud resource operator for Kubernete
<details>
To make this process more easier, we provide all the needed scripts in [this folder](https://github.com/oam-dev/kubevela.io/tree/master/examples/kubecondemo).
To make this process more easier, we provide all the needed scripts in [this folder](https://github.com/oam-dev/kubevela/tree/master/docs/examples/kubecondemo).
Please do:
```console
@@ -58,7 +58,7 @@ services:
...
```
> Please check the full application sample in [tutorial folder](https://github.com/oam-dev/kubevela.io/blob/master/examples/kubecondemo/vela.yaml).
> Please check the full application sample in [tutorial folder](https://github.com/oam-dev/kubevela/blob/master/docs/examples/kubecondemo/vela.yaml).
Next, we could deploy the application with `$ vela up`
+2 -39
View File
@@ -8,45 +8,8 @@ Make sure you have finished and verified the installation following [this guide]
## Step 2: Deploy Your First Application
**vela init**
```bash
$ vela init --render-only
Welcome to use KubeVela CLI! Please describe your application.
Environment: default, namespace: default
? What is the domain of your application service (optional): example.com
? What is your email (optional, used to generate certification):
? What would you like to name your application (required): testapp
? Choose the workload type for your application (required, e.g., webservice): webservice
? What would you like to name this webservice (required): testsvc
? Which image would you like to use for your service (required): crccheck/hello-world
? Which port do you want customer traffic sent to (optional, default is 80): 8000
Deployment config is rendered and written to vela.yaml
```
In the current directory, you will find a generated `vela.yaml` file (i.e., an Appfile):
```yaml
createTime: ...
updateTime: ...
name: testapp
services:
testsvc:
type: webservice
image: crccheck/hello-world
port: 8000
route:
domain: testsvc.example.com
```
**vela up**
```bash
$ vela up
$ vela up -f https://raw.githubusercontent.com/oam-dev/kubevela/master/docs/examples/vela.yaml
Parsing vela.yaml ...
Loading templates ...
@@ -111,7 +74,7 @@ Hello World
Congratulations! You have just deployed an app using KubeVela. Here are some recommended next steps:
- Learn about the project's [motivation](./introduction.md) and [architecture](./design.md)
- Try out more [tutorials](./developers/config-enviroments.md)
- Try out more [tutorials](./developers/devex/appfile.md)
- Join our community [Slack](https://cloud-native.slack.com/archives/C01BLQ3HTJA) and/or [Gitter](https://gitter.im/oam-dev/community)
Welcome onboard and sail Vela!
+9 -9
View File
@@ -36,15 +36,15 @@ services:
# scheme: "http"
# enabled: true
# autoscale:
# min: 1
# max: 4
# cron:
# startAt: "14:00"
# duration: "2h"
# days: "Monday, Thursday"
# replicas: "2"
# timezone: "America/Seattle"
# autoscale:
# min: 1
# max: 4
# cron:
# startAt: "14:00"
# duration: "2h"
# days: "Monday, Thursday"
# replicas: "2"
# timezone: "America/Seattle"
# pi:
# image: perl
+8
View File
@@ -0,0 +1,8 @@
name: testapp
services:
testsvc:
type: webservice
image: crccheck/hello-world
port: 8000
route:
domain: testsvc.example.com
+22
View File
@@ -5,8 +5,10 @@ import (
"context"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
"github.com/crossplane/oam-kubernetes-runtime/apis/core/v1alpha2"
"github.com/crossplane/oam-kubernetes-runtime/pkg/oam"
@@ -72,12 +74,32 @@ type AppfileOptions struct {
Env *types.EnvMeta
}
func saveRemoteAppfile(url string) (string, error) {
resp, err := http.Get(url)
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
dest := "vela.yaml"
return dest, ioutil.WriteFile(dest, body, 0600)
}
func (o *AppfileOptions) Run(filePath string) error {
var app *appfile.AppFile
var err error
o.IO.Info("Parsing vela.yaml ...")
if filePath != "" {
if strings.HasPrefix(filePath, "https://") || strings.HasPrefix(filePath, "http://") {
filePath, err = saveRemoteAppfile(filePath)
if err != nil {
return err
}
}
app, err = appfile.LoadFromFile(filePath)
} else {
app, err = appfile.Load()
Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB