0

The Cluster is running multiple NGINX pods in one service, deployed over a Deployment YAML file. I'm trying to cache GET Requests on both services a rest.js client, and an API web-application. I'm struggling to make caching work with this ingress resource:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: myNamespace
  name: test-ingress
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
    acme.cert-manager.io/http01-edit-in-place: "true"
    kubernetes.io/ingress.class: nginx
    ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/proxy-body-size: 8m
    nginx.ingress.kubernetes.io/proxy-buffering: "on"
    nginx.ingress.kubernetes.io/http-snippet: "proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=static-cache:32m use_temp_path=off max_size=4g inactive=24h;"
    nginx.ingress.kubernetes.io/server-snippet: |
      proxy_cache static-cache;
      proxy_cache_lock on;
      proxy_cache_valid any 60m;
      proxy_ignore_headers "Set-Cookie";
      proxy_hide_header "Set-Cookie"
      add_header Cache-Control "public";
      add_header X-Cache-Status $upstream_cache_status;
spec:
  rules:
  - host: "{{ HOST }}"
    http:
      paths:
        - pathType: Prefix
          path: "/"
          backend:
            service:
              name: server
              port:
                number: 8080
  - host: "client-{{ HOST }}"
    http:
      paths:
        - pathType: Prefix
          path: "/"
          backend:
            service:
              name: client
              port:
                number: 5500
  tls:
  - hosts:
    - "{{ HOST }}"
    - "testclientapplication-{{ HOST }}"
    secretName: ingress-cert

In the response to any requests are the content-length, content-type, date and the strict-transport-security header.

Previously i was attempting to get it to run over a ConfigMap but that didn't work out either.

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: myNamespace
  name: ingress-nginx-controller
data:
  http-snippet: "proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=static-cache:32m use_temp_path=off max_size=4g inactive=24h;"

The service and client application are running fine but i'm struggeling to enable caching. Some advice on how to enable caching would be highly appreciated.

JMG
  • 11
  • 2
  • Try debugging steps mentioned in this [link](https://stackoverflow.com/questions/62245119/ingress-nginx-cache). Try changing the snippet from this [link](https://serverfault.com/questions/583570/understanding-the-nginx-proxy-cache-path-directive) that might resolve this issue. – Sai Chandra Gadde Nov 03 '22 at 11:35

0 Answers0