Amazon EKS — Advanced Routing

1 minute read

Advanced Routing

ALB Ingress supports sophisticated routing: path-based, host-based, weighted (canary), and header-based routing.


Path-Based Routing

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-routing
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
spec:
  rules:
    - host: api.example.com
      http:
        paths:
          - path: /users
            pathType: Prefix
            backend:
              service:
                name: user-service
                port:
                  number: 80
          - path: /orders
            pathType: Prefix
            backend:
              service:
                name: order-service
                port:
                  number: 80
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend
                port:
                  number: 80

Host-Based Routing

spec:
  rules:
    - host: app.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: main-app
                port:
                  number: 80
    - host: api.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: api-service
                port:
                  number: 80

Canary / Weighted Routing

Split traffic between versions using ALB Ingress groups:

# Stable version (90% traffic)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-stable
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/group.name: my-app
    alb.ingress.kubernetes.io/actions.weighted: |
      {"type":"forward","forwardConfig":{"targetGroups":[
        {"serviceName":"app-v1","servicePort":80,"weight":90},
        {"serviceName":"app-v2","servicePort":80,"weight":10}
      ]}}
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: weighted
                port:
                  name: use-annotation

Ingress Group (Share ALB)

Multiple Ingress resources can share one ALB to save costs:

# Ingress 1
annotations:
  alb.ingress.kubernetes.io/group.name: shared-alb

# Ingress 2
annotations:
  alb.ingress.kubernetes.io/group.name: shared-alb

Both Ingresses create rules on the same ALB instead of creating separate ALBs.


Common Mistakes

Mistake Impact
One ALB per Ingress $18/month per ALB adds up
Wrong path priority Catch-all / matches before /api
Not using Ingress groups Wasted money on duplicate ALBs

What’s Next?

Practice: Load Balancing Exercises.