# Using DNS for External Services in Kubernetes

**URL:** <https://discuss.hashicorp.com/t/using-dns-for-external-services-in-kubernetes/26186>\
**Category:** Consul\
**Tags:** k8s, dns\
**Created:** [June 30, 2021, 12:32pm UTC](https://discuss.hashicorp.com/t/using-dns-for-external-services-in-kubernetes/26186 "2021-06-30T12:32:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jon/32/16573_2.png) [@jon](https://discuss.hashicorp.com/u/jon)\
**Post date:** [June 30, 2021, 12:32pm UTC](https://discuss.hashicorp.com/t/using-dns-for-external-services-in-kubernetes/26186/1 "2021-06-30T12:32:09Z")

</div>

Hello,

I have Consul set up with the official Consul Helm chart (v0.32.0) in K8s.  
I am using DNS for service discovery, and have changed the `coredns` settings according to the documentation.

I can use `<service>.service.consul` URLs within the pods to talk to the other pods.

I want to be able to do the same for external services.  
I set up an external service according to the External Service documentation by creating a “dummy” node like follows:

```json
{
  "Node": "external-node",
  "Address": "external-service.that.is.publicly.accessible.com",
  "NodeMeta": {
    "external-node": "true",
    "external-probe": "true"
  },
  "Service": {
    "ID": "external",
    "Service": "external",
    "Port": 80
  }
}

```

I have also tried settings DNS recursors (Google’s 8.8.8.8 and 8.8.4.4 servers) either via the Helm chart value (so that `-recursor` parameters are added to the command line of the client and server pods), or via the `extraConfig` value in the Helm chart, so that it gets added to the `extra-from-values.json` ConfigMap.

However, trying to use `external.service.consul`does not work. When I try to ping it, I get ‘bad address’. Using `dig`, I can see it returning an A record in the end, but it’s like recursion doesn’t work outside of using `dig`.

`external-node.node.service.consul` works, but trying to remember which service uses which URL format runs kind of counter to service discovery IMO.

Inspecting the `dig` answers, they look identical except that the `node` URL also includes the `NodeMeta` entries as TXT records. Shouldn’t matter for my purposes here.

Using `nslookup external.service.consul`, the resolving stops at the CNAME.  
Using `nslookup external-node.node.service.consul`, the A record is returned.

Is this a limitation or a bug or have I done something wrongin setting up either the external service or the DNS?

---

<div class="post-metadata">

**Author:** ![arbhatta-blk](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/arbhatta-blk/32/21841_2.png) [@arbhatta-blk](https://discuss.hashicorp.com/u/arbhatta-blk)\
**Post date:** [December 20, 2021, 11:12pm UTC](https://discuss.hashicorp.com/t/using-dns-for-external-services-in-kubernetes/26186/2 "2021-12-20T23:12:10Z")

</div>

> [@jon](#):
>
> but trying to remember which service uses which URL format runs kind of counter to service discovery IMO.

Exploring something similar.  
@jon Did you get a solution eventually?

---

<div class="post-metadata">

**Author:** ![blake](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/blake/32/27620_2.png) [@blake](https://discuss.hashicorp.com/u/blake)\
**Post date:** [December 21, 2021, 12:07am UTC](https://discuss.hashicorp.com/t/using-dns-for-external-services-in-kubernetes/26186/3 "2021-12-21T00:07:10Z")

</div>

Hi @jon,

> [@jon](#):
>
> Using `nslookup external.service.consul` , the resolving stops at the CNAME.

You should be able to resolve this issue by setting [`dns_config.enable_truncate`](https://www.consul.io/docs/agent/options#enable_truncate) to `true` in your client and server configs. See [https://github.com/hashicorp/consul/issues/10551#issuecomment-919621937](https://github.com/hashicorp/consul/issues/10551#issuecomment-919621937) for a config example.

> [@jon](#):
>
> I can use `<service>.service.consul` URLs within the pods to talk to the other pods.
> 
> I want to be able to do the same for external services.

Are you attempting to use this in the context of the service mesh, or a simple service discovery use case?

If the former, we’re looking to add support for routing through a terminating gateway to external services that are registered in Consul (e.g., `<name>.service.consul`) using transparent proxy in a near-term patch release for Consul 1.11. I recommend subscribing to issue [#11091](https://github.com/hashicorp/consul/issues/11091) for updates. In the interim, you’ll need to use a statically declared upstream in order to reach external services.
