Workaround Kubernetes Ingress to allow wildcard hosts?

While Kong supports routing based on host headers with wildcards, the Kubernetes Ingress API does not (see this issue for a discussion).

Other ingress controllers, like the nginx and traefik appear to have workarounds, either by allowing for a file-based configuration or by using a special Ingress annotation.

Are there plans for the Kong Ingress Controller to support this? It is surprising that the Kong Ingress Controller does not support the same configurations as the standard Kong.

echo "                                                                                                                                                                        <<<
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: wildcard-host
spec:
  rules:
  - host: '*.foo.com'
    http:
      paths:
      - path: /
        backend:
          serviceName: svcA
          servicePort: 80
" | kubectl apply -f -

The above is correctly parsed and populated in Kong.
What error do you run into?

Thanks for the reply. It looks like using a wildcard at the beginning of the host is supported by the native Kubernetes Ingress resource (but needs to be in quotes, which I just learned from your reply). However, we’d like the wildcard to be at the end of the host, so we can use rules like host: blue.* and host: green.* to alternate between blue/green deployments.

The error we get is:

# * spec.rules[0].host: Invalid value: "blue.*": a wildcard DNS-1123 subdomain must start with '*.', followed by a valid DNS subdomain, which must consist of lower case alphanumeric characters, '-' or '.' and end with an alphanumeric character (e.g. '*.example.com', regex used for validation is '\*\.[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
# * spec.rules[0].host: Invalid value: "blue.*": a wildcard DNS-1123 subdomain must start with '*.', followed by a valid DNS subdomain, which must consist of lower case alphanumeric characters, '-' or '.' and end with an alphanumeric character (e.g. '*.example.com', regex used for validation is '\*\.[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
#

That unfortunately is not possible at the Ingress level.
We could expand support for it by using host field from the KongIngress resource but then it almost renders the Ingress resource itself quite useless.

You have two options:

I’ve also opened up a feature request in Kong’s Ingress repository for another solution for this problem:

1 Like