Reputation: 537
I have an AKS cluster paired with Azure Application GW with AGIC. Am looking for a simple way to redirect from short name to FQDN for a site. So for example,
contoso -> contoso.com
My assumption is that if I create any manual rules directly in Az App GW, it will get overwritten by AGIC on the next sync. I am not migrated to ALB since we are using private IPs.
Is there an easy yaml definition to achieve this redirect?
In the Ingress definition, I tried the following annotation
appgw.ingress.kubernetes.io/redirect-target: "contoso.com"
But that doesnt seem to work.
Other option would be to use an nginx container that manages redirects. But was hoping there is a simpler solution
Upvotes: 0
Views: 34
Reputation: 3639
You're right that manually configuring rules in Azure Application Gateway (App GW) won’t work because AGIC (Application Gateway Ingress Controller) syncs resources from Kubernetes and overwrites manual changes.
Instead, the best approach is to use Gateway API and HTTPRoute
resources to handle redirections within the Kubernetes setup.
to redirect from "contoso"
to "contoso.com"
in Azure Application Gateway (AGIC) use Gateway API
and HTTPRoute
to define a rule that redirects the short name to the FQDN.
Refer this MSDOC to use URL Redirect for Azure Application Gateway for Containers.
Below is the sample YAML Code for Redirect
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway-01
namespace: test-infra
annotations:
alb.networking.azure.io/alb-namespace: alb-test-infra
alb.networking.azure.io/alb-name: alb-test
spec:
gatewayClassName: azure-alb-external
listeners:
- name: http-listener
port: 80
protocol: HTTP
allowedRoutes:
namespaces:
from: Same
- name: https-listener
port: 443
protocol: HTTPS
allowedRoutes:
namespaces:
from: Same
tls:
mode: Terminate
certificateRefs:
- kind: Secret
group: ""
name: listener-tls-secret
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: http-to-https-contoso-redirect
namespace: test-infra
spec:
parentRefs:
- name: gateway-01
sectionName: http-listener
hostnames:
- "contoso"
rules:
- filters:
- type: RequestRedirect
requestRedirect:
hostname: "contoso.com"
scheme: https
statusCode: 301
Upvotes: 0