Why doesn't Ocelot.Provider.Kubernetes
work?
#2227
-
Both Ocelot API and Price API are running on K8s packages<PackageReference Include="Ocelot" />
<PackageReference Include="Ocelot.Provider.Kubernetes" /> Program.csusing Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Provider.Kubernetes;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration
.AddJsonFile("ocelot.json", optional: false, reloadOnChange: true)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
builder.Services.AddOcelot()
.AddKubernetes();
var app = builder.Build();
app.UseOcelot().Wait();
app.Run(); ocelot.json{
"Routes": [
{
"Servicename": "price-webapi",
"DownstreamPathTemplate": "/api/price/{everything}",
"UpstreamPathTemplate": "/api/price/{everything}",
"UpstreamHttpMethod": [ "GET", "POST", "PUT", "DELETE" ],
"UseServiceDiscovery": true,
"LoadBalancerOptions": {
"Type": "RoundRobin"
}
}
],
"GlobalConfiguration": {
"ServiceDiscoveryProvider": {
"Type": "Kube",
"Namespace": "cafef-dev1"
}
}
} When I use url from ocelot to route to price-api, I got this error:
I checked in ocelot api's pod with: curl http://price-webapi.cafef-dev1.svc.cluster.local:9100/api/price/v1/values and got success result. Please help me fix this issue! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
What's your full name? |
Beta Was this translation helpful? Give feedback.
-
Hi @raman-m ! |
Beta Was this translation helpful? Give feedback.
-
Our extension package is based on KubeClient one.
This error means that Kube client either can't connect to the k8s service or it's not configured at all. If you don't use Pod service then configuration is injected here, and you have to define JSON settings in If you use Pod service, then it is responsible for connection to the cluster. Please read more instructions in KubeClient documentation! Hope it helps! |
Beta Was this translation helpful? Give feedback.
Our extension package is based on KubeClient one.
This error means that Kube client either can't connect to the k8s service or it's not configured at all.
If you don't use Pod service then configuration is injected here, and you have to define JSON settings in
appsettings.json
:Ocelot/src/Ocelot.Provider.Kubernetes/OcelotBuilderExtensions.cs
Line 31 in 2e352bc