Arthur Muller
Arthur Muller

Reputation: 81

API Gateway Ocelot and Kubernetes

I am trying to access my microservice "externalforum-api-svc" inside my kubernetes cluster using ocelot gateway. I`ve followed the docs but it does not seem to be working.

Can someone please tell me whats wrong with it?

I want to deploy the ocelot api gateway as clusterIP and use Ingress to access it from outside of the cluster, but i am facing this issue when trying to reroute from ocelot -> service inside the cluster.

## Error warn: Ocelot.Responder.Middleware.ResponderMiddleware[0] requestId: 0HMCO5SFMMOIQ:00000002, previousRequestId: no previous request id, message: Error Code: UnableToFindServiceDiscoveryProviderError Message: Unable to find service discovery provider for type: consul errors found in ResponderMiddleware. Setting error response for request path:/externalForumService, request method: 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"
    }
  }
}

Service to map

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

I have already ran kubectl create clusterrolebinding permissive-binding --clusterrole=cluster-admin --user=admin --user=kubelet --group=system:serviceaccounts

Specifications

Upvotes: 2

Views: 3796

Answers (3)

dawid debinski
dawid debinski

Reputation: 520

In my case error was different and it could not map proper pod. So you can map manually

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

Upvotes: 1

On Ocelot 18 (Kubernetes 1.20) just update your service provider type, the documentation is outdated:

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

Upvotes: 0

tiomkin
tiomkin

Reputation: 33

Try to change "type : kube" to "type : KubernetesServiceDiscoveryProvider" in GlobalConfiguration section.

Upvotes: 1

Related Questions