magneticio/vamp

does implement grouping virtual host?

bench87 opened this issue · 11 comments

simillar #126
but i dont know what i describe DSL, plz help me

Could you explain the use-case you'd like to achieve in more detail? tnx!

If I understand your question correctly you would like to use virtual hostnames as conditions to split routing with?

You could use the hostname shortcode to setup routing conditions:
https://vamp.io/documentation/using-vamp/v0.9.5/conditions/#create-a-condition

You can use routing to URL's, as described here: https://vamp.io/documentation/using-vamp/v0.9.5/gateways/#vamp-managed-and-external-routes

and you can use conditions with full ACL's, when not supported by our build-in "short-codes:
https://vamp.io/documentation/using-vamp/v0.9.5/conditions/#create-a-condition

Here are examples of ACL's that look for specific paths:
https://serverfault.com/questions/127491/haproxy-forward-to-a-different-web-server-based-on-uri

I want to route with 1 virtual host and many paths

for example, I run A and B app on vamp

A app : vamp.server.com/a
B app: vamp.server.com/b

A and B have same vamp.server.com virtual host name

for example for haproxy config like blow

frontend marathon_http_in
bind *:80
mode http
acl A_path path_beg -i /a
acl A_host hdr(host) -i vamp.server.com
use_backend A_backend if A_path A_host

acl B_path path_beg -i /b
acl B_host hdr(host) -i vamp.server.com
use_backend B_backend if B_path B_host

I am so sorry for my terrible english ....

Yes, this is possible. Let me explain how to achieve this:

  • you need to add your virtual hostname to your Vamp gateway, so it can resolve on port 80. You would typically do this on the "external" Vamp gateway, which is static. Example:
virtual_hosts:
- 9050.sava.vamp
- vamp.server.com

More examples: https://vamp.io/documentation/using-vamp/v0.9.5/virtual-hosts/#custom-virtual-hosts

Now you need to add a condition to your internal gateway routes that detects for the paths that are relevant for you. You can simply enter the ACL in the route condition field and put the condition strength to 100% (make sure to keep the weight to 0% for this route as you probably only want to have traffic with that specific path to land on this route), f.e. "path_beg -i /a" (without quotes)

Or you enter it in the gateway YAML:

condition:
      condition: path_beg -i  /a

Now if you would like to rewrite the path you can do like this:

rewrites:
    - path: / if path_beg /a

Hope this helps?

thank you so much ! i will try it

did it work for you @bench87 ?

@olafmol sorry, I think not working..

A app blueprint is blow

name: sava:1.0
kind: deployment
metadata: {}
lookup_name: 6528060b3dd511a46aa9ef048fbfc27505d2a970
clusters:
  sava:
    metadata: {}
    services:
    - status:
        intention: Deployment
        since: '2018-03-14T13:09:17.104Z'
        phase:
          name: Done
          since: '2018-03-14T13:09:50.153Z'
      breed:
        name: sava:1.0.0
        kind: breed
        metadata: {}
        deployable:
          definition: magneticio/sava:1.0.0
        ports:
          webport: 8080/http
        environment_variables: {}
        constants: {}
        arguments: []
        dependencies: {}
      environment_variables: {}
      scale:
        cpu: 0.2
        memory: 64.00MB
        instances: 1
      instances:
      - name: vamp_deployment-6528060b3dd511a46aa9ef048fbfc27505d2a970-service-f6688d352a6f996f10f41a736bf661babec6a45f.e86e2cae-2788-11e8-ad27-5276cae1e0fd
        host: 192.168.190.56
        ports:
          webport: 59376
        deployed: true
        metadata: {}
      arguments:
      - privileged: 'true'
      health_checks:
      - path: /
        port: webport
        initial_delay: 10s
        timeout: 5s
        interval: 10s
        failures: 10
        protocol: HTTP
      dependencies: {}
      dialects: {}
      health:
        staged: 0
        running: 1
        healthy: 1
        unhealthy: 0
    gateways:
      webport:
        sticky: null
        virtual_hosts:
        - webport.sava.sava-1-0.vamp
        - vamp.nginx.dev.toss.bz
        routes:
          sava:1.0.0:
            lookup_name: 2ae7483f14e4cfc6433ee05c18ea191663a1f915
            weight: 100%
            balance: default
            condition:
              condition: hdr(host) path_beg -i /a
            condition_strength: 100%
            rewrites:
            - path: / if path_beg /a
    dialects: {}
ports:
  sava.webport: '40018'
environment_variables: {}
hosts:
  sava: 172.17.0.1
dialects: {}

b app blueprint is blow

name: sava:1.1
kind: deployment
metadata: {}
lookup_name: 95a20c54fabafc68f41a34ae71d3057466a52c52
clusters:
  sava:
    metadata: {}
    services:
    - status:
        intention: Deployment
        since: '2018-03-14T13:14:53.098Z'
        phase:
          name: Done
          since: '2018-03-14T13:15:30.164Z'
      breed:
        name: sava:1.0.0
        kind: breed
        metadata: {}
        deployable:
          definition: magneticio/sava:1.1.0
        ports:
          webport: 8080/http
        environment_variables: {}
        constants: {}
        arguments: []
        dependencies: {}
      environment_variables: {}
      scale:
        cpu: 0.2
        memory: 64.00MB
        instances: 1
      instances:
      - name: vamp_deployment-95a20c54fabafc68f41a34ae71d3057466a52c52-service-f6688d352a6f996f10f41a736bf661babec6a45f.b311a1e0-2789-11e8-ad27-5276cae1e0fd
        host: 192.168.190.56
        ports:
          webport: 60799
        deployed: true
        metadata: {}
      arguments:
      - privileged: 'true'
      health_checks:
      - path: /
        port: webport
        initial_delay: 10s
        timeout: 5s
        interval: 10s
        failures: 10
        protocol: HTTP
      dependencies: {}
      dialects: {}
      health:
        staged: 0
        running: 1
        healthy: 1
        unhealthy: 0
    gateways:
      webport:
        sticky: null
        virtual_hosts:
        - webport.sava.sava-1-1.vamp
        - vamp.nginx.dev.toss.bz
        routes:
          sava:1.0.0:
            lookup_name: a9e7ef287ef4c4666d501affa3558d7d51949a8
            weight: 100%
            balance: default
            condition:
              condition: hdr(host) path_beg -i /b
            condition_strength: 100%
            rewrites:
            - path: / if path_beg /b
    dialects: {}
ports:
  sava.webport: '40020'
environment_variables: {}
hosts:
  sava: 172.17.0.1
dialects: {}

Hi @bench87 you could set 1 single gateway for all services (breeds) and then create a route with the specific condition and rewrite rules for each service you want to handle. Ie seperate out the gateway into a seperate gateway blueprint and point these to the services. Let me know if you need any additional assistance.

@olafmol I dont understand T_T

@olafmol It resolved

Great! :)