问题描述
我正在尝试为演示配置 Canary 部署,但我无法让流量拆分与 linkerd 一起使用。有趣的是,我能够使用 istio 来实现这一点,而且我发现 istio 比 linkerd 复杂得多。
apiVersion: argoproj.io/v1alpha1
kind: Rollout
Metadata:
name: fish
spec:
[...]
strategy:
canary:
canaryService: canary-svc
stableService: stable-svc
trafficRouting:
smi: {}
steps:
- setWeight: 5
- pause: {}
- setWeight: 20
- pause: {}
- setWeight: 50
- pause: {}
- setWeight: 80
- pause: {}
---
apiVersion: v1
kind: Service
Metadata:
name: canary-svc
spec:
selector:
app: fish
ports:
- name: http
port: 8080
---
apiVersion: v1
kind: Service
Metadata:
name: stable-svc
spec:
selector:
app: fish
ports:
- name: http
port: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
Metadata:
name: fish
annotations:
kubernetes.io/ingress.class: 'Nginx'
cert-manager.io/cluster-issuer: letsencrypt-production
cert-manager.io/acme-challenge-type: dns01
external-dns.alpha.kubernetes.io/hostname: fish.local
Nginx.ingress.kubernetes.io/enable-cors: "true"
Nginx.ingress.kubernetes.io/cors-allow-methods: "PUT,GET,POST,OPTIONS"
Nginx.ingress.kubernetes.io/cors-allow-origin: "*"
Nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header l5d-dst-override $service_name.$namespace.svc.cluster.local:$service_port;
spec:
rules:
- host: fish.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: stable-svc
port:
number: 8080
当我通过 ArgoCD 进行部署(同步)时,我可以看到流量分配为 50/50:
- apiVersion: split.smi-spec.io/v1alpha2
kind: TrafficSplit
Metadata:
[...]
name: fish
namespace: default
spec:
backends:
- service: canary-svc
weight: "50"
- service: stable-svc
weight: "50"
service: stable-svc
但是在 while 循环中执行 curl 命令我只能返回 stable-svc。我唯一一次看到更改是在我将服务完全移动到 100% 之后。
我试图遵循这个:https://argoproj.github.io/argo-rollouts/getting-started/smi/
任何帮助将不胜感激。
谢谢
解决方法
阅读本文后:https://linkerd.io/2.10/tasks/using-ingress/ 我发现您需要使用特殊注释修改入口控制器:
$ kubectl get deployment <ingress-controller> -n <ingress-namespace> -o yaml | linkerd inject --ingress - | kubectl apply -f -
TLDR;如果您需要 Linkerd 功能,例如服务配置文件、流量拆分等,则需要进行额外的配置才能使 Ingress 控制器的 Linkerd 代理在入口模式下运行。
,所以 this issue 中有更多的上下文,但 TL;DR 是入口倾向于针对单个 pod 而不是服务地址。将 Linkerd 的代理置于入口模式会告诉它覆盖该行为。 NGINX 确实已经有一个设置,可以让它直接命中服务而不是端点,您可以在他们的文档 here 中看到这一点。