Version: v1.0

Expose Application

⚠️ 本章节要求当前集群已经安装 ingress 。

如果我们需要将 application 中的服务暴露对外,只需要在该 application 中添加 ingress 的 trait。

我们使用 kubectl 查看 ingress 数据结构。

  1. $ kubectl vela show ingress
  2. # Properties
  3. +--------+------------------------------------------------------------------------------+----------------+----------+---------+
  4. | NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
  5. +--------+------------------------------------------------------------------------------+----------------+----------+---------+
  6. | http | Specify the mapping relationship between the http path and the workload port | map[string]int | true | |
  7. | domain | Specify the domain you want to expose | string | true | |
  8. +--------+------------------------------------------------------------------------------+----------------+----------+---------+

随后,修改且部署下面 application :

  1. # vela-app.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: first-vela-app
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. traits:
  14. - type: ingress
  15. properties:
  16. domain: testsvc.example.com
  17. http:
  18. "/": 8000
  1. $ kubectl apply -f https://raw.githubusercontent.com/oam-dev/kubevela/master/docs/examples/vela-app.yaml
  2. application.core.oam.dev/first-vela-app created

当状态 PHASErunningHEALTHYtrue,说明 application 已经被正确部署:

  1. $ kubectl get application first-vela-app -w
  2. NAME COMPONENT TYPE PHASE HEALTHY STATUS AGE
  3. first-vela-app express-server webservice healthChecking 14s
  4. first-vela-app express-server webservice running true 42s

同时,我们可以通过下面命令行查看 trait 的详情:

  1. $ kubectl get application first-vela-app -o yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: first-vela-app
  6. namespace: default
  7. spec:
  8. ...
  9. services:
  10. - healthy: true
  11. name: express-server
  12. traits:
  13. - healthy: true
  14. message: 'Visiting URL: testsvc.example.com, IP: 47.111.233.220'
  15. type: ingress
  16. status: running
  17. ...

最后,我们可以通过以下方式访问部署的服务。

  1. $ curl -H "Host:testsvc.example.com" http://<your ip address>/
  2. <xmp>
  3. Hello World
  4. ## .
  5. ## ## ## ==
  6. ## ## ## ## ## ===
  7. /""""""""""""""""\___/ ===
  8. ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
  9. \______ o _,/
  10. \ \ _,'
  11. `'--.._\..--''
  12. </xmp>