Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

397
Vistas
Redirect non www to www using ALB Ingress Controller

I am trying to redirect a non www request to www. I checked the annotations here https://kubernetes-sigs.github.io/aws-alb-ingress-controller/guide/ingress/annotation/ but could not find specific to non www to www redirect.

I already have a http to https redirect set and it's working.

below is my ingress resource manifest file.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: eks-learning-ingress
  namespace: production
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/certificate-arn: ard878ef678df
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]'
    alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
  labels:
    app: eks-learning-ingress
spec:
  rules:
  - host: www.myhost.in
    http:
      paths:
        - path: /*
          backend:
            serviceName: ssl-redirect
            servicePort: use-annotation
        - path: /*
          backend:
            serviceName: eks-learning-service
            servicePort: 80

Any help in this would be great. Thanks.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There are 2 ways of doing non-www to www redirections, 1. using alb.ingress.kubernetes.io/actions, 2. alb.ingress.kubernetes.io/conditions.


alb.ingress.kubernetes.io/actions

alb.ingress.kubernetes.io/actions.${action-name} Provides a method for configuring custom actions on a listener, such as for Redirect Actions.

The action-name in the annotation must match the serviceName in the ingress rules, and servicePort must be use-annotation.

We need to have one more annotation, which tells ALB how to configure redirection:

alb.ingress.kubernetes.io/actions.redirect-to-www: >
    {"Type":"redirect","RedirectConfig":{"Host":"www.myhost.in","Port":"443","Protocol":"HTTPS","StatusCode":"HTTP_302"}}

And one more host rule to catch your request domain myhost.in and redirect to www.myhost.in

- host: myhost.in
  http:
    paths:
      - path: /*
        backend:
          serviceName: redirect-to-www
          servicePort: use-annotation

alb.ingress.kubernetes.io/conditions

alb.ingress.kubernetes.io/conditions.${conditions-name} Provides a method for specifying routing conditions in addition to original host/path condition on Ingress spec.

The conditions-name in the annotation must match the serviceName in the ingress rules. It can be a either real serviceName or an annotation based action name when servicePort is "use-annotation".

In addition to the annotation we have added above, we continue to add conditions to annotations to filter the request but no need to have the host rule above.

alb.ingress.kubernetes.io/actions.redirect-to-www: >
    {"Type":"redirect","RedirectConfig":{"Host":"www.myhost.in","Port":"443","Protocol":"HTTPS","StatusCode":"HTTP_302"}}
alb.ingress.kubernetes.io/conditions.redirect-to-www: >
    [{"Field":"host-header","HostHeaderConfig":{"Values":["myhost.in"]}}]

We modify the existing host rule you currently have to achieve the redirection.

- host: www.myhost.in
    http:
      paths:
        - path: /*
          backend:
            serviceName: redirect-to-www
            servicePort: use-annotation
        - path: /*
          backend:
            serviceName: ssl-redirect
            servicePort: use-annotation
        - path: /*
          backend:
            serviceName: eks-learning-service
            servicePort: 80
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda