skip to Main Content

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

2

Answers


  1. show kubectl -n ingresscontrollernamespace describe pod ingresscontrollerpodname

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

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search