【问题标题】:Connecting to Istio ingress gateway gives a 404 error连接到 Istio 入口网关会出现 404 错误
【发布时间】:2026-01-07 08:05:02
【问题描述】:

我使用可用的舵图安装了istio v1.1.1

我有

$ kubectl get svc istio-ingressgateway -n istio-system
NAME                   TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)                                                                                                                                      AGE
istio-ingressgateway   LoadBalancer   10.31.251.20   35.189.53.230   80:31380/TCP,443:31390/TCP,31400:31400/TCP,15029:31920/TCP,15030:32305/TCP,15031:31084/TCP,15032:31163/TCP,15443:32714/TCP,15020:30964/TCP   3h

然后,我创建了一个网关和虚拟服务,如下所示:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: myservice-gateway
  namespace: stg
spec:
  selector:
    istio: ingressgateway # use Istio default gateway implementation
  servers:
  - hosts:
    - "stg.myservice.com"
    port:
      number: 80
      protocol: http
      name: http-myservice-port


---      

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: myservice
  namespace: stg
spec:
  hosts:
    - "stg.myservice.com"
  gateways:
  - myservice-gateway         
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        port:
          number: 8888
        host: myservice-service.stg.svc.cluster.local

我已确保服务正常运行,并且当我将 pod 转发到端口时,我可以使用 localhost 访问它。

我可以确认stg.myservice.com 解析为35.189.53.230。 我收到此错误

$ curl -i stg.myservice.com
HTTP/1.1 404 Not Found
location: http://stg.myservice.com/
date: Sun, 07 Apr 2019 05:54:59 GMT
server: istio-envoy
content-length: 0

我错过了什么?

我在ingress-gateway pod 中没有发现任何错误

PS:我有gateways.istio-ingressgateway.sds.enabled=true

【问题讨论】:

  • 所以你在命名空间stg 中有一个名为myservice-service 的服务,在端口8888 上运行,它在/ 上返回200?
  • 是的,我可以从同一个集群中的另一个 pod 访问 http://myservice-service:8888
  • 这很奇怪。你说你没有看到kubectl logs istio-ingressgateway-xxxxxx-xxxx -n istio-system 的这些请求(以 404 结尾)?所以它永远不会通过网关?你试过不用 SDS 吗?
  • 你能把你的kubectl describe virtualservice 输出也粘贴到问题中吗?

标签: google-kubernetes-engine gateway kubernetes-ingress istio


【解决方案1】:

在您的虚拟服务配置中,您需要将命名空间添加到网关

stg/myservice-gateway 

而不是

myservice-gateway   

像这样的

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: myservice
  namespace: stg
spec:
  hosts:
    - "stg.myservice.com"
  gateways:
  - stg/myservice-gateway         
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        port:
          number: 8888
        host: myservice-service.stg.svc.cluster.local

【讨论】: