Skip to content

dawao/traefik-consul-demo

 
 

Repository files navigation

Traefic Consul SpringBoot demo

A demonstration of using Consul Connect service discovery and Traefik reverse proxy and load balancer with Spring Boot application.

Architecture

Traefik is a dynamic reverse proxy. ConsulConnect is a service discovery server. Traefik uses ConsulConnect as a backend. SpringBoot application registers a service to Consul with Traefik specific metadata. Traefik adds a new route using this metadata.

architecture

Infrastructure

Start Portainer, Consul and Traefik:

docker-compose up -d portainer traefik consul

Open browser:

Application

Build backend service and frontend application:

./build.sh
docker-compose up -d

Service discovery

Check that there are user-repository-v1 and user-application-v1 services in Consul: https://localhost:8500

  1. Stop user-repository in Portainer
  2. Note that user-repository-v1 shows error in Consul
  3. Start user-repository in Portainer
  4. Note how quickly user-repository-v1 becomes available in Consul

Reverse proxy

Traefik shows a http port for user-application: https://localhost:8080

Application should be available through reverse proxy: https://localhost/users

  1. Login to application https://localhost/users
  2. Note service logs in Portainer

Traefik also show alternative address for Consul: https://https://consul.docker.localhost

Load balancing

scale services:

docker-compose up -d --scale user-repository=2
  1. Portainer shows two instances for user-repository
  2. Consul shows two instances of service user-repository-v1
  3. Trafik shows two instances
  4. Login to application
  5. Note service logs in Portainer
  6. Refresh application or logout/login
  7. Note service logs in Portainer, services are called in round-robin manner

Config

  1. Login to application
  2. Note the runtime environment value in footer
  3. Add config value to Consul: config/user-application/runtime/environment=production
  4. Refresh application view in browser
  5. Note the new runtime environment value
  6. Note the application log in Portainer

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 94.0%
  • Shell 2.6%
  • Dockerfile 2.6%
  • CSS 0.8%