Kubernetes Cross Namespace Ingress Network

8/16/2018

I have a simple ingress network, I want to access services at different namespaces, from this ingress network.

How I can do this? My ingress network yaml file:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  rules:
 - host: api.myhost.com
 http:
 paths:
  - backend:
      serviceName: bookapi-2
      servicePort: 8080
    path: /booking-service/

I've set the ExternalNames service type to the yaml file:

 apiVersion: v1
 kind: Service
 metadata:
   name: bookapi-2
   namespace: booking-namespace
 spec:
   type: ExternalName
   externalName: bookapi-2
   ports:
     - name: app
     protocol: TCP
      port: 8080
      targetPort: 8080
   selector:
      app: bookapi-2
      tier: backend-2
-- ColossusMark1
kubernetes
kubernetes-ingress
microservices

1 Answer

8/17/2018

An ExternalName service is a special case of service that does not have selectors and uses DNS names instead.

You can find out more about ExternalName service from the official Kubernetes documentation:

When you want to access a service from a different namespace, your yaml could, for example, look like this:

kind: Service
apiVersion: v1
metadata:
  name: test-service-1
  namespace: namespace-a
spec:
  type: ExternalName
  externalName: test-service-2.namespace-b.svc.cluster.local
  ports:
  - port: 80

As to your Ingress yaml file, please recheck it and make sure it is compliant with the official examples, for example this one as it contains some inconsistency:

apiVersion: extensions/v1beta1  
kind: Ingress  
metadata:  
  name: my-ingress  
spec:  
  rules:  
  - host: www.mysite.com  
    http:  
      paths:  
      - backend:  
          serviceName: website  
          servicePort: 80  
  - host: forums.mysite.com  
    http:  
      paths:  
      - path:  
        backend:  
          serviceName: forums  
          servicePort: 80

Please also recheck ExternalName yaml as it has TargetPorts and selectors which are not used in this type of Service and make sure that:

ExternalName Services are available only with kube-dns version 1.7 and later.

In case you will not succeed, please share the kind of problem you have meet.

-- aurelius
Source: StackOverflow