Code Monkey home page Code Monkey logo

microservices-demo's Introduction

microservices-demo

A very simple Go-Redis app to demo discovery of multiple services behind a haproxy load balanced (using the interlock plugin system).

This demo uses Docker Swarm, docker-compose and HA Proxy as the load balancer service through the interlock plugin system. If you need a simpler demo that does not use docker-compose, try the interlock-demo.

Pre-requisites

  1. Ensure Docker Swarm is working. An effective demo would require at least 3 active nodes in the swarm.
  2. Docker version > 1.8, docker-compose version > 1.3.1, Swarm version > 0.4
  3. Set the DOCKER_HOST environment variable to the Docker Swarm's tcp endpoint. Do not use localhost, even if you are on the Docker Swarm manager / master. Example: export DOCKER_HOST=tcp://10.0.0.6:9999.
  4. docker info should show the nodes added to the cluster.

Steps

  1. Clone this repo to a local folder. git clone https://github.com/anokun7/microservices-demo.git
  2. cd microservices-demo
  3. Use docker-compose to build and run the web app containers. docker-compose up -d
vagrant@ubuntu5:~/microservices-demo$ docker-compose stop ; docker-compose rm -f ; docker-compose up -d
Stopping microservicesdemo_db_1... done
Stopping microservicesdemo_lb_1... done
Stopping microservicesdemo_dbdata_1... done
Going to remove microservicesdemo_db_1, microservicesdemo_lb_1, microservicesdemo_dbdata_1
Removing microservicesdemo_db_1... done
Removing microservicesdemo_lb_1... done
Removing microservicesdemo_dbdata_1... done
Creating microservicesdemo_dbdata_1...
Creating microservicesdemo_lb_1...
Creating microservicesdemo_db_1...
Creating microservicesdemo_web_1...
  1. Every container started in a swarm cluster gets registered to the ha-proxy as a backend as long as the container has an exposed port and a hostname.
  • The hostname for the web container is configured in the docker-compose.yml using the INTERLOCK_DATA environment variable.
  1. Let's again use docker-compose to scale up the number of web containers to 10. Each of these 10 web containers will also get registered to the same backend in the HA Proxy config.
vagrant@ubuntu5:~/microservices-demo$ docker-compose scale web=10
Creating and starting 2... done
Creating and starting 3... done
Creating and starting 4... done
Creating and starting 5... done
Creating and starting 6... done
Creating and starting 7... done
Creating and starting 8... done
Creating and starting 9... done
Creating and starting 10... done
  1. Tha HA Proxy stats page should (auto) refresh to show the newly registered backends, like below:
  • It may be necessary to restart the lb (load balancer) container running HA Proxy. Do this if you do not see any backends registering after the scale up action.
vagrant@ubuntu5:~/microservices-demo$ docker-compose restart lb
Restarting microservicesdemo_lb_1...

HA Proxy stats 7. Ensure DNS is setup (or add entries to /etc/hosts file) to resolve the host where the lb0 container is running. 8. Browse to the URL: http://[host-ip-running-lb0]/demo

  1. Every time a container responds to the HTTP request, it will get its counter incremented (on a browser refresh). The counter is being stored (and retrieved) from a REDIS backend database.
  2. Using docker-compose, you can scale up or down the web containers as you wish based on the needs and traffic to your application.

microservices-demo's People

Contributors

anokun7 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.