Linkerd 流量与 Nginx Ingress Controller 分离

问题描述

我已经部署了 Linkerd 服务网格,并且我的 Kubernetes 集群配置了 Nginx 入口控制器作为 DaemonSet,并且所有入口都在 Linkerd 上工作正常。最近,我添加一个流量拆分功能来运行我的蓝/绿设置,我可以通过单独的入口资源访问这些服务。我已经按照 encapsulation principle 的描述创建了一个 apex-web 服务。如果我在内部找到您这项服务,它可以完美运行。我创建了另一个入口资源,但无法在集群外测试蓝/绿功能。我想提一下,我已将(注入 Linkerd 代理)连接到我所有的 Nginx pod,但它从 Nginx 返回“503 Service Temporarily Unavailable”消息。

我浏览了文档并在 here 之后创建了入口,我可以确认以下注释已添加到入口资源中。

annotations:
kubernetes.io/ingress.class: "Nginx"
Nginx.ingress.kubernetes.io/configuration-snippet: |
  proxy_set_header l5d-dst-override $service_name.$namespace.svc.cluster.local:$service_port;
  grpc_set_header l5d-dst-override $service_name.$namespace.svc.cluster.local:$service_port;

但在集群的外部仍然没有运气。

我正在使用给定的 emojivoto 应用进行测试,所有流量分配和 apex-web 服务都在 this 训练存储库中。

我不太确定出了什么问题以及如何从集群外部解决这个问题。如果有人帮助我解决此 Linkerd、蓝/绿问题,我将不胜感激。

解决方法

tl;dr:nginx 入口 requires 一个 Service 资源具有 Endpoint 资源,以便被视为有效的流量目的地。 repo 中的架构创建了三个 Service 资源,其中一个充当 apex 并且没有 Endpoint 资源,因为它没有选择器,因此 nginx 入口不会将流量发送到因此,leaf 服务将不会获得流量。

存储库中的示例遵循 SMI 规范,定义了一个 apex 服务和两个 leaf 服务。 web-apex 服务没有任何端点,因此 nginx 不会向其发送流量。

根据SMI Spec服务可以是自引用,这意味着一个服务可以同时是顶点叶子 strong> 服务,因此要在此示例中使用 nginx 入口,您可以修改 TrafficSplit definition 以将 spec.service 值从 web-apex 更改为 web-svc

apiVersion: split.smi-spec.io/v1alpha1
kind: TrafficSplit
metadata:
  name: web-svc-ts
  namespace: emojivoto
spec:
  # The root service that clients use to connect to the destination application.
  service: web-svc
  # Services inside the namespace with their own selectors,endpoints and configuration.
  backends:
  - service: web-svc
    # Identical to resources,1 = 1000m
    weight: 500m
  - service: web-svc-2
    weight: 500m
,

我在 Linkerd Slack 频道中提出了这个问题,并在社区的大力支持下解决了这个问题。似乎 Nginx 不喜欢没有端点的服务。我的配置是正确的,并要求将流量拆分中指向的服务更改为具有端点的服务,并解决了问题。

简而言之,我的流量拆分配置了 web-svc 和 web-svc-2 服务。我已将流量拆分 spec.service 更改为相同的 web-svc 并且它有效

这里是更新后的流量分流配置。

apiVersion: split.smi-spec.io/v1alpha1
kind: TrafficSplit
metadata:
  name: web-svc-ts
  namespace: emojivoto
spec:
  # The root service that clients use to connect to the destination application.
  service: web-svc
  # Services inside the namespace with their own selectors,1 = 1000m
    weight: 500m
  - service: web-svc-2
    weight: 500m

感谢支持我解决此问题的 Linkerd 团队。它就像一个魅力。