【问题标题】:Is there a canary property to check in nginx-ingress snippet是否有金丝雀属性可以检查 nginx-ingress 片段
【发布时间】:2021-11-07 04:23:48
【问题描述】:

我有这两个用于蓝色(生产)和绿色(金丝雀)部署的入口,我希望在我的 nginx sn-p 中根据请求是来自生产服务还是来自金丝雀来设置某些内容。 sn-p 中的if 语句应该是什么?

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: blue-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      if (canary) { <--- WHAT CAN I CHECK HERE?
        ...
      } else {
        ...
      }
spec:
  ...
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: green-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/canary: "true"
    nginx.ingress.kubernetes.io/canary-by-cookie: "green"
spec:
  ...

【问题讨论】:

    标签: kubernetes nginx-ingress canary-deployment


    【解决方案1】:

    我认为没有可以检查的特定 canary 属性。
    但是,您可以查找您的金丝雀服务可以提供的特定 cookie

    if ($http_cookie ~* "id=([^;]+)(?:;|$)") {
        ...
    }
    

    请注意,虽然 nginx 确实有 if directive,但没有 else。 else 的等价物是所有没有被if 修改的东西。

    【讨论】:

    • 你好@ManoloCarrascoMoñino。有什么进展吗?
    • 嗨,问题是我没有要在语句中测试的 cookie,我的意思是我可以在 blue-ingress 中设置一个 cookie,但不能在 green-ingress 中设置,因为它是一个金丝雀不支持 nginx sn -p
    • 我相信没有其他可能的解决方案。
    • @p10l:您对 else 等价物的回答确实帮助我解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 1970-01-01
    • 1970-01-01
    • 2016-06-01
    相关资源
    最近更新 更多