How to access the services registered in the consul catalog

Hello all, I am new to consul ( exploring now :wink: ) 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

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.

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

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 ?

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 see if that helps you understand the architecture better. I think registration is in Part 2.

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 ?

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

:service_id - gave id of my httpbin service

expected response:

{
  "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.

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.

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

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 .

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.

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’: ‘true’ . Can you tell me why is it and how to access my application when running in consul please ?

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

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

 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.

Can you provide us with:

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

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

values.yaml

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

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

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.

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.

1 Like

Any update on this @aram @lkysow ?

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

Hello @lkysow I have used this sample httpbin application istio/httpbin.yaml at master · istio/istio · GitHub . 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 ?

1 Like