【问题标题】:404 Not Found when migrating from ingress to istio从 ingress 迁移到 istio 时找不到 404
【发布时间】:2021-04-30 05:25:29
【问题描述】:

我正在尝试从 ingress 迁移到 istio 网关 + 虚拟服务路由,但我不断收到 404 Not Found 错误。

应访问应用程序的唯一链接是使用本地配置的my-todos.com

我在这里错过了什么?

注意:入口控制器工作正常。最初,istio.yaml 文件中的todo-lb.default.svc.cluster.local 只是设置为todo-lb,代表配置的负载均衡器,仍然没有成功。

这是ingress.yaml 文件(从中迁移):

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: todo-ingress
spec:
  rules:
    - host: my-todos.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: todo-lb
                port:
                  number: 3001
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: {{ .Values.api.apiName }}
                port:
                  number: {{ .Values.api.apiPort }}

这是istio.yaml 文件(要迁移到):

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: todo-istio-gateway
  namespace: istio-system
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - my-todos.com
    # - "*"
    tls:
      httpsRedirect: true
  - port:
      number: 443
      name: https
      protocol: HTTPS
    tls:
      mode: SIMPLE
      credentialName: tls-secret
    hosts:
    - my-todos.com
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: todo-lb
spec:
  hosts:
  - my-todos.com
  # - "*"
  gateways:
  - todo-istio-gateway
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: todo-lb.default.svc.cluster.local
        port:
          number: 3001
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: todo-api
spec:
  hosts:
  - my-todos.com
  # - "*"
  gateways:
  - todo-istio-gateway
  http:
  - match:
    - uri:
        prefix: /api
    route:
    - destination:
        host: {{ .Values.api.apiName }}
        port:
          number: {{ .Values.api.apiPort }}

【问题讨论】:

    标签: kubernetes istio gateway


    【解决方案1】:

    据我所知,您的虚拟服务中的网关配置错误,这就是它可能无法正常工作的原因。


    如果网关与虚拟服务不在同一个命名空间中,则必须在虚拟服务中指定

    查看spec.gateways 部分

    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: bookinfo-Mongo
    spec:
      gateways:
      - some-config-namespace/my-gateway # can omit the namespace if gateway is in same
                                           namespace as virtual service.
    

    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: my-gateway
      namespace: some-config-namespace
    

    有相关的istio documentation关于那个。


    所以请将你的 todo-istio-gateway 移动到默认命名空间。

    或使用

    gateways:
      - istio-system/todo-istio-gateway
    

    如果没有帮助,请检查几件事:

    • 您的应用是否部署在默认命名空间中?
    • 你的应用是injected吗?

    【讨论】:

    • 你好 Jakub!是的,该应用程序部署在默认命名空间中,它有istio-injection=enabled
    • @DragoșBocancea 您能否添加您的部署和服务依赖项? http 和 https 都不起作用?同样正如 Malathi 所提到的,istio 入口网关日志中是否有任何内容?
    【解决方案2】:

    除了@Jakub 的回答之外,还有一个原因可能会导致您收到 404 错误。您当前在虚拟服务中的入口规则如下所示:

    Hostname Path Route
    my-todos.com / Forward to todo-lb.default.svc.cluster.local
    my-todos.com /api Forward to {{ .Values.api.apiName }}

    在 Istio 中,上述每个规则都是一个入口规则。如果在 Istio ingress-gateway 中,按照上述顺序添加规则,则包括前缀 /api 的所有 URL 路径都会被路由到第一个服务,即 todo-lb.default。最好像这样创建单个虚拟服务,然后查看路由是否按预期工作。

    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: todo-api
    spec:
      hosts:
      - my-todos.com
      gateways:
      - <namespace>/todo-istio-gateway
      http:
      - match:
        - uri:
            prefix: /api
        route:
        - destination:
            host: {{ .Values.api.apiName }}
            port:
              number: {{ .Values.api.apiPort }}
      - match:
        - uri:
            prefix: /
        route:
        - destination:
            host: todo-lb.default
            port:
              number: 3001
    

    【讨论】:

    • 我已经删除了包含/api前缀的第二个虚拟服务,并按照Jakub的建议添加了gateways: - istio-system/todo-istio-gateway ,但没有成功。
    • 可以查看istio-system命名空间中istio-ingressgateway pod的日志吗?
    猜你喜欢
    • 2020-08-25
    • 2021-12-08
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 2021-05-13
    • 1970-01-01
    • 2016-04-10
    相关资源
    最近更新 更多