1

For the last couple of days I have tried to make this work. Just for testing purposes, I have three small gear nodejs apps on Openshift, and I want to have a load balancer on one that will distribute the load between the other two apps through a round-robin strategy.

I want to test if it is possible to do this with different Openshift accounts. On one account, we have the load balancer, and on the other two accounts is the app hosted.

So , let's say we have these three apps hosted at the following addresses:

http://loadbalancer-hostname0.rhcloud.com/

http://appone-hostname1.rhcloud.com/

http://apptwo-hostname2.rhcloud.com/

The code for the load balancer is:

var http = require('http'),
var httpProxy = require('http-proxy');

var proxy = httpProxy.createProxyServer({});

var addresses = [

 'http://appone-hostname1.rhcloud.com:8000',
 'http://apptwo-hostname2.rhcloud.com:8000'

];

var i = 0;
var server = http.createServer(function(req, res) {

  proxy.web(req, res, { target: addresses[i] });

  i = (i + 1) % addresses.length;

});

server.listen(8080,process.env.OPENSHIFT_NODEJS_IP);

And the code for the apps is:

var http = require('http');
var express = require('express')
app = express();

app.get('/', function (req, res) {
  res.writeHead(200, {'Content-Type' : 'text/plain'});
  res.end('Pi: ' + estimatePi());
});


app.listen(8080, process.env.OPENSHIFT_NODEJS_IP, function () {
  console.log( "Listening on port 8080" )
});

function estimatePi() {
  var n = 100000000, inside = 0, i, x, y;

  for ( i = 0; i < n; i++ ) {
    x = Math.random();
    y = Math.random();
    if ( Math.sqrt(x * x + y * y) <= 1 )
      inside++;
  }
  return 4 * inside / n;
}

It should work as follows, when someone accesses https://loadbalancer-hostname.rhcloud.com/ the server should proxy the user to one of the apps and display the result of Pi. However, when accessing the load balancer, the user is being redirected to http://openshift.com

Note: when testing on my own computer, it works flawlessly.

Can somebody please tell me what I am doing wrong and what I should do to make this work?

EDIT: If port 80 is used instead of port 8000, the load balancer server redirects to http://loadbalancer-hostname.rhcloud.com/app

ElPirru
  • 183
  • 1
  • 14
  • why would you want to add a loadbalancer and create 2 apps? every openshift app has a haproxy which load balances between the gears. what you want to do is add more gears instead of creating 3 apps?! – aschmid00 Oct 07 '15 at 21:19
  • @aschmid00 I am on openshift because my budget is very limited. Are you moving to App engine by Google? What issues have you encountered with openshift? Anyways, back to topic, I am doing this for testing purposes. I want to know if there is a way to load balance two different openshift servers on different domains, on different openshift accounts. I dont want to add/create three gears/apps within the same account. I will update my post to make it clearer. – ElPirru Oct 07 '15 at 22:35
  • @ElPirru I'm pretty sure that what you are trying to achieve is not allowed by Openshift ToS – João Gonçalves Oct 08 '15 at 15:12

0 Answers0