Skip to content

Latest commit

 

History

History
56 lines (45 loc) · 2.41 KB

add-tcp-route.md

File metadata and controls

56 lines (45 loc) · 2.41 KB

Use TCP Router

This document covers adding a route to PCF's TCP Router so that you can associate an external hostname and IP address pair that will connect an external client to a MySQL or Postgres service instance.

Not for production

Note that routes must be continually re-registered within a loop, else TCP Router will stop sending traffic to the service instance.

How

  1. Configure a load balancer so that you can supply the name of the LB in the instructions below
    • The included Terraform scripts will often do this for you.
    • NB Terraform for AWS will automatically register 100 ports in the Elastic Load Balancer.
  2. Register that load balancer in DNS (e.g. route 53), so that external clients can refer to that hostname
  3. Follow the instructions to enable TCP Router in PCF
    • AWS Warning while PCF will allow you to specify a large range of ports (e.g. 1024-65535), AWS ELB does not allow more than 100 port registrations.
  4. Create a service instance

    e.g. cf create-service p.mysql large-db mysqlDB

Plumb the TCP Route

Create a route for that service instance via the Routing API

  1. Follow the instructions in the Routing API docs to get the context for the tcp_emitter UAA client.
  2. Use that token to find the GUID of the router group:
    $ curl -vvv -H "Authorization: bearer REDACTED" \
      http://api.system-domain.com/routing/v1/router_groups
    
  3. Associate a route with your service instance's IP address
    $ curl -vvv -H "Authorization: bearer REDACTED" \
      -X POST http://api.system-domain.com/routing/v1/tcp_routes/create -d '
    [{
      "router_group_guid": "9994eddc-56fb-41bc-64b8-39dcb8c0fefc",
      "port": 1034,
      "backend_ip": "10.0.8.5",
      "backend_port": 3306,
      "ttl": 120,
      "modification_tag":  {
        "guid": "e975e9c2-76a4-4f62-83e9-028c61b77e5e",
        "index": 1
      }
    }]'
    

Connect to MySQL

  1. Create a service key

    cf create-service-key mysqlDB cli-key

  2. Get the username/pw

    cf service-key mysqlDB cli-key

  3. Connect to MySQL

    mysql -uUSERNAME -h tcp.pcf.system-domain.com -P 1034 -p

Note: Per above, the route registration API must be repeated every < 120 sec or new connections will not be routed to the VM's IP address.