1
votes

I currently have 2 services running on a single node (EC2 instance) with a consul client. I would like to health check both of these by hitting a single endpoint, namely: http://localhost:8500/v1/agent/health/service/id/AliasService based on the information Consul provides from https://www.consul.io/api/agent/service.html.

The issue is that I can't seem to find any sort of documentation regarding this AliasService, just that I can use it to run health checks. I've tried putting it into my service definitions but to no avail. It just seems to ignore it altogether.

1

1 Answers

0
votes

It seems that what you need is to manually define both services and then attach HTTP health check to one of them and alias health check to the other. What is being aliased here is not service but health check.

For example:

$ consul services register -name ssh -port 22
$ consul services register -name ssh-alias -port 22 -address 172.17.0.1
$ cat >ssh-check.json
{
  "ID": "ssh",
  "Name": "SSH TCP on port 22",
  "ServiceID": "ssh",
  "TCP": "localhost:22",
  "Interval": "10s",
  "Timeout": "1s"
}
$ curl --request PUT --data @ssh-check.json http://127.0.0.1:8500/v1/agent/check/register
$ cat >ssh-alias-check.json
{
  "ID": "ssh-alias",
  "Name": "SSH TCP on port 22 - alias",
  "ServiceID": "ssh-alias",
  "AliasService": "ssh"
}
$ curl --request PUT --data @ssh-alias-check.json http://127.0.0.1:8500/v1/agent/check/register

Here I have defined two separate services and two health checks. But only the first health check is doing actual work, the second is aliasing health status from one service to the other.