title: How to configure dynamic routing of gRPC requests with envoy, nomad and consul
body: <p>We use <a href="https://www.nomadproject.io/" rel="nofollow noreferrer">nomad</a> to deploy our applications - which provide <a href="https://grpc.io/" rel="nofollow noreferrer">gRPC</a> endpoints - as tasks. The tasks are then registered to <a href="https://www.consul.io/" rel="nofollow noreferrer">Consul</a>, using <a href="https://www.nomadproject.io/docs/job-specification/service.html" rel="nofollow noreferrer">nomad's service stanza</a>.</p>
  
  <p>The routing for our applications is achieved with <a href="https://www.envoyproxy.io/" rel="nofollow noreferrer">envoy proxy</a>. We are running central envoy instances loadbalanced at IP <code>10.1.2.2</code>.</p>
  
  <p>The decision to which endpoint/task to route is currently based on the <code>host</code> header and every task is registered as a service under <code>&lt;$JOB&gt;.our.cloud</code>. This leads to two problems.</p>
  
  <ol>
  <li><p>When accessing the service, the DNS name must be registered for the loadbalancer IP which leads to <code>/etc/hosts</code> entries like</p>
  
  <pre><code>10.1.2.2 serviceA.our.cloud serviceB.our.cloud serviceC.our.cloud
  </code></pre>
  
  <p>This problem is partially mitigated by using <code>dnsmasq</code>, but it is still a bit annoying when we add new services</p></li>
  <li><p>It is not possible to have multiple services running at the same time which provide the same gRPC service. If we e.g. decide to test a new implementation of a service, we need to run it in the same <code>job</code> under the same name and all services which are defined in a gRPC service file need to be implemented.</p></li>
  </ol>
  
  <p>A possible solution we have been discussing is to use the <code>tags</code> of the <code>service</code> stanza to add tags which define the provided gRPC services, e.g.:</p>
  
  <pre><code>service {
    tags = ["grpc-my.company.firstpackage/ServiceA", "grpc-my.company.secondpackage/ServiceB"]
  }
  </code></pre>
  
  <p>But this is discouraged by <a href="https://www.consul.io/docs/agent/services.html" rel="nofollow noreferrer">Consul</a>:</p>
  
  <pre><code>Dots are not supported because Consul internally uses them to delimit service tags.
  </code></pre>
  
  <p>Now we were thinking about doing it with tags like <code>grpc-my-company-firstpackage__ServiceA</code>, ... This looks really disgusting, though :-(</p>
  
  <p>So my questions are:</p>
  
  <ul>
  <li>Has anyone ever done something like that?</li>
  <li>If so, what are recommendations on how to route to gRPC services which are autodiscovered with Consul?</li>
  <li>Does anyone have some other ideas or insights into this?</li>
  <li>How is this accomplished in e.g. <a href="https://istio.io" rel="nofollow noreferrer">istio</a>?</li>
  </ul>