Running Kubernetes locally via Minikube always returns 304 not modified resource

12/27/2019

I'm using an Nginx ingress controller to direct traffic to a specific service, although right now there is only one. The service points to a Node.js app, and the html returned from the server is always 304 not modified. Does anyone have any ideas as to how I can return 200 and prevent cache?

Here's my Ingress settings:

apiVersion: networking.k8s.io/v1beta1 # for versions before 1.14 use extensions/v1beta1
kind: Ingress
metadata:
  name: kludge-ingress
  namespace: kludge
  annotations:
    # use the shared ingress-nginx
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: kludge.local
      http:
        paths:
          - path: /
            backend:
              serviceName: kludge-front-end
              servicePort: 80

Service:

apiVersion: v1
kind: Service
metadata:
  name: kludge-front-end
  namespace: kludge
spec:
  type: NodePort
  selector:
    name: kludge-front-end
  ports:
    - name: http
      protocol: TCP
      nodePort: 30080
      port: 80
      targetPort: 3000

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kludge-front-end
  namespace: kludge
spec:
  replicas: 3
  selector:
    matchLabels:
      name: kludge-front-end
  template:
      metadata:
        namespace: kludge
        labels:
          name: kludge-front-end
      spec:
        containers:
          - name: kludge-front-end
            image: gibson445/kludge-front-end
            ports:
              - containerPort: 3000
            imagePullPolicy: Never

enter image description here

-- thatguyjono
kubernetes
minikube
nginx
nginx-ingress

1 Answer

12/27/2019

There's a pretty good chance you'd actually want configuration-snippet to add the header Cache-Control.

Example:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myingress
  namespace: mynamespace
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
      add_header Cache-Control "max-age=0, no-cache, no-store, must-revalidate";
-- Arghya Sadhu
Source: StackOverflow