<p>I deployed an aws eks cluster via terraform. I also deployed Consul following hasicorp’s tutorial and I see the nodes in consul’s UI.</p>
<p>Now I’m wondering how al the consul agents will know about the pods I deploy? I deploy something and it’s not shown anywhere on consul.</p>
<p>I can’t find any documentation as to how to register pods (services) on consul via the node’s consul agent, do I need to configure that somewhere? Should I not use the node’s agent and register the service straight from the pod? Hashicorp discourages this since it may increase resource utilization depending on how many pods one deploy on a given node. But then how does the node’s agent know about my services deployed on that node?</p>
<p>Moreover, when I deploy a pod in a node and ssh into the node, and install consul, consul’s agent can’t find the consul server (as opposed from the node, which can find it)</p>
<p>EDIT:</p>
<p>Bottom line is I can't find WHERE to add the configuration. If I execute ON THE POD:</p>
<p><code>consul members</code></p>
<p>It works properly and I get:</p>
<pre><code>Node                          Address            Status  Type    Build   Protocol  DC         Segment
consul-consul-server-0        10.0.103.23:8301   alive   server  1.10.0  2         full  &lt;all&gt;
consul-consul-server-1        10.0.101.151:8301  alive   server  1.10.0  2         full  &lt;all&gt;
consul-consul-server-2        10.0.102.112:8301  alive   server  1.10.0  2         full  &lt;all&gt;
ip-10-0-101-129.ec2.internal  10.0.101.70:8301   alive   client  1.10.0  2         full  &lt;default&gt;
ip-10-0-102-175.ec2.internal  10.0.102.244:8301  alive   client  1.10.0  2         full  &lt;default&gt;
ip-10-0-103-240.ec2.internal  10.0.103.245:8301  alive   client  1.10.0  2         full  &lt;default&gt;
ip-10-0-3-223.ec2.internal    10.0.3.249:8301    alive   client  1.10.0  2         full  &lt;default&gt;
</code></pre>
<p>But if i execute:</p>
<pre><code># consul agent -datacenter=voip-full -config-dir=/etc/consul.d/ -log-file=log-file -advertise=$(wget -q -O - http://169.254.169.254/latest/meta-data/local-ipv4)
</code></pre>
<p>I get the following error:</p>
<pre><code>==&gt; Starting Consul agent...
           Version: '1.10.1'
           Node ID: 'f10070e7-9910-06c7-0e12-6edb6cc4c9b9'
         Node name: 'ip-10-0-3-223.ec2.internal'
        Datacenter: 'voip-full' (Segment: '')
            Server: false (Bootstrap: false)
       Client Addr: [127.0.0.1] (HTTP: 8500, HTTPS: -1, gRPC: -1, DNS: 8600)
      Cluster Addr: 10.0.3.223 (LAN: 8301, WAN: 8302)
           Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false, Auto-Encrypt-TLS: false

==&gt; Log data will now stream in as it occurs:

2021-08-16T18:23:06.936Z [WARN]  agent: skipping file /etc/consul.d/consul.env, extension must be .hcl or .json, or config format must be set
2021-08-16T18:23:06.936Z [WARN]  agent: Node name &quot;ip-10-0-3-223.ec2.internal&quot; will not be discoverable via DNS due to invalid characters. Valid characters include all alpha-numerics and dashes.
2021-08-16T18:23:06.946Z [WARN]  agent.auto_config: skipping file /etc/consul.d/consul.env, extension must be .hcl or .json, or config format must be set
2021-08-16T18:23:06.947Z [WARN]  agent.auto_config: Node name &quot;ip-10-0-3-223.ec2.internal&quot; will not be discoverable via DNS due to invalid characters. Valid characters include all alpha-numerics and dashes.
2021-08-16T18:23:06.948Z [INFO]  agent.client.serf.lan: serf: EventMemberJoin: ip-10-0-3-223.ec2.internal 10.0.3.223
2021-08-16T18:23:06.948Z [INFO]  agent.router: Initializing LAN area manager
2021-08-16T18:23:06.950Z [INFO]  agent: Started DNS server: address=127.0.0.1:8600 network=udp
2021-08-16T18:23:06.950Z [WARN]  agent.client.serf.lan: serf: Failed to re-join any previously known node
2021-08-16T18:23:06.950Z [INFO]  agent: Started DNS server: address=127.0.0.1:8600 network=tcp
2021-08-16T18:23:06.951Z [INFO]  agent: Starting server: address=127.0.0.1:8500 network=tcp protocol=http
2021-08-16T18:23:06.951Z [WARN]  agent: DEPRECATED Backwards compatibility with pre-1.9 metrics enabled. These metrics will be removed in a future version of Consul. Set `telemetry { disable_compat_1.9 = true }` to disable them.
2021-08-16T18:23:06.953Z [INFO]  agent: started state syncer
2021-08-16T18:23:06.953Z [INFO]  agent: Consul agent running!
2021-08-16T18:23:06.953Z [WARN]  agent.router.manager: No servers available
2021-08-16T18:23:06.954Z [ERROR] agent.anti_entropy: failed to sync remote state: error=&quot;No known Consul servers&quot;
2021-08-16T18:23:34.169Z [WARN]  agent.router.manager: No servers available
2021-08-16T18:23:34.169Z [ERROR] agent.anti_entropy: failed to sync remote state: error=&quot;No known Consul servers&quot;
</code></pre>
<p>So where to add the config?</p>
<p>I also tried adding a service in k8s pointing to the pod, but the service doesn't come up on consul's UI...</p>
<p>What do you guys recommend?</p>
<p>Thanks</p>

<blockquote>
<p>Consul knows where these services are located because each service
registers with its local Consul client. Operators can register
services manually, configuration management tools can register
services when they are deployed, or container orchestration platforms
can register services automatically via integrations.</p>
</blockquote>
<p>if you planning to use manual option you have to register the service into the consul.</p>
<p>Something like</p>
<pre><code>echo '{
  &quot;service&quot;: {
    &quot;name&quot;: &quot;web&quot;,
    &quot;tags&quot;: [
      &quot;rails&quot;
    ],
    &quot;port&quot;: 80
  }
}' &gt; ./consul.d/web.json
</code></pre>
<p>You can find the good example at : <a href="https://thenewstack.io/implementing-service-discovery-of-microservices-with-consul/" rel="nofollow noreferrer">https://thenewstack.io/implementing-service-discovery-of-microservices-with-consul/</a></p>
<p>Also this is a very nice document for having detailed configuration of the health check and service discovery : <a href="https://cloud.spring.io/spring-cloud-consul/multi/multi_spring-cloud-consul-discovery.html" rel="nofollow noreferrer">https://cloud.spring.io/spring-cloud-consul/multi/multi_spring-cloud-consul-discovery.html</a></p>
<p>Official document : <a href="https://learn.hashicorp.com/tutorials/consul/get-started-service-discovery" rel="nofollow noreferrer">https://learn.hashicorp.com/tutorials/consul/get-started-service-discovery</a></p>
