You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "illflavored (via GitHub)" <gi...@apache.org> on 2023/06/12 22:45:44 UTC

[GitHub] [apisix] illflavored opened a new issue, #9648: help request: How To Set Custom Headers with k8s Ingress .yaml (syntax)

illflavored opened a new issue, #9648:
URL: https://github.com/apache/apisix/issues/9648

   ### Description
   
   I'm trying to use the response-rewrite headers.set functionality found here:
   https://apisix.apache.org/zh/docs/apisix/plugins/response-rewrite/
   
   > Rewrite the response header. The format is {"name": "value", ...}. This value can contain NGINX variables $varin the format, eg $remote_addr $balancer_ip.
   
   I'm on kubernetes, so I need to be able to utilize this in .yaml form, but the documentation doesn't give an example. I've tried a few variations as a best guess. My ingress:
   
   ```
   apiVersion: networking.k8s.io/v1
   kind: Ingress
   metadata:
     name: my-ingress
     namespace: my-namespace
     annotations:
       cert-manager.io/cluster-issuer: "letsencrypt-apisix"
       k8s.apisix.apache.org/rewrite-target-regex: "/my-path/(.*)"
       k8s.apisix.apache.org/rewrite-target-regex-template: "/$1"
       k8s.apisix.apache.org/http-to-https: "true"
       kubernetes.io/tls-acme: "true"
       k8s.apisix.apache.org/enable-response-rewrite: "true"
       k8s.apisix.apache.org/response-rewrite:
         headers:
           set:
             name: "Location",
             exists-action: "override"
             value: '@("https://" + context.Request.OriginalUrl.Host + context.Request.OriginalUrl.Path)'
   spec:
     ingressClassName: apisix
     tls:
       - hosts:
           - mydomain.com
         secretName: my-secret
     rules:
     - host: mydomain.com
       http:
         paths:
         - backend:
             service:
               name: my-service
               port:
                 number: 80
           path: /my-path
           pathType: Prefix
   ```
   
   My kubectl apply is consistently giving me output message as such:
   
   ```
   kubectl apply -f apisix.yaml
   error: error validating "apisix.yaml": error validating data: ValidationError(Ingress.metadata.annotations.k8s.apisix.apache.org/response-rewrite): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.annotations: got "map", expected "string"; if you choose to ignore these errors, turn validation off with --validate=false
   ```
   
   Specifically what I'm trying to do is port over these header rules from another API manager we're using on the inbound requests. 
   
   ```
   <set-header name="Location" exists-action="override">
       <value>@("https://" + context.Request.OriginalUrl.Host + context.Request.OriginalUrl.Path)</value>
   </set-header> 
   ```
   
   ### Environment
   
   - APISIX helm chart version: apisix-1.4.0
   - APP VERSION 3.3.0
   - Operating system k8s
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org