Search code examples
proxyconsulsidecar

Getting error connection refused when trying to consul connect using sidecar proxy to web


I am following this tutorial https://learn.hashicorp.com/consul/getting-started/connect

at the point when I ran consul connect proxy -sidecar-for web it started throwing this error:

2020-07-26T14:30:18.243+0100 [ERROR] proxy.inbound: failed to dial: error="dial tcp 127.0.0.1:0: connect: can't assign requested address"

why this does not have port assigned in his demonstration ?

{
  "service": {
    "name": "web",
    "connect": {
      "sidecar_service": {
        "proxy": {
          "upstreams": [
            {
              "destination_name": "socat",
              "local_bind_port": 9191
            }
          ]
        }
      }
    }
  }
}

Solution

  • The video in the tutorial shows the forth line as:

    "port": 8080,
    

    The documentation is missing that line. Not that it will matter because nothing is listening on web service so the error will persist. You can safely ignore that. I suspect your issue is that the operation nc 127.0.0.1 9191 is failing. I address that below.

    The full config should look like:

    {
      "service": {
        "name": "web",
        "port": 8080,
        "connect": {
          "sidecar_service": {
            "proxy": {
              "upstreams": [
                {
                  "destination_name": "socat",
                  "local_bind_port": 9191
                }
              ]
            }
          }
        }
      }
    }   
    

    But, this isn't important for getting through this section of the lab. The instructions aren't clear but don't forget to restart web proxy consul connect proxy -sidecar-for web and start socat proxy consul connect proxy -sidecar-for socat The last part is sorely missing from the instructions and the video.