6

I have consul running on Consul v0.5.2 version & services running in Mesos. Services keep moving from 1 server to another.

Is there way to deregister services in consul that are in 'failing' state? I am able to get the list of services in failing state using this curl

curl http://localhost:8500/v1/health/state/critical

Issue that we are seeing is over a period of time in consul UI we have stale data & making the whole UI unusable

janisz
  • 6,292
  • 4
  • 37
  • 70
DevOpsNewB
  • 185
  • 2
  • 14

2 Answers2

10

Consul by default do not deregister unhealthy services instead marks them as critical. From Consul 0.7 there is special option (deregister_critical_service_after) that allows you to define time after unhealthy service will be deregstered

From Consul 0.7 Changelog

Automatic Service Deregistration: Added a new deregister_critical_service_after timeout field for health checks which will cause the service associated with that check to get deregistered if the check is critical for longer than the timeout. This is useful for cleanup of health checks registered natively by applications, or in other situations where services may not always be cleanly shutdown. GH-679

If you are usign Marathon then you can consider using allegro/marathon-consul it will deregister task when its dead

janisz
  • 6,292
  • 4
  • 37
  • 70
  • How to specify the `deregister_critical_service_after` value in consul? I did not know how to use it. @janisz the document did not mention how to use it. – Dolphin Aug 29 '21 at 14:42
  • 1
    https://www.consul.io/api-docs/agent/check#deregistercriticalserviceafter – janisz Aug 30 '21 at 10:35
  • I configure it like this: https://stackoverflow.com/questions/69007497/how-to-deregister-the-service-in-consul-when-using-spring-could-consul still did not work. @janisz – Dolphin Sep 01 '21 at 07:07
0

Along with what janisz said, you can also run your services in Nomad and Nomad will automatically register and deregister your services for you. See the Nomad Service Discovery docs for additional details.

Sean
  • 9,888
  • 4
  • 40
  • 43