我正在尝试缓存 API 的响应,但每次都得到
X-Cache-Status: MISS
。我的 Api 返回文本/简单响应('hello' 和 'bye')。
我不知道我错过了什么,而且设置也在 minikube 上。
我的 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
入口配置图
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;"
由于某种原因
Cache-Control
设置为 Private
。
我尝试了这里提到的解决方案,但没有成功。
show kubectl -n ingresscontrollernamespace 描述 pod ingresscontrollerpodname
https://kubernetes.slack.com/archives/CANQGM8BA/p1654524670938769
仔细观察,唯一“真正”的区别可能是
http-snippets
中缺少尾随 s 吗?
我在 NGINX Ingress Controller 文档中找到了 http-snippets 示例
您的配置图带有 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;"
一般来说,我希望获得关于如何使用 NGINX Ingress Controller 设置 API 缓存的更简洁的文档或指南,因为它目前是事实上的标准入口,并且每个人都在进行性能调整。