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:
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.
It does not attach the authorization header