Learning Appfile Step by Step

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/.

Prerequisites

1. Download test app code

git clone and go to the testapp directory:

  1. $ git clone https://github.com/oam-dev/kubevela.git
  2. $ 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 which follows Appfile format supported by Vela. We are going to use it to build and deploy the app.

NOTE: please change oamdev to your own registry account so you can push. Or, you could try the alternative approach in Local testing without pushing image remotely section.

  1. image: oamdev/testapp:v1 # change this to your image

Run the following command:

  1. $ vela up
  2. Parsing vela.yaml ...
  3. Loading templates ...
  4. Building service (express-server)...
  5. Sending build context to Docker daemon 71.68kB
  6. Step 1/10 : FROM mhart/alpine-node:12
  7. ---> 9d88359808c3
  8. ...
  9. pushing image (oamdev/testapp:v1)...
  10. ...
  11. Rendering configs for service (express-server)...
  12. Writing deploy config to (.vela/deploy.yaml)
  13. Applying deploy configs ...
  14. Checking if app has been deployed...
  15. App has not been deployed, creating a new deployment...
  16. App has been deployed 🚀🚀🚀
  17. Port forward: vela port-forward testapp
  18. SSH: vela exec testapp
  19. Logging: vela logs testapp
  20. App status: vela status testapp
  21. Service status: vela status testapp --svc express-server

Check the status of the service:

  1. $ vela status testapp
  2. About:
  3. Name: testapp
  4. Namespace: default
  5. Created at: 2020-11-02 11:08:32.138484 +0800 CST
  6. Updated at: 2020-11-02 11:08:32.138485 +0800 CST
  7. Services:
  8. - Name: express-server
  9. Type: webservice
  10. HEALTHY Ready: 1/1
  11. Last Deployment:
  12. Created at: 2020-11-02 11:08:33 +0800 CST
  13. Updated at: 2020-11-02T11:08:32+08:00
  14. Routes:

Alternative: Local testing without pushing image remotely

If you have local kind cluster running, you may try the local push option. No remote container registry is needed in this case.

Add local option to build:

  1. build:
  2. # push image into local kind cluster without remote transfer
  3. push:
  4. local: kind
  5. docker:
  6. file: Dockerfile
  7. context: .

Then deploy the app to kind:

  1. $ vela up

(Advanced) Check rendered manifests

By default, Vela renders the final manifests in .vela/deploy.yaml:

  1. apiVersion: core.oam.dev/v1alpha2
  2. kind: ApplicationConfiguration
  3. metadata:
  4. name: testapp
  5. namespace: default
  6. spec:
  7. components:
  8. - componentName: express-server
  9. ---
  10. apiVersion: core.oam.dev/v1alpha2
  11. kind: Component
  12. metadata:
  13. name: express-server
  14. namespace: default
  15. spec:
  16. workload:
  17. apiVersion: apps/v1
  18. kind: Deployment
  19. metadata:
  20. name: express-server
  21. ...
  22. ---
  23. apiVersion: core.oam.dev/v1alpha2
  24. kind: HealthScope
  25. metadata:
  26. name: testapp-default-health
  27. namespace: default
  28. spec:
  29. ...

[Optional] Configure another workload type

By now we have deployed a Web Service, which is the default workload type in KubeVela. We can also add another service of Task type in the same app:

  1. services:
  2. pi:
  3. type: task
  4. image: perl
  5. cmd: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
  6. express-server:
  7. ...

Then deploy Appfile again to update the application:

  1. $ vela up

Interested in the more details of Appfile? Learn Full Schema of Appfile

What’s Next?

Congratulations! You have just deployed an app using Vela.

Some tips that you can have more play with your app: