ISTIO交通路由规则无效

发布于 2025-01-26 02:34:26 字数 3279 浏览 4 评论 0原文

我正在尝试使用ISTIO和INGRESS-NGINX配置请求路由,但我无法正确路由请求。基本上,我有两个部署作为另一个子集,并实现了加权虚拟服务。 在Kiali仪表板中,它显示了从Ingress-controller到PassThroughCluster的请求,即使我可以使用istioctl proxy-config路由命令看到正确的路由映射命令。 这是完整的配置:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: dummy-app
  namespace: my-namespace
---
apiVersion: v1
kind: Service
metadata:
  name: dummy-app
  namespace: my-namespace
  labels:
    app: dummy-app
    service: dummy-app
spec:
  ports:
  - port: 8080
    targetPort: 8080
    name: http-web
  selector:
    app: dummy-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dummy-app-1
  namespace: my-namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dummy-app
      version: v1
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
      labels:
        app: dummy-app
        version: v1
    spec:
      serviceAccountName: dummy-app
      containers:
      - image: my-img
        imagePullPolicy: IfNotPresent
        name: dummy-app
        env:
          - name: X_HTTP_ENV
            value: dummy-app-1
        ports:
        - containerPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dummy-app-2
  namespace: my-namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dummy-app
      version: v2
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
      labels:
        app: dummy-app
        version: v2
    spec:
      serviceAccountName: dummy-app
      containers:
      - image: my-img
        imagePullPolicy: IfNotPresent
        name: dummy-app
        env:
          - name: X_HTTP_ENV
            value: dummy-app-2
        ports:
        - containerPort: 8080
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: dummy-app
  namespace: my-namespace
spec:
  host: dummy-app
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: dummy-app
  namespace: my-namespace
spec:
  hosts:
    - dummy-app.my-namespace.svc.cluster.local
  http:
  - match:
    - uri:
        prefix: "/my-route"
    route:
      - destination:
          host: dummy-app.my-namespace.svc.cluster.local
          subset: v1
        weight: 0
      - destination:
          host: dummy-app.my-namespace.svc.cluster.local
          subset: v2
        weight: 100
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "my-ingress-class"
    nginx.ingress.kubernetes.io/service-upstream: "true"
    nginx.ingress.kubernetes.io/upstream-vhost: dummy-app.my-namespace.svc.cluster.local
  name: dummy-ingress
  namespace: my-namespace
spec:
  rules:
  - host: myapp.com
    http:
      paths:
      - backend:
          service:
            name: dummy-app
            port:
              number: 8080
        path: /my-route(.*)
        pathType: ImplementationSpecific

奇怪的是,我有其他应用程序在相同的名称空间中使用,并且使用相同的Ingress-Controller,因此我不考虑Ingress-nginx设置存在问题。

ISTIO版本:

  • 客户端版本:1.11.4
  • 控制平面版本:1.11.4
  • 数据平面版本:1.11.4(13个代理),1.12-DEV(15代理)

关于配置问题的任何想法或我如何更好地调试这些想法ISTIO的一种问题?

I am trying to configure a request routing using Istio and Ingress-nginx but I'm not able to route the requests properly. Basically I have two deployments each as a different subset and implemented a weighted VirtualService.
In Kiali dashboard it shows the request being routed from the ingress-controller to PassthroughCluster even though I can see the correct route mapping using istioctl proxy-config routes command.
Here is the complete configuration:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: dummy-app
  namespace: my-namespace
---
apiVersion: v1
kind: Service
metadata:
  name: dummy-app
  namespace: my-namespace
  labels:
    app: dummy-app
    service: dummy-app
spec:
  ports:
  - port: 8080
    targetPort: 8080
    name: http-web
  selector:
    app: dummy-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dummy-app-1
  namespace: my-namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dummy-app
      version: v1
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
      labels:
        app: dummy-app
        version: v1
    spec:
      serviceAccountName: dummy-app
      containers:
      - image: my-img
        imagePullPolicy: IfNotPresent
        name: dummy-app
        env:
          - name: X_HTTP_ENV
            value: dummy-app-1
        ports:
        - containerPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dummy-app-2
  namespace: my-namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dummy-app
      version: v2
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
      labels:
        app: dummy-app
        version: v2
    spec:
      serviceAccountName: dummy-app
      containers:
      - image: my-img
        imagePullPolicy: IfNotPresent
        name: dummy-app
        env:
          - name: X_HTTP_ENV
            value: dummy-app-2
        ports:
        - containerPort: 8080
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: dummy-app
  namespace: my-namespace
spec:
  host: dummy-app
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: dummy-app
  namespace: my-namespace
spec:
  hosts:
    - dummy-app.my-namespace.svc.cluster.local
  http:
  - match:
    - uri:
        prefix: "/my-route"
    route:
      - destination:
          host: dummy-app.my-namespace.svc.cluster.local
          subset: v1
        weight: 0
      - destination:
          host: dummy-app.my-namespace.svc.cluster.local
          subset: v2
        weight: 100
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "my-ingress-class"
    nginx.ingress.kubernetes.io/service-upstream: "true"
    nginx.ingress.kubernetes.io/upstream-vhost: dummy-app.my-namespace.svc.cluster.local
  name: dummy-ingress
  namespace: my-namespace
spec:
  rules:
  - host: myapp.com
    http:
      paths:
      - backend:
          service:
            name: dummy-app
            port:
              number: 8080
        path: /my-route(.*)
        pathType: ImplementationSpecific

Weird thing is I have other applications working in the same namespace and using the same ingress-controller, so I'm not considering there is a problem with ingress-nginx setup.

Istio version:

  • client version: 1.11.4
  • control plane version: 1.11.4
  • data plane version: 1.11.4 (13 proxies), 1.12-dev (15 proxies)

Any ideas on what is the configuration problem or how can I better debug these kind of issues in Istio?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许一世地老天荒 2025-02-02 02:34:26

主要问题似乎与Ingress-Nginx资源有关。基于上述入口定义,您正在尝试绕过ISTIO INGRESS网关(在此处已实施了所有代理规则,例如网关,虚拟服务和目标规则),并将流量直接从Ingress推动到应用程序服务。为了使ISTIO代理规则可行,您应该让流量通过Istio-Ingressgateway(ISTIO-SYSTEM命名空间下的服务)。因此,应对您的入口资源进行以下更改:

  rules:
  - host: myapp.com
    http:
      paths:
      - backend:
          service:
            name: istio-ingressgateway.istio-system
            port:
              number: 80
        path: /my-route(.*)
        pathType: ImplementationSpecific

Main issue seems to be with ingress-nginx resource. Based on the above ingress definition, you are trying to bypass istio ingress gateway (where all the proxying rules has been implemented, like gateway,virtual-service and destination rules) and directly pushing the traffic to the application service from ingress. For istio proxy rules to work, you should let traffic pass through istio-ingressgateway (a service under istio-system namespace). So following changes should be made to your ingress resource:

  rules:
  - host: myapp.com
    http:
      paths:
      - backend:
          service:
            name: istio-ingressgateway.istio-system
            port:
              number: 80
        path: /my-route(.*)
        pathType: ImplementationSpecific
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文