Nginx proxy to many container running on different CoreOS nodes

containerscoreosdockernginxPROXY

Surfing the net, I've found many tutorials about proxying to different Docker containers running on the same host, using Nginx/Confd (or Haproxy, or Vulcand). However, what I need to do it's different. Following an overview of my infrastructure:

  • An online CoreOS cluster with 5 nodes, all running etcd
  • On every node of the cluster are launched different Docker containers (Nginx webservers running WordPress apps) using fleet, without exposing a port and writing their ips (Docker ip taken with docker inspect) on etcd .
  • If a node goes down, my services are automatically moved on another available node

Now, what I need to do is to have let's say one Nginx proxy that route my traffic to various containers depending on the vhost. Following an example:

Nginx (with pub IP) receive request xxx.domain.com –> node-1 –> container with auto assigned ip (listening on port 80)

Nginx (with pub IP) receive request yyy.domain.com –> node-2 –> container with auto assigned ip(listening on port 80)

Here my questions:

  • It's my scenario correct? Am I thinking something wrong?
  • My Nginx proxy must be outside the CoreOS cluster? Or I have to run it on every CoreOS node?
  • How can I achieve this configuration? What's the best way?

Thank you in advance!

Best Answer

You need some type of service discovery for nginx to be able to "find" the containers running on the nodes. You could write a record into etcd when container starts and remove on exit and have nginx check those.

For moving services around, you could take a look at fleet for simple scheduling.