4

我正在做一个简单的项目来了解更多关于微服务的信息。

我有一个非常简单的 .net 核心网络,只有一个 GET 端点。我添加了一个带有 Ocelot 的 ApiGateway Web 应用程序,除了部署到本地 Kubernetes 集群外,一切似乎都运行良好。

这些是我用于部署的 yaml 文件:

ApiGateway.yaml

kind: Pod
apiVersion: v1
metadata:
  name: api-gateway
  labels:
    app: api-gateway
spec:
  containers:
    - name: api-gateway
      image: apigateway:dev

---

kind: Service
apiVersion: v1
metadata:
  name: api-gateway-service
spec:
  selector:
    app: api-gateway
  ports:
    - port: 80

测试服务.yaml

kind: Pod
apiVersion: v1
metadata:
  name: testservice
  labels:
    app: testservice
spec:     
  containers:
    - name: testservice
      image: testbuild:latest

---

kind: Service
apiVersion: v1
metadata:
  name: testservice-service
spec:
  selector:
    app: testservice
  ports:
    - port: 80

豹猫.json

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/endpoint",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "testservice-service",
          "Port": 80
        }
      ],
      "UpstreamPathTemplate": "/test",
      "UpstreamHttpMethod": [ "Get" ]
    }
  ]
}

如果我尝试使用 cUrl 直接从 ApiGateway pod 向 TestService 服务发出请求,则它可以正常工作。但是当我尝试从 Ocelot 请求它时,它返回一个 500 错误,说:

warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
  requestId: 0HLUEDTNVVN26:00000002, previousRequestId: no previous request id, message: Error Code: UnableToCompleteRequestError Message: Error making http request, exception: System.Net.Http.HttpRequestException: Name or service not known
   ---> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known

另外,我尝试使用此https://ocelot.readthedocs.io/en/latest/features/kubernetes.html但老实说,该文档并不是很清楚,到目前为止我还没有取得任何成功。

知道问题可能是什么吗?

(我也在使用 Ingress 资源来公开服务,但这没有问题,所以我暂时将其排除在此线程之外)

4

0 回答 0