You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过cloud.google.com/v1 BackendConfig配置CDN缓存键包含指定Cookie

解决方案

直接在BackendConfig的spec.cdn.cachePolicy节点下添加includeNamedCookies字段,指定需要纳入缓存键的Cookie名称即可。修改后的完整配置如下:

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: foobar
spec:
  timeoutSec: "{{ timeout_sec }}"
  cdn:
    enabled: true
    cachePolicy:
      includeHost: true
      includeProtocol: true
      includeQueryString: true
      queryStringWhitelist: []
      includeNamedCookies: ["FOOBAR"] # 新增配置:指定要包含的Cookie键
    defaultTtl: "{{ caching_ttl }}"
    maxTtl: "{{ caching_ttl }}"
    clientTtl: "{{ caching_ttl }}"
  healthCheck:
    requestPath: /healthz
  sessionAffinity:
    affinityType: "NONE"
    affinityCookieTtlSec: 86400

这个字段是cloud.google.com/v1版本BackendConfig的标准配置项,添加后Kubernetes的Backend Controller会自动将配置同步到GCP的Backend Service,无需再手动执行gcloud命令,彻底解决配置被自动覆盖的问题。

之所以1.24版本没有这个问题,是因为当时BackendConfig尚未支持该字段,手动修改的配置不会被同步逻辑覆盖;而1.26版本中BackendConfig接管了更多CDN配置的同步工作,导致手动修改的内容会被CRD配置覆盖。


内容的提问来源于stack exchange,提问作者Dan Schalow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 09:46:18