<p>The problem that i am facing is that the ocelot kubernetservicediscorverProvider does not seem to find the other services on the name space in kubernetes.My goal is to use api gateway to call apis in the other services in the same namespace. I currently get a http 404 Not Found error. And the api gateway pod, logs the following:</p>
<blockquote>
<p>Ocelot.Provider.Kubernetes.KubernetesServiceDiscoveryProvider[0]
requestId: 0HM93C93DL2T0:00000003, previousRequestId: no previous request id, message: namespace:serviceservice:managementservice Unable to use ,it is invalid. Address must contain host only e.g. localhost and port must be greater than 0</p>
</blockquote>
<blockquote>
<p>warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
requestId: 0HM93C93DL2T0:00000003, previousRequestId: no previous request id, message: Error Code: ServicesAreEmptyError Message: There were no services in NoLoadBalancer errors found in ResponderMiddleware. Setting error response for request path:/api/management/User/3910, request method: GET</p>
</blockquote>
<p>I suspect that i have mis configured something. I first tried using the Ocelot documentation, regarding kubernetes, but the documentation is out dated. (an example is the Type the sugest value does not work for more info go this github issue <a href="https://github.com/ThreeMammals/Ocelot/issues/1346" rel="nofollow noreferrer">Docs/Kubernetes provider are wrong</a>)</p>
<p>Then i went on searching online through github issues, stack overflow posts and even the source code. But i do not see  have what i am lacking in my config.</p>
<p>I currently have kubernetes running localy, with minikube. The only things that i have seen online is that others have misconfigured the ocelot.json. But i do not see what i have done incorrectly in my config.</p>
<p>(Before trying ocelot on kubernetes i first try it with local hosts, to try out if it works and to see what it lacks. It apparantly lacked a middleware that could control jwt with different roles which had right to acces the end point. I have now written the middleware my self and it works on the local host config for ocelot)</p>
<p>My ocelot.json config file looks like this for kubernetes:</p>
<pre class="lang-json prettyprint-override"><code>{
  &quot;Routes&quot;: [
    {
      &quot;UpstreamPathTemplate&quot;: &quot;/api/management/User/{everything}&quot;,
      &quot;UpstreamHttpMethod&quot;: [ &quot;POST&quot;, &quot;PUT&quot;, &quot;GET&quot; ],
      &quot;DownstreamPathTemplate&quot;: &quot;/api/management/User/{everything}&quot;,
      &quot;DownstreamScheme&quot;: &quot;http&quot;,
      &quot;ServiceName&quot;: &quot;managementservice&quot;,
      &quot;AuthenticationOptions&quot;: {
        &quot;AuthenticationProviderKey&quot;: &quot;Bearer&quot;,
        &quot;AllowedScopes&quot;: [ &quot;CompanyId&quot;, &quot;http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier&quot; ]
      },
      &quot;RouteClaimsRequirement&quot;: { &quot;role&quot;: &quot;1,2,3&quot; },
      &quot;AddHeadersToRequest&quot;: {
        &quot;CompanyId&quot;: &quot;Claims[CompanyId] &gt; value&quot;,
        &quot;UserId&quot;: &quot;Claims[http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier] &gt; value&quot;
      }
    }
  ],
  &quot;GlobalConfiguration&quot;: {
    &quot;ServiceDiscoveryProvider&quot;: {
      &quot;Host&quot;: &quot;127.0.0.1&quot;,
      &quot;Port&quot;: 8083,
      &quot;Namespace&quot;: &quot;service&quot;,
      &quot;Type&quot;: &quot;KubernetesServiceDiscoveryProvider&quot;
    }
  }
}
</code></pre>
<p>my startup.cs ConfigureServices method looks like this</p>
<pre class="lang-cs prettyprint-override"><code>public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(c =&gt;
            {
                c.AddPolicy(&quot;AllowOrigin&quot;, options =&gt; options.WithOrigins(Configuration[&quot;Cors:AllowOrigins&quot;])
                    .AllowAnyHeader()
                    .AllowAnyMethod().AllowCredentials());
            });

            #region Authication settings

            TokenValidationParameters tokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration[&quot;Jwt:Key&quot;])),
                ValidateIssuer = false,
                ValidateAudience = false,
                ValidateLifetime = true,
                ClockSkew = TimeSpan.Zero
            };

            services.AddSingleton(tokenValidationParameters);
            services.AddAuthentication(
                    x =&gt;
                    {
                        x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                        x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
                    }
                )
                .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, x =&gt;
                {

                    x.RequireHttpsMetadata = false;
                    x.SaveToken = true;
                    x.TokenValidationParameters = tokenValidationParameters;
                });

            #endregion

       //Some more code

       services.AddOcelot().AddKubernetes();
       }
</code></pre>
<p>my startup.cs Configure method looks like this</p>
<pre class="lang-cs prettyprint-override"><code>public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // some more code

            app.UseOcelot(configuration);
        }
</code></pre>
<p>my program.cs CreateHostBuilder method looks like this</p>
<pre class="lang-cs prettyprint-override"><code>public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
            Host.CreateDefaultBuilder(args)
               .ConfigureAppConfiguration((hostingContext, config) =&gt;
               {
                   config.AddJsonFile(&quot;secrets/appsettings.kubernetes.json&quot;, optional: true)
                         .AddJsonFile(&quot;ocelot.json&quot;);
               })
                .ConfigureWebHostDefaults(webBuilder =&gt;
                {
                    webBuilder.UseStartup&lt;Startup&gt;();
                });
</code></pre>

Programmer
<p>It turns out that the real problem that i was having was in the permissions in kubernetes. The ocelot documentation also mentions this. But the command in the documentation is incorrect (most likely out dated).</p>
<p>This is the command that i used. Be warned the kubernetes documenation strongly disrecommend usage of this command <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/#permissive-rbac-permissions" rel="nofollow noreferrer">permissive-rbac-permissions</a>. But it is at least a way for you to test your api gateway in ocelot locally.</p>
<pre><code>kubectl create clusterrolebinding permissive-binding --clusterrole=cluster-admin --user=admin --user=kubelet --group=system:serviceaccounts
</code></pre>
