hashicorp / consul-helm

Helm chart to install Consul and other associated components.
Mozilla Public License 2.0
419 stars 385 forks source link

Kubernetes, ConsulCatalog and Traefik - Changing default Sync Rule between K8s and ConsulCatalog? #1043

Closed Raskosk closed 3 years ago

Raskosk commented 3 years ago

I'm running 3 Debian 10.10 VMs with containerd v1.4.6-1 and Kubernetes v1.20.8. As Ingress-Controller, I'm using Traefik v2.4.11 and Consul v1.10 as a central key-value-store for different use-cases. For Consul-Deployment, I'm using the helm chart with a custom values.yaml (see here).

In my configuration, every registered Kubernetes-Service will be synced towards the ConsulCatalog. And every Consul-Catalog-Service will be synced twice (as Router- and as Service-Rule) with a specific "defaultRule" to Traefik, e.g. <cc_servicename>.<k8s-subdomain>.<fqdn>. So, with that setup, I only need to register my k8s-applications as a service and there will be an auto-generated Rule-Setup to access it from the outside the cluster.

Unfortunately, the ist synced from K8s to ConsulCatalog as <cc_prefix>-<servicename>-<namespace>. So the Traefik-Routing-Rule would be far too long with <cc_prefix>-<servicename>-<namespace>.<subdomain>.<fqdn> -> k8s-myapp0-default.k8s.example.com.

Is there any configuration to deploy all consul-pods in a separate namespace as a free user? Is there any configuration to shorten the default sync Rule of Services between K8s and ConsulCatalog?

ishustava commented 3 years ago

Hey @Raskosk

You can remove the prefix by not setting syncCatalog.consulPrefix (you're setting it to k8s). You can also not add namespace to the synced name by setting syncCatalog.addK8SNamespaceSuffix to false (it's true by default). Note though that you would need to make sure there are no two services named the same across k8s namespaces because Consul OSS doesn't have namespace support.

I hope that answers your question!

Raskosk commented 3 years ago

@ishustava Thanks a lot