Score:0

How to return 204 with Nginx Ingress K8S

gf flag

Is it possible to configure Nginx Ingress to return 204 on a given path?

In Nginx, it would look like this:

location / { return 204; }

Thank you!

Score:0
tr flag

There is a way to do this in AWS scenarios mentioned here: https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.2/guide/ingress/annotations/#actions

nginx supports some annotations like nginx.org/location-snippets (https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-annotations/#snippets-and-custom-templates), which might allow you to pass in an nginx location in the way you describe above.

But I don't know if there is a generic way.

Francois Coulloudon avatar
gf flag
Thank you! You put me on the right way, in fact I had to add annotation on "server-snippet".
Score:0
gf flag

This is what I did:

metadata:
  annotations:
    nginx.ingress.kubernetes.io/server-snippet: |
      location /ping {
        return 204;
        }

More information here: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-snippet

And here: https://stackoverflow.com/questions/52782415/nginx-ingress-config-map-snippets-being-ignored-by-the-nginx-conf

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.