Home > front end >  How to service multiple solution webui through one port using k8s ingress service
How to service multiple solution webui through one port using k8s ingress service

Time:04-09

I need to service gitlab, nexus and jupyterhub based on URL using one open port using k8s ingress.

If the path is written as "/" when create ingress, it works normally, but if you write "/nexus" like this, a problem occurs during the redirection process.

Have any of you solved the same problem? Please help.

enter image description here

my ingress.yaml as below

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  creationTimestamp: "2022-04-06T05:56:40Z"
  generation: 7
  name: nexus-ing
  namespace: nexus
  resourceVersion: "119075924"
  selfLink: /apis/extensions/v1beta1/namespaces/nexus/ingresses/nexus-ing
  uid: 4b4f97e4-225e-4faa-aba3-6af73f69c21d
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - backend:
          serviceName: nexus-service
          servicePort: 8081
        path: /nexus(/|$)(.*)
        pathType: ImplementationSpecific
status:
  loadBalancer:
    ingress:
    - ip: 172.30.1.87

CodePudding user response:

That's a problem with nexus itself. Your ingress works as intended, and you cannot do more from this side.

The problem here is that nexus webpage, i.e. index.html, requests resources in such a way that it's looking at the wrong place. You can see this by opening the network tab and inspecting the request URL of the missing statics.

To see what I mean, let's examine the below HTML image tags.

<img id="1" src="./statics/some-image.svg" alt="some image" />

<img id="2" src="/statics/some-image.svg" alt="some image" />

You can see that the first one, is using relative path, and would work with your configuration since the request URL would be relative to the location in the browser and then the nexus part gets stripped by the ingress controller.

However, the second one is using absolute path, so it will not have the nexus part in the request URL and the ingress controller will not be able to route it to the correct service.

This is a common problem when stripping path prefixes. It only works fully when the application you are serving when stripping a prefix is correctly configured.

In your case this means, checking the documentation of the services, if you have any way to influence this.

It may be more straight forward to route based on hostname instead of path. I.e nexus.myhost.com. For that, you would need a domain and point the corresponding A records to your ingress services IP / use a wildcard record.

CodePudding user response:

I solve this problem by myself

  1. I edited my pc hosts file
172.30.1.87     nexus.k8s.io
172.30.1.87     gitlab.k8s.io
  1. I edited each Ingress in same service namespace
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
  namespace: nexus
spec:
  ingressClassName: nginx
  rules:
  - host: nexus.k8s.io
    http:
      paths:
      - backend:
          serviceName: nexus-service
          servicePort: 8081
        path: /
status:
  loadBalancer:
    ingress:
    - ip: 172.30.1.87
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: gitlab-ingress
  namespace: gitlab
spec:
  ingressClassName: nginx
  rules:
  - host: gitlab.k8s.io
    http:
      paths:
      - backend:
          serviceName: gitlab-webservice
          servicePort: 8181
        path: /
status:
  loadBalancer:
    ingress:
    - ip: 172.30.1.87
  1. connect test ingress Hostname ingress Controller Nodeport

enter image description here

enter image description here

  • Related