Skip to content

Access Service in VelaD

qiaozp edited this page Aug 10, 2022 · 1 revision

This document will show you how to access the service running in VelaD.

Background

Typically, you can expose service in cluster in several ways.

  1. LoadBalancer type Service
  2. NodePort type Service
  3. Ingress API

First two types both have some limitations. In VelaD cluster, exposing service through Ingress API is out of box. In KubeVela, we can use the gateway trait to expose service through Ingress API.

Using gateway trait

In VelaD, we have installed a default Ingress Controller, which is needed to use Ingress API. The default Ingress controller is Traefik. If you want to switch to other like Nginx Ingress Controller, see Switch to Nginx Ingress Controller.

After running velad install command, there is one hint printed to the screen.

💻  When using gateway trait, you can access with 127.0.0.1:8090

It means you can access the Application with gateway trait through http://127.0.0.1:8090.

For example, Run command below to apply app in VelaD cluster:

cat << EOF | vela up -f -
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: example
spec:
  components:
    - name: hello-world
      type: webservice
      properties:
        image: crccheck/hello-world
      traits:
        - type: gateway
          properties:
            domain: testsvc.example.com
            class: traefik
            http:
              "/": 8000
EOF

Then access this app by:

curl -H "Host: testsvc.example.com" http://localhost:8090/

The output like:

<pre>
Hello World


                                       ##         .
                                 ## ## ##        ==
                              ## ## ## ## ##    ===
                           /""""""""""""""""\___/ ===
                      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
                           \______ o          _,/
                            \      \       _,'
                             `'--.._\..--''
</pre>

Switch To Nginx Ingress Controller

There are three steps to switch to nginx ingress controller and using gateway trait.

  1. Uninstall Traefik

Helm CLI is needed

helm uninstall traefik --namespace kube-system
  1. Enable Ingress-nginx Addon and dependent FluxCD addon
vela addon enable fluxcd
vela addon enable ingress-nginx
  1. Port-forward Nginx Ingress Controller To Localhost
vela port-forward addon-ingress-nginx -n vela-system

We don't need to do port-forwarding for Traefik in the last section because we when velad install, a container is created for that.

Using the app above, only change class: traefik to class: nginx in the gateway trait section, run the command below:

cat << EOF | vela up -f -
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: example
spec:
  components:
    - name: hello-world
      type: webservice
      properties:
        image: crccheck/hello-world
      traits:
        - type: gateway
          properties:
            domain: testsvc.example.com
            class: nginx
            http:
              "/": 8000
EOF
Now you can access the services through Ingress like:

```shell
curl -H "Host: testsvc.example.com" http://localhost:8080/