How can the ingress controller receive traffic from a certain port in loadbalancer to a specific path

32 Views Asked by At

I have a local k3d cluster, and there is a mapping port in loadbalancer (8081:80 and 8082:80). I have such an ingress controller:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ing
  annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              number: 80
  - http:
      paths:
      - path: /{slug}
        pathType: Prefix
        backend:
          service:
            name: redirectnginx
            port:
              number: 80

The nginx service is for a web app that creates shortened links, and the redirectnginx service is for app that only accepts /slug for redirecting to any website. With this ingress manifest, the application with the creation of short links is available from both ports (localhost:8081/, localhost:8082/), and the /admin, /login, /shortenlink paths are no longer available, because ingress perceives all paths ( except / ) as /{slug}. Therefore, if possible, I would like to separate these paths so that the path / receives traffic only from port 8081 and /{slug} from port 8082.

I tried to create 2 ingress controllers, but in the end only 1 worked

0

There are 0 best solutions below