Home > Enterprise >  How to convert a prefix domain name to a directory/prefix in EKS(kubernetes)
How to convert a prefix domain name to a directory/prefix in EKS(kubernetes)

Time:12-16

I have a Route53 and EKS environment.

I have written several domain names in EKS ingress-controller, and now I need to access each directory using URLs.

If you have a domain name, "example.com", and it has a prefix, you want to treat the prefix as a directory after the domain name. (ex:main.example.com -> example.com/main) (ex:settings.example.com -> example.com/settings)

In other words, if you enter "main.example.com" in your browser's URL, it will access the pod example.com/main that is being routed.

I'm spending a lot of working hours on this issue. Do you know the solution?

CodePudding user response:

Update base on your feedback, what you may be looking for is using nginx server block rather than k8s ingress rules:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    ...
    nginx.ingress.kubernetes.io/server-snippet: |
      server {
        location / {
          server_name ~^(?<name>[\w-] )\.example\.com$;
          proxy_pass http://<your k8s service>/$name;
          proxy_set_header Host $host;
        }
      }
spec:
  rules:
  - host: main.example.com
  - host: setting.example.com
  • Related