1

I am trying to cache response of my API but I am getting X-Cache-Status: MISS every time. My Api return a text/plain response('hello' & 'bye'). I don't know what I am missing, also the setup is on minikube.

My Ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test
  labels:
    name: test
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/cache-enable: "true"
    nginx.ingress.kubernetes.io/proxy-buffering: "on"  
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_cache mycache;
      proxy_cache_valid 404 5m;
      proxy_ignore_headers Cache-Control;
      add_header X-Cache-Status $upstream_cache_status;
spec:
  rules:
  - host: myhost.local
    http:
      paths:
        - path: /hello
          pathType: Prefix
          backend:
            service:
              name: hello-api
              port:
                number: 8080
        - path: /bye
          pathType: Prefix
          backend:
            service: bye
              name: bye-api
              port:
                number: 8081

ingress config map

apiVersion: v1
kind: ConfigMap
metadata:
  name: ingress-nginx-controller
  namespace: ingress-nginx
data:
  http-snippet: "proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=mycache:10m use_temp_path=off max_size=4g inactive=60m;"

For some reason Cache-Control is set to Private.

I tried solutions mentioned here, but no success.

How to properly configure ingress cache to get it working?

Ingress nginx cache

Alan
  • 61
  • 2
  • 6
  • fyi Im running this on minikube with the default ingress controller installed via `minikube addons enable ingress` – Alan Jun 06 '22 at 18:27

2 Answers2

2

show kubectl -n ingresscontrollernamespace describe pod ingresscontrollerpodname

https://kubernetes.slack.com/archives/CANQGM8BA/p1654524670938769

Long
  • 31
  • 4
1

Looking closely, might the only "real" difference be a missing trailing s in http-snippets? I found the http-snippets example in the NGINX Ingress Controller Documentation

Your config map with the s:

apiVersion: v1
kind: ConfigMap
metadata:
  name: ingress-nginx-controller
  namespace: ingress-nginx
data:
  http-snippets: "proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=mycache:10m use_temp_path=off max_size=4g inactive=60m;"

Generally I hoped for a more concise documentation or guide on how to setup API Caching with NGINX Ingress Controller as it is currently the defacto standard ingress and everybody is always performance tuning.

sebisnow
  • 1,671
  • 17
  • 26