Home > database >  AWS EKS - Wildcard in kubernetes ingress
AWS EKS - Wildcard in kubernetes ingress

Time:11-21

I am trying to understand if I can specify a wildcard domain in the kubernetes ingress configuration. I am running AWS Eks cluster. I have a web pages, where url is structured as client.example.com but for the invite and login app I need to redirect traffic to related invite/login services. All other traffic should normally go to the main-service.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: -ingress
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip


spec:
  rules:
  - host: "*.example.com"
    http:
      paths:
      - backend:
          service:
            name: main-service
            port:
              number: 80
        path: /*
        pathType: ImplementationSpecific
  - host: login.example.com
    http:
      paths:
      - backend:
          service:
            name: login-service
            port:
              number: 80
        path: /*
        pathType: ImplementationSpecific
  - host: invite.example.com
    http:
      paths:
      - backend:
          service:
            name: invite-service
            port:
              number: 80
        path: /*
        pathType: ImplementationSpecific

Is it possible to create such a configuration within Kubernetes ingress?

Thanks

CodePudding user response:

Wildcard hostname is officially supported starting in 1.18:

"Many Ingress providers have supported wildcard hostname matching like .foo.com matching app1.foo.com, but until now the spec assumed an exact FQDN match of the host. Hosts can now be precise matches (for example “foo.bar.com”) or a wildcard (for example “.foo.com”). Precise matches require that the http host header matches the Host setting. Wildcard matches require the http host header is equal to the suffix of the wildcard rule."

https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/#support-for-hostname-wildcards

CodePudding user response:

So after some investigation, wildcard is supported in versions >=1.18. Rules are evaluated in the specified order.

So if you have something like:

*.example.com
invite.example.com
loginm.example.com

then your order should be

invite.example.com
login.example.com

and the last one is

*.example.com
  • Related