<p>i'm trying to config my ingress controller to allow only GET method on it ,
i saw there is a cors config that i can use to do that , but no idea why it doesn't work here my config :</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-elasticsearch-service
  namespace: my-application-namespace
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/enable-cors: &quot;true&quot;
    nginx.ingress.kubernetes.io/cors-allow-methods: &quot;GET&quot;
    nginx.ingress.kubernetes.io/cors-allow-origin: &quot;https://my-host.com&quot;
spec:
  tls:
  - hosts:
    - my-host.com
    secretName: my-ingress-secret
  rules:
  - host: my-host.com
    http:
      paths:
      - path: /elasticsearch/(.+)
        pathType: Prefix
        backend:
          service:
            name: elasticsearch-service
            port:
              number: 9200
</code></pre>
<p>as you guess i'm trying to expose an elasticsearch but only the get method so my frontend can use it directly .</p>
<p>Another option i saw is that it's possible to config nginx with &quot;nginx.ingress.kubernetes.io/server-snippet&quot; like the following (from documentation ) :</p>
<pre><code>
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/server-snippet: |
        set $agentflag 0;

        if ($http_user_agent ~* &quot;(Mobile)&quot; ){
          set $agentflag 1;
        }

        if ( $agentflag = 1 ) {
          return 301 https://m.example.com;
        } 
</code></pre>
<p>i've tried both config i put this in annotations :</p>
<pre><code>nginx.ingress.kubernetes.io/server-snippet: |
      location ~* &quot;^/elasticsearch/(.+)&quot; {
          if ($request_method != GET) {
            return 403;
          }
        }
</code></pre>
<p>but my entire elasticsearch GET route went into a 404 for some reason , not sure why .
but the other HTTP method return a 403 .</p>
<p>Anyone got an idea on how can i achieve this properly ?</p>
<p>Thanks .</p>

kevP-Sirius
<p>Solved finally ,
i used the wrong snippet i had to use configuration-snippet instead of server-snippet and without the location condition because it was overwriting the kubernetes config and i couldnt reproduce the way kubernetes redirect inside my location  .</p>
<p>As a result the final solution look like the following :</p>
<pre><code> nginx.ingress.kubernetes.io/configuration-snippet: |
      
          if ($request_method != GET) {
            return 403;
          }
        

</code></pre>
