Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Consul service endpoints for service discovery #100

Closed
johnrengelman opened this issue Jul 10, 2014 · 7 comments
Closed

Support Consul service endpoints for service discovery #100

johnrengelman opened this issue Jul 10, 2014 · 7 comments
Milestone

Comments

@johnrengelman
Copy link
Contributor

Currently, confd is limited to accessing the KV store of consul. It would be very helpful if the service and nodes endpoints could also be accessed. Then things like writing a HAProxy conf file can be done by querying the healthy endpoints for a service in Consul (not sure what/if there is a similar feature in etcd).

Would there be interest in a feature like this? I may be able to get schedule some work at my job to develop it if there is interest.

The main question without looking at anything yet is how would the confd templating discriminate between normal KV and the service or node data.

@carlosdp
Copy link

Yep, I would very much like this and would like to start working on it. It makes more sense than just the kv store because those don't take advantage of Consul's health checks and such. My first thought was to have a flag to enable service endpoints and then namespacing those keys under a service_ prefix like so:

upstream web {
  {{range .service_web}}
    {{.Node.Address}}:{{.Service.Port}}
  {{end}}
}

@johnrengelman
Copy link
Contributor Author

I got something put together last week that works pretty nice (based off the 0.6.x branch).

I didn't add a flag to control the generation, as I thought it was just something that should be supported out of the box. I went to the route of just injecting the service data into the KV using paths:

/_consul/services/<service_name>/<idx>/address
/_consul/services/<service_name>/<idx>/port

And additionally, Tags were supported by adding to the path:

/_consul/services/<service_name>/<tag>/<idx>/address
/_consul/services/<service_name>/<tag>/<idx>/port

Then in the template, I could use the normal KV methods:

{{range gets "/_consul/service/web/*/address"}}
  {{.Value}}
{{end}}

I like the structure of your example above though, but I find it might be hard to support tags and datacenters using the style.

Perhaps something that's a hybrid where, we use a method to get the service information?

upstream web {
  {{range (.service 'web')}}
    {{.Node.Address}}:{{.Service.Port}}
  {{end}}
}

Then, that could be expanded to include tags:

{{range (.service 'web' 'tag1')}}
{{end}}

@carlosdp
Copy link

Actually, I like your implementation better. No need to abstract the Consul api 😄 I'm not that familiar with gotext templating so I was just going off of the confd docs.

Yea, if you post that PR I'll defintely help!

@johnrengelman
Copy link
Contributor Author

Here's my first crack at this: #102

@mohitarora
Copy link

Consul documentation says: Lookup consul nodes using SRV records will be available in 0.5.0

Is there any timeline around 0.5.0? I can work on it but i see PR already submitted for this.

Please let us know.

@johnrengelman
Copy link
Contributor Author

The SRV record support is for using SRV records from consul to detect the backend nodes for confd itself, not for acquiring the consul service information and exposing it to templates. I was confused by that initially as well.

Yeah, I put #102 out there as my attempt to solve this problem.

@kelseyhightower kelseyhightower added this to the 0.6.0-alpha2 milestone Aug 4, 2014
@kelseyhightower
Copy link
Owner

See #102 but the idea is that we will add support this via custom backends.

seewerah pushed a commit to seewerah/confd that referenced this issue Sep 21, 2024
)

Bumps [github.com/go-zookeeper/zk](https://github.com/go-zookeeper/zk) from 1.0.2 to 1.0.3.
- [Release notes](https://github.com/go-zookeeper/zk/releases)
- [Commits](go-zookeeper/zk@v1.0.2...v1.0.3)

---
updated-dependencies:
- dependency-name: github.com/go-zookeeper/zk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants