Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kubernetes 如何正确配置入口缓存以使其工作?_Kubernetes_Nginx Ingress_Microk8s - Fatal编程技术网

Kubernetes 如何正确配置入口缓存以使其工作?

Kubernetes 如何正确配置入口缓存以使其工作?,kubernetes,nginx-ingress,microk8s,Kubernetes,Nginx Ingress,Microk8s,我正在尝试为特定主机配置缓存,但得到了404。另外,我的配置似乎没有包含在最终的nginx.conf中。此文件不包含它 我的名字。亚马尔: apiVersion: extensions/v1beta1 kind: Ingress metadata: name: images-ingress labels: last_updated: "14940999355" annotations: kubernetes.io/ingress.class: &q

我正在尝试为特定主机配置缓存,但得到了404。另外,我的配置似乎没有包含在最终的nginx.conf中。此文件不包含它

我的名字。亚马尔:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: images-ingress
  labels:
    last_updated: "14940999355"
  annotations:
    kubernetes.io/ingress.class: "nginx"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    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/server-snippet: |
      proxy_cache static-cache;
      proxy_cache_valid 404 10m;
      proxy_cache_use_stale error timeout updating http_404 http_500 http_502 http_503 http_504;
      proxy_cache_bypass $http_x_purge;
      add_header X-Cache-Status $upstream_cache_status;
spec:
  tls:
  - hosts:
    - static.qwstrs.com
    secretName: letsencrypt-prod
  rules:
  - host: static.qwstrs.com
    http:
      paths:
      - path: /
        backend:
          serviceName: imaginary
          servicePort: 9000
如果我去掉这个样本

  nginx.ingress.kubernetes.io/server-snippet: |
      proxy_cache static-cache;
      proxy_cache_valid 404 10m;
      proxy_cache_use_stale error timeout updating http_404 http_500 http_502 http_503 http_504;
      proxy_cache_bypass $http_x_purge;
      add_header X-Cache-Status $upstream_cache_status;
一切正常,但没有缓存

即使我在上面的代码片段中有一行代码,它也会产生404错误,无法工作

  nginx.ingress.kubernetes.io/server-snippet: |
      proxy_cache static-cache;

要启用缓存,您需要为
nginx入口控制器

配置 您可以通过修改
nginx入口控制器的
ConfigMap
来完成此操作


我已经创建了一个示例来说明它是如何工作的(我想您已经创建了)

首先,创建一个名为
ingres nginx controller
ConfigMap
,如文档中所述:
注意:您可能需要修改
代理缓存路径
设置,但共享内存区域(keys\u zone=静态缓存)应与
代理缓存
指令中的相同

$ cat configmap.yml
# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: ingress-nginx-controller
  namespace: default
data:
  http-snippet: "proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=static-cache:10m max_size=10g  inactive=60m use_temp_path=off;"
  
$ kubectl apply -f configmap.yml 
configmap/ingress-nginx-controller configured
然后创建
ingres
资源(我对您的ingres资源进行了一些修改,以演示
X-Cache-Status
头的工作原理):

最后,我们可以检查:

$ curl -k -I https://static.qwstrs.com
HTTP/2 200
...
x-cache-status: MISS
accept-ranges: bytes

$ curl -k -I https://static.qwstrs.com
HTTP/2 200
...
x-cache-status: HIT
accept-ranges: bytes

有关
代理缓存路径
代理缓存
的更多信息,可以找到。

@ССааааааааааааааа。非常感谢。
$ curl -k -I https://static.qwstrs.com
HTTP/2 200
...
x-cache-status: MISS
accept-ranges: bytes

$ curl -k -I https://static.qwstrs.com
HTTP/2 200
...
x-cache-status: HIT
accept-ranges: bytes