OpenSource

Fabio Route 처리 (urlprefix) with Consul

아르비스 2018. 12. 6. 11:29

 base :

Hashcorp Consul 기반의 Service Routing을 Fabio로 처리하기 위함.


한참의 구글링과, 서핑, Document를 정독해도.. fabio에서는 Routing Table에서 아무것도 보이지 않았다..


애꿋은 Fabio 만 욕하며,, 왜 가이드가 없는거야.. 했는데..

있기는 했다.. 영어를 잘 못하는게 잘 못이지..ㅠㅠ

https://github.com/fabiolb/fabio

1. Register your service in consul. Make sure that each instance registers with a unique ServiceID and a service name without spaces.

2. Register a health check in consul as described here. By default fabio only watches services which have a passing health check, unless overriden with registry.consul.service.status.

3. Register one urlprefix- tag per host/path prefix it serves, e.g.:

# HTTP/S examples
urlprefix-/css                                     # path route
urlprefix-i.com/static                             # host specific path route
urlprefix-mysite.com/                              # host specific catch all route
urlprefix-/foo/bar strip=/foo                      # path stripping (forward '/bar' to upstream)
urlprefix-/foo/bar proto=https                     # HTTPS upstream
urlprefix-/foo/bar proto=https tlsskipverify=true  # HTTPS upstream and self-signed cert

# TCP examples 

urlprefix-:3306 proto=tcp # route external port 3306  


3번의 Register "urlprefix" 를 어디서 등록하느냐로.. 한 3~4일간 뒤졌는데.. 결론은 의외로 간단했다..ㅠㅠ


Fabio가 아닌 Consul에 등록해 주는 것이었다.

Consul에 Tags로 해당 rule을 등록하면 Routing은 Fabio가 알아서 한다는거..ㅠㅠ 

이럴꺼면 그냥 Consul에서 Routing을 해주지.. 왜 Fabio를 쓰는건지..


Consul에 등록방법, application 쪽에서 yml과 properties에서 

spring.cloud.consul.discovery.tags=urlprefix-/${spring.application.name}

위와 같이 설정해서 Consul에 접속되면.

(applicatiion.name = example)


 example Healthchecks Passing  4  urlprefix-/example secure=false

로 표시됨.

이후 Fabio 에서 접속하면.

아래와 같은 Routing Table이 보임

Routing Table


type to filter routes

# Service Source Dest Options Weight

1 example /example http://127.0.0.1:50344/ 50.00%

2 example /example http://127.0.0.1:50299/ 50.00%