|
| 1 | +# ServDiscovery |
| 2 | + |
| 3 | +ServDiscovery is a Discovery Service that keeps an Endpoint updated with active Hosts (of Services). |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +> [!NOTE] |
| 8 | +> ServDiscovery only works with Traefik and not with **any** other Reverse Proxy due to `discover.enable` lable |
| 9 | +
|
| 10 | +Get the latest `docker-compose.yaml` file: |
| 11 | + |
| 12 | +```yaml |
| 13 | +services: |
| 14 | + discovery: |
| 15 | + image: ghcr.io/codeshelldev/servdiscovery:latest |
| 16 | + container_name: service-discovery |
| 17 | + environment: |
| 18 | + ENDPOINT: https://mydomain.com/ENDPOINT |
| 19 | + ENDPOINT_KEY: MY_VERY_SECURE_KEY |
| 20 | + SERVER_NAME: server-1 |
| 21 | + volumes: |
| 22 | + - /var/run/docker.sock:/var/run/docker.sock |
| 23 | +``` |
| 24 | +
|
| 25 | +```bash |
| 26 | +docker compose up -d |
| 27 | +``` |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +Take this little `whoami` Container as an Example: |
| 32 | + |
| 33 | +```yaml |
| 34 | +services: |
| 35 | + whoami: |
| 36 | + image: traefik/whoami:latest |
| 37 | + container_name: whoami |
| 38 | + labels: |
| 39 | + - traefik.enable=true |
| 40 | + - traefik.http.routers.whoami.rule=Host(`whoami.mydomain.com`) |
| 41 | + - traefik.http.routers.whoami.entrypoints=websecure |
| 42 | + - traefik.http.routers.whoami.tls=true |
| 43 | + - traefik.http.routers.whoami.tls.certresolver=cloudflare |
| 44 | + - traefik.http.routers.whoami.service=whoami-svc |
| 45 | + - traefik.http.services.whoami-svc.loadbalancer.server.port=80 |
| 46 | + # Enable Discovery on this Container |
| 47 | + - discovery.enable=true |
| 48 | + networks: |
| 49 | + - traefik |
| 50 | + |
| 51 | +networks: |
| 52 | + traefik: |
| 53 | + external: true |
| 54 | + |
| 55 | +``` |
| 56 | +
|
| 57 | +Whenever a new **Host-Rule** gets added / modified ServDiscovery will update the set Endpoint to notify of any new changes. |
| 58 | +This way the Endpoint can correctly route to different Hosts based on **SNI / Hostnames**. |
| 59 | +
|
| 60 | +## Endpoint |
| 61 | +
|
| 62 | +ServDiscovery sends requests to the Endpoint as a **JSON HTTP Request**: |
| 63 | +
|
| 64 | +```json |
| 65 | +{ |
| 66 | + "serverName": "server-1", |
| 67 | + "diff": { |
| 68 | + "added": [ |
| 69 | + "whoami.mydomain.com", |
| 70 | + "website.mydomain.com", |
| 71 | + "auth.mydomain.com" |
| 72 | + ], |
| 73 | + "removed": [ |
| 74 | + "whoami-backup.mydomain.com", |
| 75 | + "website-backup.mydomain.com", |
| 76 | + "auth-backup.mydomain.com" |
| 77 | + ] |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +This example tell the Endpoint that... |
| 83 | + |
| 84 | +| Available | Unavailable | |
| 85 | +| -------------------- | --------------------------- | |
| 86 | +| whoami.mydomain.com | whoami-backup.mydomain.com | |
| 87 | +| website.mydomain.com | website-backup.mydomain.com | |
| 88 | +| auth.mydomain.com | auth-backup.mydomain.com | |
| 89 | + |
| 90 | +This way (if the Endpoint is used by a LoadBalancer) the Owner of the Endpoint can now delete the `*-backup.mydomain.com` records from a Registry, |
| 91 | +thus updating the list of routable Containers / Services. |
| 92 | + |
| 93 | +## Configuration |
| 94 | + |
| 95 | +### ENDPOINT_KEY |
| 96 | + |
| 97 | +The Endpoint Key is provided in the Authorization Header (via Bearer) during the POST request between the Endpoint and ServDiscovery. |
| 98 | +If no Key is provided ServDiscovery will leave out the Authorization Header. |
| 99 | + |
| 100 | +### DISCOVERY_INTERVAL |
| 101 | + |
| 102 | +The Discovery Interval sets the Interval of which ServDiscovery will update the Endpoint, etc. |
| 103 | + |
| 104 | +## Contributing |
| 105 | + |
| 106 | +Found a bug or have new ideas or enhancements for this Project? |
| 107 | +Feel free to open up an issue or create a Pull Request! |
| 108 | + |
| 109 | +## License |
| 110 | + |
| 111 | +[MIT](https://choosealicense.com/licenses/mit/) |
0 commit comments