How to redirect EKS AWS ALB Ingress to another domain

In order to redirect the EKS AWS ALB Ingress host you can use alb.ingress.kubernetes.io/actions annotation to do its job to redirect ALB Listener rule from artifactory.domain.com to artifactory-new.domain.com

Imagine having artifactory.domain.com Ingress manifest:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: artifactory
  namespace: default
  labels:
    app: artifactory
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/certificate-arn: ***
    alb.ingress.kubernetes.io/scheme: internal
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/healthcheck-port: "80"
    alb.ingress.kubernetes.io/healthcheck-path: /api/health
    alb.ingress.kubernetes.io/security-groups: "***"
spec:
  backend:
    serviceName: artifactory
    servicePort: 8082
  rules:
    - host: artifactory.domain.com
      http:
        paths:
          - path: /
            backend:
              serviceName: artifactory
              servicePort: 8082
          - path: /artifactory/
            backend:
              serviceName: artifactory
              servicePort: 8081

And we need to adjust the manifest with the following annotations and rules:

  • alb.ingress.kubernetes.io/actions.redirect-to-new-domain
  • serviceName: redirect-to-new-domain
  • servicePort: use-annotation

A final manifest example that redirects from artifactory.domain.com to artifactory-new.domain.com:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: artifactory
  namespace: default
  labels:
    app: artifactory
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/certificate-arn: ***
    alb.ingress.kubernetes.io/scheme: internal
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/healthcheck-port: "80"
    alb.ingress.kubernetes.io/healthcheck-path: /api/health
    alb.ingress.kubernetes.io/security-groups: "***"
    alb.ingress.kubernetes.io/actions.redirect-to-new-domain: '{"Type":"redirect","RedirectConfig":{"Host":"artifactory-new.domain.com","Path":"/#{path}","Port":"443","Protocol":"HTTPS","Query":"#{query}","StatusCode":"HTTP_301"}}'
spec:
  backend:
    serviceName: artifactory
    servicePort: 8082
  rules:
    - host: artifactory.domain.com
      http:
        paths:
          - path: /
            backend:
              serviceName: redirect-to-new-domain
              servicePort: use-annotation
          - path: /artifactory/
            backend:
              serviceName: redirect-to-new-domain
              servicePort: use-annotation

Final result from AWS Console:

Result after implementing a redirect

Click here to get more details on possible combinations of how to use annotations and different routing rules.

If you need to rewrite any request set rule path to path: /*

Bear in mind that each ALB Ingress Controller Reconciliation change will be reflected approximately in 10-20 minutes.

1 thought on “How to redirect EKS AWS ALB Ingress to another domain

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.