Tiven Wang
Wang Tiven May 24, 2017
425 favorite favorites
bookmark bookmark
share share

Try CloudFoundry Series

Routes and Domains

Create Custom Domain and Route

Create a your private domain for your organization:

$ cf create-domain tiven.wang cf.tiven.wang

Creating domain cf.tiven.wang for org tiven.wang as i.tiven.wang@gmail.com...
OK

Use the cf domains command to view a list of available domains for the targeted org:

Getting domains in org tiven.wang as i.tiven.wang@gmail.com...
name            status   type
cfapps.io       shared
cf-tcpapps.io   shared   tcp
cf.tiven.wang   owned

Map the a route to your respective apps, Developers use hostname, domain, and path to uniquely identify a route to map their apps to:

$ cf map-route try-cloud-foundry cf.tiven.wang --hostname try-cloud-foundry

Creating route try-cloud-foundry.cf.tiven.wang for org tiven.wang / space development as i.tiven.wang@gmail.com...
OK
Adding route try-cloud-foundry.cf.tiven.wang to app try-cloud-foundry in org tiven.wang / space development as i.tiven.wang@gmail.com...
OK

View the urls attribute of your app:

cf apps

Getting apps in org tiven.wang / space development as i.tiven.wang@gmail.com...
OK

name                requested state   instances   memory   disk   urls
try-cloud-foundry   started           2/2         128M     128M   try-cloud-foundry.cfapps.io, try-cloud-foundry.cf.tiven.wang

Call try-cloud-foundry.cfapps.io to access my app, but try-cloud-foundry.cf.tiven.wang can’t, because we need configure a CNAME record with your DNS provider.

Mapping Domains to Your Custom Domain

Add a CNAME record in my DNS provider:

try-cloud-foundry.cf to try-cloud-foundry.cfapps.io

Now we can access the app by try-cloud-foundry.cf.tiven.wang

Mapping Route of Path to App

You can also map a path route to the app:

$ cf map-route try-cloud-foundry cf.tiven.wang --hostname labs --path try-cloud-foundry

Creating route labs.cf.tiven.wang/try-cloud-foundry for org tiven.wang / space development as i.tiven.wang@gmail.com...
OK
Adding route labs.cf.tiven.wang/try-cloud-foundry to app try-cloud-foundry in org tiven.wang / space development as i.tiven.wang@gmail.com...
OK

Add a CNAME record in your DNS provider:

labs.cf to cfapps.io

Now you can access http://labs.cf.tiven.wang/try-cloud-foundry

You must handle the path /try-cloud-foundry in your app

TCP Routing

Build a TCP Application

Application source codes on Github

Build a TCP chat server using Node.js.

var net = require('net');

var server = net.createServer();

var sockets = [];

server.on('connection', function(socket) {
  console.log('got a new connection');

  sockets.push(socket);

  socket.on('data', function(data) {
    //console.log('got data:', data.toString());

    sockets.forEach(function(otherSocket) {
      if(otherSocket !== socket) {
        otherSocket.write(data);
      }
    });
  });
});

server.on('error', function(err) {
  console.error('Server error:', err.message);
});

server.on('close', function() {
  console.log('Server closed:');
});

server.listen(4001);

Deploy to PWS

Using domain: cf-tcpapps.io

---
applications:
- name: try-cf-tcp
  buildpack: nodejs_buildpack
  command: node index.js
  memory: 128M
  host: try-cf-tcp
  domain: cf-tcpapps.io

Currently, only Shared Domains can be TCP. Admins manage shared domains, which are available to users in all orgs of a PWS deployment. Shared domains are HTTP by default, but can be configured to be TCP when associated with the TCP Router Group.

So we can’t use TCP in PWS now.

$ cf push
Using manifest file C:\dev\github\tiven-wang\try-cf\manifest.yml

Updating app try-cf-tcp in org tiven.wang / space development as i.tiven.wang@gmail.com...
OK

Creating random route for cf-tcpapps.io...
OK

FAILED
Server error, status code: 400, error code: 310009, message: You have exceeded the total reserved route ports for your organization's quota.

By default, PWS only supports routing of HTTP requests to applications.

References

Similar Posts

  • Try Cloud Foundry 13 - Logs Loggregator is the next generation system for aggregating and streaming logs and metrics from all of the user apps and system components in an Elastic Runtime deployment. Loggregator uses Google's protocol buffers along with gRPC to deliver logs.
  • Try Cloud Foundry 12 - Config Server Config Server for Pivotal Cloud Foundry (PCF) is an externalized application configuration service, which gives you a central place to manage an application’s external properties across all environments.
  • Try Cloud Foundry 11 - Autoscaler Autoscaler
  • Try CloudFoundry Try CloudFoundry
  • Try Cloud Foundry 10 - Service Discovery Service Registry for Pivotal Cloud Foundry (PCF) provides your applications with an implementation of the Service Discovery pattern, one of the key tenets of a microservice-based architecture. Trying to hand-configure each client of a service or adopt some form of access convention can be difficult and prove to be brittle in production. Instead, your applications can use the Service Registry to dynamically discover and call registered services.
  • Try Cloud Foundry 9 - Message Broker A message broker is an architectural pattern for message validation, transformation and routing. It mediates communication amongst applications, minimizing the mutual awareness that applications should have of each other in order to be able to exchange messages, effectively implementing decoupling.

Comments

comments powered by Disqus
Back to Top