question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot resolve scoped service 'KubeClient.IKubeApiClient' from root provider.

See original GitHub issue

Expected Behavior / New Feature

redirect to service in k8s cluster

Actual Behavior / Motivation for New Feature

[19-08-01 11:02:11.11Z INF] requestId: 0HLOMDUGQ7EF3:00000004, previousRequestId: no previous request id, message: EndpointRateLimiting is not enabled for /{everything} <s:Development/Ocelot.RateLimit.Middleware.ClientRateLimitMiddleware> [19-08-01 11:02:11.11Z INF] requestId: 0HLOMDUGQ7EF3:00000004, previousRequestId: no previous request id, message: No authentication needed for /devices/v1/devices <s:Development/Ocelot.Authentication.Middleware.AuthenticationMiddleware> [19-08-01 11:02:11.11Z INF] requestId: 0HLOMDUGQ7EF3:00000004, previousRequestId: no previous request id, message: /{everything} route does not require user to be authorised <s:Development/Ocelot.Authorisation.Middleware.AuthorisationMiddleware> [19-08-01 11:02:11.11Z WRN] requestId: 0HLOMDUGQ7EF3:00000004, previousRequestId: no previous request id, message: unabe to find load balancer for /devices/{everything}|Get| exception is System.InvalidOperationException: Cannot resolve scoped service ‘KubeClient.IKubeApiClient’ from root provider. at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.ValidateResolution(Type serviceType, IServiceScope scope, IServiceScope rootScope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.Microsoft.Extensions.DependencyInjection.ServiceLookup.IServiceProviderEngineCallback.OnResolve(Type serviceType, IServiceScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at Ocelot.Provider.Kubernetes.KubernetesProviderFactory.GetkubeProvider(IServiceProvider provider, ServiceProviderConfiguration config, String name, IOcelotLoggerFactory factory) at Ocelot.ServiceDiscovery.ServiceDiscoveryProviderFactory.GetServiceDiscoveryProvider(ServiceProviderConfiguration config, String key) at Ocelot.ServiceDiscovery.ServiceDiscoveryProviderFactory.Get(ServiceProviderConfiguration serviceConfig, DownstreamReRoute reRoute) at Ocelot.LoadBalancer.LoadBalancers.LoadBalancerFactory.Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config) at Ocelot.LoadBalancer.LoadBalancers.LoadBalancerHouse.Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config) <s:Development/Ocelot.LoadBalancer.Middleware.LoadBalancingMiddleware> [19-08-01 11:02:11.11Z WRN] requestId: 0HLOMDUGQ7EF3:00000004, previousRequestId: no previous request id, message: Error Code: UnableToFindLoadBalancerError Message: unabe to find load balancer for /devices/{everything}|Get| exception is System.InvalidOperationException: Cannot resolve scoped service ‘KubeClient.IKubeApiClient’ from root provider. at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.ValidateResolution(Type serviceType, IServiceScope scope, IServiceScope rootScope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.Microsoft.Extensions.DependencyInjection.ServiceLookup.IServiceProviderEngineCallback.OnResolve(Type serviceType, IServiceScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at Ocelot.Provider.Kubernetes.KubernetesProviderFactory.GetkubeProvider(IServiceProvider provider, ServiceProviderConfiguration config, String name, IOcelotLoggerFactory factory) at Ocelot.ServiceDiscovery.ServiceDiscoveryProviderFactory.GetServiceDiscoveryProvider(ServiceProviderConfiguration config, String key) at Ocelot.ServiceDiscovery.ServiceDiscoveryProviderFactory.Get(ServiceProviderConfiguration serviceConfig, DownstreamReRoute reRoute) at Ocelot.LoadBalancer.LoadBalancers.LoadBalancerFactory.Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config) at Ocelot.LoadBalancer.LoadBalancers.LoadBalancerHouse.Get(DownstreamReRoute reRoute, ServiceProviderConfiguration config) errors found in ResponderMiddleware. Setting error response for request path:/devices/v1/devices, request method: GET <s:Development/Ocelot.Responder.Middleware.ResponderMiddleware>

Steps to Reproduce the Problem

Follow this docs https://ocelot.readthedocs.io/en/latest/features/kubernetes.html

services.AddOcelot(_configuration).AddKubernetes(false); // or true

My service in k8s: devices-api.dev:10010

Config:

{
    "ReRoutes": [
        {
            "DownstreamPathTemplate": "/{everything}",
            "DownstreamScheme": "http",
            "UpstreamPathTemplate": "/devices/{everything}",
            "ServiceName": "devices-api.dev",
            "UpstreamHttpMethod": [ "Get" ]
        }
    ],
    "GlobalConfiguration": {
        "ServiceDiscoveryProvider": {
            "Namespace": "dev",
            "Type": "kube"
        }
    }
}

Specifications

  • Version: Ocelot 13.5.2, Ocelot.Provider.Kubernetes 13.5.2
  • Platform: Docker
  • Subsystem: ASP.NET Core that runs in docker container in k8s cluster

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Marusykcommented, May 29, 2020

@neetra no, I just don’t use it. I run Ocelot in kubernetes but without AddKubernetes

0reactions
mot256commented, Feb 1, 2021

Hi @mot256

If you set this setting to false you are going to have an exception at runtime 😉

Nope. Works just fine. Its without setting it to false in runtime that we get an issue…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot resolve scoped service from root provider .Net Core 2
You registered the IEmailRepository as a scoped service, in the Startup class. This means that you can not inject it as a constructor ......
Read more >
Cannot resolve scoped service from root provider ASP.NET ...
Issue resolution for error -Cannot resolve scoped service from root provider ASP.NET Core. Understand the lifetime of service instances is registered, ...
Read more >
Cannot resolve scoped service 'KubeClient.IKubeApiClient' ...
Cannot resolve scoped service 'KubeClient.IKubeApiClient' from root provider.
Read more >
.NET Core: Cannot resolve scoped service 'Microsoft ...
I was trying to create an instance of an object from a service provider to resolve any dependencies, using ActivatorUtilities.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found