API Gateway Ocelot and Kubernetes



我正在尝试访问我的微服务" externalforum-api-svc ";在我的kubernetes集群中使用ocelot网关。我已经按照文档做了,但它似乎不起作用。

谁能告诉我有什么问题吗?我想将ocelot api网关部署为clusterIP,并使用Ingress从集群外部访问它,但是当我试图从ocelot ->

##错误警告:Ocelot.Responder.Middleware。ResponderMiddleware[0] requestId: 0HMCO5SFMMOIQ:00000002, previousRequestId: no previous请求id,消息:UnableToFindServiceDiscoveryProviderError消息:无法找到中发现的类型:consul错误的服务发现提供程序ResponderMiddleware。为请求设置错误响应路径:/externalForumService,请求方法:GET

{
"Routes": [
{
"UpstreamPathTemplate": "/externalForumService/GetAll",
"DownstreamPathTemplate": "/api/externalforum/v1/forum/GetAll",
"DownstreamScheme": "http",
"ServiceName": "externalforum-api-svc",
"UpstreamHttpMethod": [ "Get" ]
},
{
"UpstreamPathTemplate": "/externalForumService",
"DownstreamPathTemplate": "/api/externalforum/v1/forum",
"DownstreamScheme": "http",
"ServiceName": "externalforum-api-svc",
"UpstreamHttpMethod": [ "Get" ]
}
],
"GlobalConfiguration": {
"ServiceDiscoveryProvider": {
"Namespace": "propnull",
"Type": "kube"
}
}
}

映射服务

apiVersion: v1
kind: Service
metadata:
name: externalforum-api-svc
namespace: propnull
spec:
type: ClusterIP
selector:
app: externalforum-api
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80

我已经运行了kubectl create clusterrolebinding permissive-binding --clusterrole=cluster-admin --user=admin --user=kubelet --group=system:serviceaccounts

规范
  • 版本:17.0.0
  • 平台:core 5.0

尝试更改"type: kube"类型:kubernetesservicediscoveryprovider

在我的情况下,错误是不同的,它不能映射适当的pod。所以你可以手动映射

{
"Routes": [
{
"DownstreamPathTemplate": "/api/{everything}",
"DownstreamScheme": "http", 
"DownstreamHostAndPorts": [
{
"Host": "serviceName.Namespace.svc.cluster.local",
"Port": 80
}
],
"UpstreamPathTemplate": "/something/{everything}",

},....

在Ocelot 18 (Kubernetes 1.20)上只需更新您的服务提供商类型,文档已过时:

"GlobalConfiguration": {
"ServiceDiscoveryProvider": {
"Namespace": "propnull",
"Type": "KubernetesServiceDiscoveryProvider"
}
}