Closed lawliet89 closed 4 years ago
Hi Yong, thanks for the detailed write-up.
If your services are using {service name}.service.consul
then you can turn off syncing
syncCatalog:
toK8S: false
The syncing is only used so that {service name}
resolves but if you're always adding the .service.consul
then you don't need those services registered since the CoreDNS rule will take any .consul
lookups and redirect them to the Consul servers.
Another workaround is to set
syncCatalog:
k8sPrefix: consul
This will cause the service we register to be consul-consul
and so it won't match xxx.service.consul
.
Thanks for the response. I think turning off syncing to Kubernetes seems like the right solution for me.
I guess this isn't really a bug
per se but more of something that might be useful to be documented since it took me a whole day to figure out what was going on.
I hear you! I think it really is a bug because we shouldn't be syncing the consul
service over since that borks DNS.
@lawliet89 I'm looking at this ticket again and wondering what the use case is for using catalog sync and consul DNS. Because if catalog sync is used, then I think the idea is that you don't need to use Consul DNS.
The only solution I can think of is adding a flag -sync-consul-service
that defaults to false
and controls whether we sync the consul
service into kube.
There isn't one per se. I just had it enabled for "completeness" sake.
Okay I think we should close this then since it's not required and the workaround is confusing.
When Consul Catalog Sync is configured to sync Consul services to Kubernetes,
consul-k8s
will createExternalName
services in Kubernetes for Consul services.This causes DNS resolution issues when resolving
x.service.consul
DNS names from a pod in the same namespace as Consul.Consider Consul running in some namespace called
core
and we are trying to access a service calledprometheus-server
with 2 replicas. CoreDNS is configured as per the documentation.From a pod in the
default
namespace, when we query DNSdig
:compared to a pod in the
core
namespace (same as Consul):This is because of the
/etc/resolv.conf
fordefault
namespace pods configured by Kubernetes:v.s pods in the
core
namespace:What is happening is that in the
core
namespace,xxx.service.consul
is being searched for in thecore.svc.cluster.local
domain and this resolves to theconsul
ExternalName
service that has been synced to Kubernetes by Consul Catalog Sync. Thus, the DNS returned from CoreDNS is unexpected.This does not happen in a cluster running
kube-dns
, as expected becauseExternalName
only works withCoreDNS
. Turning off syncing of services from Consul to Kubernetes and deleting theExternalName
services left behind fixes this issue.If it helps, I deployed Consul using the Helm chart provided by HashiCorp.
Not sure what can be done about this. The only solution I can come up with is to disable syncing from Consul to Kubernetes.