Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have an Ingress point to a Service from another namespace?

What I want to do is have a service in the default namespace and ingresses in my other namespaces, which point to that service. I tried implementing the service and Ingress shown below, but it didn't work.

kind: Service
apiVersion: v1
metadata:
  name: serviceX
  namespace: default
spec:
  type: ExternalName
  externalName: serviceX.default.svc.cluster.local
ports:
- port: 123


kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: web-ingress-test-vpndev
  namespace: my-namespace
spec:
  tls:
  - hosts:
    - abc.my-namespace.domain.com
    secretName: tls-secret-my-namespace
  rules:
  - http:
      paths:
      - path: "/"
        backend:
          serviceName: serviceX
          servicePort: 123
status:
  loadBalancer:
    ingress: {}

I know that I could implement the service in every namespace, but I was wondering if it's possible to have a single service. If I try to type the externalName of the service in the backend->serviceName handler of the ingress, I get and error saying that the name of the service can only contain numbers, letter and '-'.

like image 702
Daniel Avatar asked Dec 12 '19 13:12

Daniel


People also ask

Should ingress and service be in same namespace?

A couple of things to notice about those ingress rules: They are deployed in the same namespace as the service they point to. They use URL-based routing.

Does ingress need namespace?

The Ingress rules, however, must reside in the namespace where the app that they configure reside.

Can Kubernetes have multiple ingress?

Yes you can multiple ingress backed by single ingress controller nginx, or else you can multiple ingress controller also as per required you can configure.

What is the namespace of ingress controller?

The Ingress Controller handles configuration resources created in any namespace of the cluster. As NGINX is a high-performance load balancer capable of serving many applications at the same time, this option is used by default in our installation manifests and Helm chart. Single-namespace Ingress Controller.


2 Answers

I don't think this is possible and also don't think it's a good idea. Ingress is not a cluster level resource. Each namespace should have its own instance.

like image 83
Dávid Molnár Avatar answered Sep 30 '22 16:09

Dávid Molnár


I would have to say that this isnt a good way. as all of ingress in different NS would be convert to Nginx Rule and take effect in ingress-controller pod.

And if you take a look the Nginx Rule(nginx.conf in ingress-controller pod), you will see each block of location in nginx.conf has variable set $namespace "****"; which means the ingress has been isolated by NS

Also, if you still want to implement your idea, might need to modify the ingress-contoller.

like image 32
Vampire_D Avatar answered Sep 30 '22 16:09

Vampire_D