From 5eea63476dd6399243afc0bd9f72f66f73db0f27 Mon Sep 17 00:00:00 2001 From: Evan Anderson Date: Tue, 17 Jul 2018 11:18:41 -0700 Subject: [PATCH] Make (cluster-local) DNS work out of the box by default. --- config/config-domain.yaml | 17 ++++++++++------- pkg/controller/route/resources/service.go | 6 ++---- .../route/resources/virtual_service.go | 6 ++++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/config/config-domain.yaml b/config/config-domain.yaml index df23cf2506be..0c62def41c6f 100644 --- a/config/config-domain.yaml +++ b/config/config-domain.yaml @@ -19,12 +19,15 @@ metadata: namespace: knative-serving data: # These are example settings of domain. - # example.org will be used for routes having app=prod. - # example.org: | + # example.com will be used for routes having app=external. + # example.com: | # selector: - # app: prod + # app: external - # Default value for domain, for routes that does not have app=prod labels. - # Although it will match all routes, it is the least-specific rule so it - # will only be used if no other domain matches. - example.com: | + # This is the default value for domain, for routes that does not have + # app=external labels. This is the least-specific rule and acts as a default. + # The 'svc.cluster.local' default provides a DNS name which works inside the + # cluster. If you want your cluster to be public, you'll need to follow the + # instructions here: + # https://github.com/knative/docs/blob/master/serving/using-a-custom-domain.md#publish-your-domain + svc.cluster.local: | diff --git a/pkg/controller/route/resources/service.go b/pkg/controller/route/resources/service.go index 99f7da2f1bdd..937cb80dfbf5 100644 --- a/pkg/controller/route/resources/service.go +++ b/pkg/controller/route/resources/service.go @@ -39,10 +39,8 @@ func MakeK8sService(route *v1alpha1.Route) *corev1.Service { }, }, Spec: corev1.ServiceSpec{ - Ports: []corev1.ServicePort{{ - Name: PortName, - Port: PortNumber, - }}, + Type: corev1.ServiceTypeExternalName, + ExternalName: "knative-ingressgateway.istio-system.svc.cluster.local", }, } } diff --git a/pkg/controller/route/resources/virtual_service.go b/pkg/controller/route/resources/virtual_service.go index a2cf90fa5244..f4781d59b9c3 100644 --- a/pkg/controller/route/resources/virtual_service.go +++ b/pkg/controller/route/resources/virtual_service.go @@ -80,10 +80,12 @@ func makeVirtualServiceSpec(u *v1alpha1.Route, targets map[string][]traffic.Revi // Traffic originates from outside of the cluster would be of the form "*.domain", or "domain" fmt.Sprintf("*.%s", domain), domain, - // Traffic from inside the cluster will use the FQDN of the Route's headless Service. - names.K8sServiceFullname(u), }, } + if domain != names.K8sServiceFullname(u) { + // Add a local alias for the k8s Service in the svc.cluster.local DNS space. + spec.Hosts = append(spec.Hosts, names.K8sServiceFullname(u)) + } names := []string{} for name := range targets { names = append(names, name)