12

I want Ingress to redirect a specific subdomain to one backend and all others to other backend. Basically, I want to define a rule something like the following:

If subdomain is foo.bar.com then go to s1, for all other subdomains go to s2

When I define the rules as shown below in the Ingress spec, I get this exception at deployment:

Error: UPGRADE FAILED: cannot re-use a name that is still in use

When I change *.bar.com to demo.bar.com it works, however.

Here's my Ingress resource spec:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - backend:
          serviceName: s1
          servicePort: 80
  - host: *.bar.com
    http:
      paths:
      - backend:
          serviceName: s2
          servicePort: 80

Anyone has an idea if it is possible or not?

Michael Hausenblas
  • 13,162
  • 4
  • 52
  • 66
fyelci
  • 1,399
  • 2
  • 16
  • 27

4 Answers4

5

This is now possible in Kubernetes with nginx:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
    kubernetes.io/ingress.class: nginx
    kubernetes.io/ingress.global-static-ip-name: web-static-ip
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/server-alias: www.foo.bar
    nginx.ingress.kubernetes.io/use-regex: "true"
  name: foo-bar-ingress
  namespace: test
spec:
  rules:
  - host: 'foo.bar.com'
    http:
      paths:
      - backend:
          serviceName: specific-service
          servicePort: 8080
        path: /(.*)
        pathType: ImplementationSpecific
  - host: '*.bar.com'
    http:
      paths:
      - backend:
          serviceName: general-service
          servicePort: 80
        path: /(.*)
        pathType: ImplementationSpecific
Hendy Irawan
  • 20,498
  • 11
  • 103
  • 114
Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
2

I'm pretty sure this is currently not possible when looking at Issue 41881, but I could be missing something in the most recent version of Kubernetes—we're about to release 1.12 as we speak.

Michael Hausenblas
  • 13,162
  • 4
  • 52
  • 66
1

THere is already a PR raised for supporting the wild card domains in ingress rules. refer the below link

https://github.com/containous/traefik/issues/3884

Can you try Traefik v1.7 and see if the wild card support is enabled.

P Ekambaram
  • 15,499
  • 7
  • 34
  • 59
1

You can use a default backend -

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test
spec:
  - backend:
      serviceName: s2
      servicePort: 80
  rules:
  - host: foo.bar.com
    http:
      paths:
      - backend:
          serviceName: s1
          servicePort: 80
Harkirat Singh
  • 115
  • 2
  • 3