Skip to main content

Multiple IngressRoutes for One App

Create multiple IngressRoutes to expose the same service under different subdomains — for example, an API endpoint and a web frontend endpoint.

Prerequisites​

base/base-values.yaml

image:
registry: docker.io
repository: traefik/whoami
tag: latest
port: 80

Configuration​

envs/prod/values.yaml

deployment:
enabled: true
replicas: 1

service:
enabled: true

customResources:
- |
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: my-app-api-prod
annotations:
kubernetes.io/ingress.class: public-traefik
external-dns.alpha.kubernetes.io/target: public-v2.{{ .Values.captain_domain }}
spec:
entryPoints:
- web
- websecure
routes:
- match: Host(`my-app-api-prod.apps.{{ .Values.captain_domain }}`)
kind: Rule
services:
- name: '{{ include "app.name" . }}'
namespace: '{{ include "app.namespace" . }}'
port: 80
- |
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: my-app-web-prod
annotations:
kubernetes.io/ingress.class: public-traefik
external-dns.alpha.kubernetes.io/target: public-v2.{{ .Values.captain_domain }}
spec:
entryPoints:
- web
- websecure
routes:
- match: Host(`my-app-web-prod.apps.{{ .Values.captain_domain }}`)
kind: Rule
services:
- name: '{{ include "app.name" . }}'
namespace: '{{ include "app.namespace" . }}'
port: 80

What Gets Created​

ResourceNameHostname
IngressRoutemy-app-api-prodmy-app-api-prod.apps.nonprod.antoniostacos.onglueops.com
IngressRoutemy-app-web-prodmy-app-web-prod.apps.nonprod.antoniostacos.onglueops.com

Both route to the same my-app-prod service.

Verify​

# Both hostnames should resolve (after ~2 min for DNS)
curl https://my-app-api-prod.apps.nonprod.antoniostacos.onglueops.com
curl https://my-app-web-prod.apps.nonprod.antoniostacos.onglueops.com
note

The -prod suffix matches your environment folder name (envs/prod/). If you deploy to a different environment like envs/uat/, the suffix changes accordingly (e.g., my-app-api-uat).

Key Points​

  • Each IngressRoute must have a unique metadata.name within the namespace
  • Both IngressRoutes need their own external-dns annotation so DNS records are created for each hostname
  • You can attach different middlewares to each IngressRoute (e.g., rate limiting on the API, different headers on the web route)