【问题标题】:GKE ingress pass cookie as headerGKE 入口传递 cookie 作为标头
【发布时间】:2021-05-30 19:28:14
【问题描述】:

我想在 google cloud GKE 1.19.7-gke.1302 和 nginx-ingress-0.8.0 helm chart 部署的 nginx ingress 上使用一些 kubernetes ingress(与 ingress 类型无关),以及我的需要是获取一个 cookie 并稍后使用它来对我们的服务进行身份验证。当我使用 nginx 作为部署时,它可以工作,但是当我使用 nginx ingress 时,它似乎忽略了注释。

我尝试将这个配置 sn-p 用于 nginx 入口,它适用于 nginx 部署但不适用于入口:

nginx.ingress.kubernetes.io/configuration-snippet: |
  proxy_set_header "Authorization" "Basic $cookie_myToken";  

这是我的整个入口 yaml:

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-nginx-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    # enable backend redirections
    kubernetes.io/tls-acme: "true"
    # enable stickiness
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/session-cookie-name: "route"
    nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
    nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header "Authorization" "Basic $cookie_myToken";  
spec:
  tls:
  - secretName: supersmart-tls
    hosts: 
    - "test.com"
  defaultBackend:
    service:
      name: supersmart-nodeport
      port:
        number: 80
  rules:
    - host: "test.com"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: my-nodeport
                port:
                  number: 80

有什么想法吗?

【问题讨论】:

  • 您使用的是哪个 GKE 版本?你是如何部署Nginx Ingress Controller 的?你的错误到底是什么?日志中有什么可疑之处?
  • GKE 1.19.7-gke.1302,和nginx-ingress-0.8.0 helm chart部署的nginx ingress,日志中什么都没有,只是忽略了配置sn-p。
  • 你能用this steps重新部署Nginx Ingress 0.44吗?
  • 是的,用 helm 重新安装 nginx ingress 到最新版本解决了这个问题。

标签: nginx kubernetes proxy google-kubernetes-engine kubernetes-ingress


【解决方案1】:

发布此答案以使其在comment section 中发现和解决问题时更加明显。

此问题的根本原因是 Nginx Ingress Controller 配置错误。

在 OP 的设置 Nginx Ingress Controller 中,使用了 v.0.8.0。在将 Nginx IngressNginx Ingress Documentation 重新部署到最新版本 (v0.44.0) 后,它开始正常工作。

是的,用 helm 重新安装 nginx ingress 到最新版本解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 2020-04-22
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-13
    相关资源
    最近更新 更多