# How to access the services registered in the consul catalog

**URL:** <https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230>\
**Category:** Consul\
**Tags:** testing, k8s, k8s-service-sync\
**Created:** [November 22, 2021, 5:53am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230 "2021-11-22T05:53:54Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![magr90900](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magr90900/32/16071_2.png) [@magr90900](https://discuss.hashicorp.com/u/magr90900)\
**Post date:** [November 22, 2021, 5:53am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/1 "2021-11-22T05:53:54Z")

</div>

Hello all, I am new to consul ( exploring now 😉 ) and I have installed consul using helm charts on my minikube cluster and it works well. Now I have deployed a sample HTTPBIN application in a separate namespace. Then I have upgraded my installation to enable sync so that services can be synced to catalog and it was successful as I was able to see the service in the catalog from Consul UI as well as API. Now I want to access this httpbin service using /get path via consul, how can I achieve it as I want to use this a service discovery .

Any help on this will be appreciated

---

<div class="post-metadata">

**Author:** ![aram](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aram](https://discuss.hashicorp.com/u/aram)\
**Post date:** [November 22, 2021, 7:59am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/2 "2021-11-22T07:59:23Z")

</div>

I’m a little confused by what you’re asking. Are you looking for the API to get a list of services?

`curl http://127.0.0.1:8500/v1/agent/services`  
to get all or  
`curl http://127.0.0.1:8500/v1/agent/service/:service_id`  
to get a specific service.

However, the typical use case is to use DNS to get the service resolution.

---

<div class="post-metadata">

**Author:** ![magr90900](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magr90900/32/16071_2.png) [@magr90900](https://discuss.hashicorp.com/u/magr90900)\
**Post date:** [November 22, 2021, 8:14am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/3 "2021-11-22T08:14:22Z")

</div>

Hello @aram , thanks for the help. I have deployed a sample httpbin application on my minikube cluster which has consul running and now if i do a curl request to httpbinservice:port /get I am getting a expected response as what k8’s provides me. Now using k8s-sync I have synced all the services to consul and wondering how to access those services via consul ? Something like below

```auto
curl http://127.0.0.1:8500/v1/agent/httpbin/get

```

Do I need to get my httpbin service registered to consul for accessing it from outside application ? Is syncing and registering a service different ?

---

<div class="post-metadata">

**Author:** ![aram](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aram](https://discuss.hashicorp.com/u/aram)\
**Post date:** [November 22, 2021, 8:28am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/4 "2021-11-22T08:28:44Z")

</div>

In a kubs pod it wouldn’t be 127.0.0.1 but your agent’s kub name so you can get to the consul agent. Or you could make an external call to the leader node if that has a advertise name. Also the path is `/agent/services/` … not replace service with your servicename.

Yes sync and register are two different things ( looking at it from a consul point of view). Sync refers to the agents and servers transferring the state of a service. Registration is how you tell consul where your service is so that it can tell anyone else who’s asking.

There is a series of streams that Hashicorp put on their youtube channel: [Getting into HashiCorp Consul, Part 1: Configuring a Server & Client on AWS - YouTube](https://www.youtube.com/watch?v=0H06VKvlTJQ) see if that helps you understand the architecture better. I think registration is in Part 2.

---

<div class="post-metadata">

**Author:** ![magr90900](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magr90900/32/16071_2.png) [@magr90900](https://discuss.hashicorp.com/u/magr90900)\
**Post date:** [November 22, 2021, 9:00am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/5 "2021-11-22T09:00:52Z")

</div>

Thanks @aram , I have curled like below and it is giving me empty response and not a http bin get response. Am I doing something wrong here please ?

```auto
curl http://127.0.0.1:8500/v1/agent/service/:service_id

:service_id - gave id of my httpbin service

```

expected response:

```auto
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.64.1",
    "X-Amzn-Trace-Id": "Root=xxxx"
  },
  "origin": "x.x.x.x, x.x.x.x",
  "url": "http://httpbin.org/get"
}

```

Is it the problem because I just only synced it not registered ? Actually my goal here is to make my application which is running in same cluster use the httpbin API in consul like service discovery thing.

---

<div class="post-metadata">

**Author:** ![aram](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aram](https://discuss.hashicorp.com/u/aram)\
**Post date:** [November 23, 2021, 8:15am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/6 "2021-11-23T08:15:13Z")

</div>

How did you get the service\_id if you didn’t register the service?

Go to the consul server and run:  
`consul catalog services`

If your app isn’t listing then you need to either register it with a configuration and restart consul or you can do it via API.

---

<div class="post-metadata">

**Author:** ![magr90900](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magr90900/32/16071_2.png) [@magr90900](https://discuss.hashicorp.com/u/magr90900)\
**Post date:** [November 23, 2021, 8:49am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/7 "2021-11-23T08:49:50Z")

</div>

Hello @aram , thanks for your help and response. I can see services listed along with my service when I exec into the consul-server pod also I have used below API to check the services and I can see my service here

```auto
curl localhost:8500/v1/catalog/services

```

My query is how can consume this service in my another application meaning what hostname:port should and endpoint I use to access this service from my application .

---

<div class="post-metadata">

**Author:** ![aram](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aram](https://discuss.hashicorp.com/u/aram)\
**Post date:** [November 23, 2021, 9:00am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/8 "2021-11-23T09:00:48Z")

</div>

[![](https://global.discourse-cdn.com/hashicorp/original/3X/d/c/dc0fa5326556afad2224ce48fe8b5216ceed4d8e.jpeg "Getting into HashiCorp Consul, Part 1: Configuring a Server & Client on AWS") ](https://www.youtube.com/watch?v=0H06VKvlTJQ)

---

<div class="post-metadata">

**Author:** ![magr90900](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magr90900/32/16071_2.png) [@magr90900](https://discuss.hashicorp.com/u/magr90900)\
**Post date:** [November 26, 2021, 10:35am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/9 "2021-11-26T10:35:53Z")

</div>

Hello @aram

I have deployed the sample and counting example in my k8’s cluster where consul is also being deployed. When I exec into any pod and then try a curl request to the counting pod IP with the port it is giving me empty reply from server message. Is this expected and if yes then how can access my application with pod IP or another way from a another application.

```auto
k get pod -o wide -n consul-k8s

counting-d9d58c4cb-fr5cr 2/2 Running 0 33h 10.288.0.157 <none> <none>

Now if do curl as below with Pod IP

k exec network-toolspod-f64c586f4-7nzrd -- curl 10.288.0.157:9001/counting
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
  0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (52) Empty reply from server
command terminated with exit code 52

```

The same curl command works as expected giving response if there are no consul sidecar containers present along with the deployment by using annotation **‘[consul.hashicorp.com/connect-inject](http://consul.hashicorp.com/connect-inject)’: ‘true’**. Can you tell me why is it and how to access my application when running in consul please ?

---

<div class="post-metadata">

**Author:** ![lkysow](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/lkysow/32/1105_2.png) [@lkysow](https://discuss.hashicorp.com/u/lkysow)\
**Post date:** [November 26, 2021, 5:32pm UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/10 "2021-11-26T17:32:33Z")

</div>

Hi, is it possible to use a Kubernetes Service instead of the Pod IP? e.g. `curl http://counting`. I’d start by following the examples here: [Service Mesh - Kubernetes | Consul by HashiCorp](https://www.consul.io/docs/k8s/connect#accepting-inbound-connections)

---

<div class="post-metadata">

**Author:** ![magr90900](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magr90900/32/16071_2.png) [@magr90900](https://discuss.hashicorp.com/u/magr90900)\
**Post date:** [November 26, 2021, 5:55pm UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/11 "2021-11-26T17:55:59Z")

</div>

Hello @lkysow I have even tried with Service Ip and still same result as Empty reply from server

```auto
 k exec <test-tool-podname> -- curl counting.consul-k8s.svc:9001/counting
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
  0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (52) Empty reply from server
command terminated with exit code 52

```

Actually I am thinking whether I should use any other annotation here to expose svc when we are using envoy proxy along with my application. The main problem is I am not able to access my application if there is a side car proxy injection by consul . Can you test it on your end and let me know if you see the same behaviour. This is quite important as I am performing a POC on Consul product to evaluate.

---

<div class="post-metadata">

**Author:** ![lkysow](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/lkysow/32/1105_2.png) [@lkysow](https://discuss.hashicorp.com/u/lkysow)\
**Post date:** [November 26, 2021, 7:06pm UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/12 "2021-11-26T19:06:46Z")

</div>

Can you provide us with:

- `values.yaml` for installing Consul
- All the Kubernetes manifests for your applications

---

<div class="post-metadata">

**Author:** ![magr90900](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magr90900/32/16071_2.png) [@magr90900](https://discuss.hashicorp.com/u/magr90900)\
**Post date:** [November 26, 2021, 7:28pm UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/13 "2021-11-26T19:28:19Z")

</div>

Hello @lkysow thanks for the response. Below is my values.yaml file contents used for installing consul.

values.yaml

```auto
global:
  name: consul
  datacenter: dc1
server:
  replicas: 1
  securityContext:
    runAsNonRoot: false
    runAsGroup: 0
    runAsUser: 0
    fsGroup: 0
ui:
  enabled: true
  service:
    type: 'NodePort'
connectInject:
  enabled: true
  default: false
controller:
  enabled: true
syncCatalog:
  enabled: true

```

I have deployed the sample counting and dashboard example from docs link [Consul Service Discovery and Mesh on Minikube | Consul - HashiCorp Learn](https://learn.hashicorp.com/tutorials/consul/kubernetes-minikube#deploy-services-with-kubernetes)

Please let me know if you need anything else from my side to move this issue forward.

---

<div class="post-metadata">

**Author:** ![magr90900](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magr90900/32/16071_2.png) [@magr90900](https://discuss.hashicorp.com/u/magr90900)\
**Post date:** [November 27, 2021, 9:35am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/14 "2021-11-27T09:35:37Z")

</div>

Hello @lkysow any update on this please ? Actually I need this because I am trying to integrate with a external application and want to resolve why I am not able use svc/pod ip to connect to the consul service running with side cars.

---

<div class="post-metadata">

**Author:** ![magr90900](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magr90900/32/16071_2.png) [@magr90900](https://discuss.hashicorp.com/u/magr90900)\
**Post date:** [November 28, 2021, 7:56am UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/15 "2021-11-28T07:56:26Z")

</div>

Hello @lkysow I have tested with istio service mesh which also injects side car containers and curling a pod ip and port works as expected but only consul side cars I am getting empty reply from server error. Can you please help on this as this becomes a situation for me to re-evaluate other products away from hashicorp products end as this is critical to understand.

---

<div class="post-metadata">

**Author:** ![magr90900](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magr90900/32/16071_2.png) [@magr90900](https://discuss.hashicorp.com/u/magr90900)\
**Post date:** [November 29, 2021, 4:14pm UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/16 "2021-11-29T16:14:21Z")

</div>

Any update on this @aram @lkysow ?

---

<div class="post-metadata">

**Author:** ![lkysow](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/lkysow/32/1105_2.png) [@lkysow](https://discuss.hashicorp.com/u/lkysow)\
**Post date:** [November 29, 2021, 6:20pm UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/17 "2021-11-29T18:20:38Z")

</div>

Hi, what about your httpbin tool yaml you’re using?

---

<div class="post-metadata">

**Author:** ![magr90900](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magr90900/32/16071_2.png) [@magr90900](https://discuss.hashicorp.com/u/magr90900)\
**Post date:** [November 29, 2021, 6:47pm UTC](https://discuss.hashicorp.com/t/how-to-access-the-services-registered-in-the-consul-catalog/32230/18 "2021-11-29T18:47:46Z")

</div>

Hello @lkysow I have used this sample httpbin application [istio/httpbin.yaml at master · istio/istio · GitHub](https://github.com/istio/istio/blob/master/samples/httpbin/httpbin.yaml) . I can say that the problem is not the application, it is just that when consul injects a side car into application we cannot reach the application via svc ip or pod ip. We need to figure out if we need to add any annotation to make the communication proper when using side car envoy proxy.

Can you please test this and help me ?
