Manifest to Redirect Non-www Requests to www When Using ALB with AWS EKS Ingress

2024-05-20 20:20 (7 months ago) ytyng

Here is the translation of the provided Japanese blog post content into English:


This is an Ingress manifest that responds to a request without "www" by redirecting to a URL with "www".

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: no-www-ytyng-com-ingress
  namespace: ytyng
  labels:
    app: my-k8s-alb
  annotations:
    alb.ingress.kubernetes.io/actions.redirect-to-eks: >
      {"type": "redirect", "redirectConfig": {"host": "www.ytyng.com", "path": "/", "protocol": "HTTPS", "port":"443", "query": "", "statusCode": "HTTP_301"}}
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]'
    alb.ingress.kubernetes.io/group.name: my-k8s-alb
    alb.ingress.kubernetes.io/group.order: "5"
    alb.ingress.kubernetes.io/load-balancer-name: my-k8s-alb

spec:
  ingressClassName: alb
  rules:
    - host: ytyng.com
      http:
        paths:
          - pathType: ImplementationSpecific
            backend:
              service:
                name: redirect-to-eks
                port:
                  name: use-annotation

After applying the manifest, check the ALB listener rules and look at the EKS cluster → Resources → Resource Type → Services and Networking → Ingress → the name of this manifest, and check the event logs.

Currently unrated

Comments

Archive

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011