kubernetes nginx ingress controller / caching static assets

11/6/2017

I have a problem about the images returned via the apps running behind the nginx ingress controller. They always returns 200 instead of an expected 304 once visited.

Digging around, i've found out about the ability to add specific blocks within the servers; so added the following under metadata > annotations :

 ingress.kubernetes.io/server-snippets: |
   location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
     expires 30d;
     add_header Pragma public;
     add_header Cache-Control "public";
   }

The problems persists, so still getting a permanent 200; "ssh'ing" into the nginx pod and doing a cat on the nginx.conf created, I don't see this block appearing anywhere

So am kind of lost about how to improve it. I'm using kube-lego, but did not found out if it could have an impact here

-- Ben
caching
etags
kubernetes
nginx

2 Answers

6/22/2018

In case somebody else stumbles upon this (probably be me in the future), the annotation is nginx.ingress.kubernetes.io/server-snippet.

-- AWippler
Source: StackOverflow

11/8/2017

Support for server-snippets annotation was added in nginx-0.9.0-beta.16. Upgrade your ingress controller image to quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.9.0-beta.16

-- user1279647
Source: StackOverflow