Version: v1.0
Expose Application
⚠️ 本章节要求当前集群已经安装 ingress 。
如果我们需要将 application 中的服务暴露对外,只需要在该 application 中添加 ingress 的 trait。
我们使用 kubectl 查看 ingress 数据结构。
$ kubectl vela show ingress# Properties+--------+------------------------------------------------------------------------------+----------------+----------+---------+| NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |+--------+------------------------------------------------------------------------------+----------------+----------+---------+| http | Specify the mapping relationship between the http path and the workload port | map[string]int | true | || domain | Specify the domain you want to expose | string | true | |+--------+------------------------------------------------------------------------------+----------------+----------+---------+
随后,修改且部署下面 application :
# vela-app.yamlapiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: first-vela-appspec:components:- name: express-servertype: webserviceproperties:image: crccheck/hello-worldport: 8000traits:- type: ingressproperties:domain: testsvc.example.comhttp:"/": 8000
$ kubectl apply -f https://raw.githubusercontent.com/oam-dev/kubevela/master/docs/examples/vela-app.yamlapplication.core.oam.dev/first-vela-app created
当状态 PHASE 为 running 且 HEALTHY 为 true,说明 application 已经被正确部署:
$ kubectl get application first-vela-app -wNAME COMPONENT TYPE PHASE HEALTHY STATUS AGEfirst-vela-app express-server webservice healthChecking 14sfirst-vela-app express-server webservice running true 42s
同时,我们可以通过下面命令行查看 trait 的详情:
$ kubectl get application first-vela-app -o yamlapiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: first-vela-appnamespace: defaultspec:...services:- healthy: truename: express-servertraits:- healthy: truemessage: 'Visiting URL: testsvc.example.com, IP: 47.111.233.220'type: ingressstatus: running...
最后,我们可以通过以下方式访问部署的服务。
$ curl -H "Host:testsvc.example.com" http://<your ip address>/<xmp>Hello World## .## ## ## ==## ## ## ## ## ===/""""""""""""""""\___/ ===~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~\______ o _,/\ \ _,'`'--.._\..--''</xmp>