1

I have a service running on Kubernetes available on a domain like example.com. I'm trying to add a path which should redirect to a wordpress blog. So I need to add a rule: everithing that goes in /blog/ should redirect to wordpress, otherwise use the main app.

I tried to include a regexp for the main application path to include all except /blog/

  - host: example.com
    http:
      paths:
      - path: /^(?!blog).*$

but I keep getting must be a valid regex or if I remove the slash, it says must be an absolute path. I can't seem to find a way how to do that, it just keeps redirecting to my root app

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: MainAppService
          servicePort: 3010
      - path: /blog/*
        backend:
          serviceName: BlogService
          servicePort: 3020
Liviu
  • 452
  • 1
  • 5
  • 14

1 Answers1

2

Try this -

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    kubernetes.io/ingress.class: nginx
  name: app
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /(.*)
        backend:
          serviceName: MainAppService
          servicePort: 3010
      - path: /blog/(.*)
        backend: 
          serviceName: BlogService
          servicePort: 3020

I guess, this should work

Tushar Mahajan
  • 2,044
  • 1
  • 7
  • 18