Application gateway rewrite rules

Shreyas Arani 271 Reputation points
2021-12-10T19:08:43.667+00:00

we are using application gateway in our AKS cluster. The requirement is that we need to remove port number from request of an api .
for example
https://my-domain.com//v1/location - 200{"headers":{},"body":", X.X.X.X:24487: Name does not resolve","statusCode":"BAD_REQUEST","statusCodeValue":400}

from the above request we need to remove port number, Because of this port number our api is failing.

we tried rewrite rules to parse ports number but the set rule is removed when we have any service deployment / POD failure in the cluster. Thus, affecting the rule implementation.

Please suggest how to resolve this issue.
@SRIJIT-BOSE-MSFT can you help?

Azure Application Gateway
Azure Application Gateway
An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.
1,213 questions
Azure Kubernetes Service
Azure Kubernetes Service
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,447 questions
{count} votes

2 answers

Sort by: Most helpful
  1. SRIJIT-BOSE-MSFT 4,346 Reputation points Microsoft Employee
    2021-12-13T08:55:16.447+00:00

    @Shreyas Arani , thanks for the reply.

    Azure Application Gateway Ingress Controller annotations keep getting added/updated. Please check here for updated list of supported annotations. You can also stay up-to-date with release updates from Azure Application Gateway Ingress Controller here.

    In this particular case,

    Rewrite Rule Set

    This annotation allows to assign an existing rewrite rule set to the corresponding request routing rule.

    Usage
       appgw.ingress.kubernetes.io/rewrite-rule-set: <rewrite rule set>  
    
    Example
       apiVersion: extensions/v1beta1  
       kind: Ingress  
       metadata:  
         name: go-server-ingress-bkprefix  
         namespace: test-ag  
         annotations:  
           kubernetes.io/ingress.class: azure/application-gateway  
           appgw.ingress.kubernetes.io/rewrite-rule-set: add-custom-response-header  
       spec:  
         rules:  
        - http:  
             paths:  
             - path: /  
               backend:  
                 serviceName: go-server-service  
                 servicePort: 8080  
    

    Using this will ensure that the Ingress Controller takes the existing static rewrite rules on the Application Gateway into account and does not override this in the process of updates.

    References:

    ----
    Hope this helps.

    Please "Accept as Answer" if it helped, so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.
    0 comments No comments

  2. Mayur Dhande 1 Reputation point
    2022-02-07T14:56:57.417+00:00

    @SRIJIT-BOSE-MSFT the documentation seems to be vague.
    One the one hand it says add-custom-response-header, but it also says
    This annotation allows to assign an existing rewrite rule set to the corresponding request routing rule.

    What should be the value for this annotation ?
    Should it be a custom header something like

    appgw.ingress.kubernetes.io/rewrite-rule-set: 'myheader:value'  
    

    Or I need to create a Rewrite Set and mention it's name in the value,

    appgw.ingress.kubernetes.io/rewrite-rule-set: 'myrewriteset'  
    

    ----------

    In fact, I tried both the options, and it did not work.
    For second option, I could not see any Associations of rule with the rewrite set after applying the ingress rule.

    Container image I am using is: azure-application-gateway/kubernetes-ingress:1.5.0
    AKS version: 1.21

    Could someone explain how to make this work ?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.