2

I was following the following tutorial on consul learn (https://learn.hashicorp.com/tutorials/consul/service-mesh-with-envoy-proxy). Everything makes sense to me up until the point where the envoy sidecar proxy is started with the command consul connect envoy -sidecar-for service-id.

Usually when I register a service in consul, I generate a random id for the service and for that matter, trying to start the proxy this way would be impossible because I do not know the generated id as at the time of starting the sidecar proxy. What I thought of was to programmatically start the sidecar proxy in the service during startup, that way I have access to the service id and then I use that to start it. Is there any way to do this programmatically?, are there different ways this can be done aside running the consul cli command?.

Thanks.

yhiamdan
  • 113
  • 1
  • 7

1 Answers1

0

In case anyone is interested, I still could not find a way to start the envoy sidecar proxy alongside my service in code, but after some research, I realized the more appropriate way to do this is to use a deployment platform like Hashicorp Nomad or kubernettes. In the case of Nomad, you basically define your service with a sidecar proxy in a configuration file and it takes care of starting them. It actually makes sense because for the most part in microservice deployments, you would need such tools to ease your deployments.

Below is a sample nomad code to start a service and a sidecar proxy.

    service {
  name = "count-api"
  port = "9001"

  connect {
    sidecar_service {
      proxy {
        upstreams {
          destination_name = "count-api"
          local_bind_port = 8080
        }
      }
    }
  }
}
yhiamdan
  • 113
  • 1
  • 7