Vikas Rathore
Vikas Rathore

Reputation: 8801

How to map host path with service path in ingress?

How to create an alb ingress such that only "/" will redirect to a service that shows static files in service-1. all other paths should redirect to service 2. it will host something like this

spec:
  rules:
    - host: a.abc.com
      http:
        paths:
          - path: /
            backend:
              serviceName: service-1
              servicePort: 80
          - path: /v1
            backend:
              serviceName: service-2/v1
              servicePort: 9090

I know I can't have service-2/v1 on serviceName but I want to map /v1 to service-2:9090/v1.

I am hosting some static files in service-1(nginx) which I want to show on / and then /v1 and /admin is on my another service (i.e service-2/v1 and service-2/admin).

Upvotes: 1

Views: 2256

Answers (1)

kool
kool

Reputation: 3613

Name of the service and any other resource may not contain / and % as explained here and if you would like to deploy it, it will show following error:

metadata.name: Invalid value: "demo/v1": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start 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])?)*')

So you have to consider changing name of the services, besides that you can specify multiple paths in single Ingress definition:

spec:
  rules:
    - host: a.abc.com
      http:
        paths:
          - path: /
            backend:
              serviceName: service-1
              servicePort: 80
          - path: /v1
            backend:
              serviceName: service-v1
              servicePort: 9090
          - path: /admin #additional path
            backend:
              serviceName: service-admin   #service name pointing to /admin
              servicePort: 9091    #port it will be accessible on

Upvotes: 1

Related Questions