Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Wildcard Host for Kubernetes Ingress #792

Closed
jwaldrip opened this issue Oct 31, 2016 · 8 comments
Closed

Question: Wildcard Host for Kubernetes Ingress #792

jwaldrip opened this issue Oct 31, 2016 · 8 comments
Labels

Comments

@jwaldrip
Copy link

jwaldrip commented Oct 31, 2016

How do you create a wildcard host using kubernetes ingress? The following format does not work:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: 3-0-proxy
spec:
  rules:
  - host: '*.mydomain.com'
    http:
      paths:
      - backend:
          serviceName: service-3-0-proxy
          servicePort: 80
        path: /
@emilevauge
Copy link
Member

I suggest you to have a look at the documentation http://docs.traefik.io/basics/#frontends and use the rule HostRegexp

@jjungnickel
Copy link

I can't for the life of me figure out how to select HostRegexp instead of Host from the Ingress resource manifest. Is this something that needs to be implemented in traefik's Kubernetes provider?

@errm errm reopened this Nov 16, 2016
@errm errm added the kind/enhancement a new or improved feature. label Nov 16, 2016
@errm
Copy link
Contributor

errm commented Nov 16, 2016

There is no way to do this with the kubernetes integration at present.

We allow a Path* rule type to be chosen using annotations.

The definition of the kubernetes Ingress type is far more restrictive than the config that traefik can support.

Would it make sense to look at the host to detect if any regex characters are being used then switch the rule type?

Or do we wan't to do something explicit with another annotation?

@zarqman
Copy link
Contributor

zarqman commented Nov 23, 2016

I believe the Kubernetes host definition is too strict to allow for many regex characters, so detection of a regex on the host may not really work.

Given Kubernetes' strictness, simply detecting the wildcard and converting it to an appropriate regex in Traefik might be sufficient for at least a decent portion of use cases (it'd be sufficient here). It'd have the benefit of also being portable, for those experimenting with multiple Ingress controllers.

@ghost
Copy link

ghost commented Dec 11, 2016

I just stumbled upon this. I think the simple solution is to simply allow the "*" what works in kubernetes to work in Traefik as expected instead of some weird {subdomain:[a-z]+} regex prefix. Also path rules allow to select the type via annotation so the same could be done for the host as well.

https://github.com/containous/traefik/blob/master/provider/kubernetes.go#L137

@ghost
Copy link

ghost commented Dec 12, 2016

Hi, any development with this or working hack? I just realized that I really needs this for my CDN forward proxy because I am using subdomains as client identifiers and I already have * host routed to my app because of this so I cannot have two of these ingresses.

I'm not a golang guy but something like:

if _, exists := templateObjects.Frontends[r.Host+pa.Path].Routes[r.Host]; !exists {
        ruleType := 'Host'
        rule := r.Host
        if _, wildcard := Contains('*', r.Host) {
               ruleType = 'HostRegexp'
               rule = Replace(rule, '*', '{subdomain:[a-z]+}')
         }
	templateObjects.Frontends[r.Host+pa.Path].Routes[r.Host] = types.Route{
		ruleType + ":" + rule,
        }
}

Although I am not sure how Traefik works internally, maybe wildcards are supported only for subdomains/beginning of the host, in which case the HasPrefix() should be used instead of Contains(). And also I'm not sure how the host array is supposed to be keyed as well so that's for someone more knowledgeable to figure out.

@sheerun
Copy link
Contributor

sheerun commented Jan 9, 2017

Same issue ;( If someone manages to hack it somehow, please post here

@sheerun
Copy link
Contributor

sheerun commented Jan 9, 2017

I've prepared an enhancement at #1029

sheerun added a commit to sheerun/traefik that referenced this issue Jan 11, 2017
@traefik traefik locked and limited conversation to collaborators Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants