Comments (14)
You are right. It will be better if ports have different hosts, but in some special cases we can use custom provider to override it. I would like once again to thank you for your patience.
from ocelot.
I'm sorry for the late reply. For example, my web service on k8s expose two ports: https for 443 and http for 80, like this:
Name: example-web
Namespace: default
Subsets:
Addresses: 10.1.161.59
Ports:
Name Port Protocol
---- ---- --------
https 443 TCP
http 80 TCP
I use ocelot as the entry of my service. If I access some API like 'http://example-web/api/example/1', ocelot will redirect the request to the address like 'http://10.1.161.59:443' . The hostname can be parsed correctly, but port is wrong.
I try to specify DownstreamScheme=http in ocelot but k8s provider still choose the https port:
{
"DownstreamPathTemplate": "/{url}",
"DownstreamScheme": "http",
"UpstreamPathTemplate": "/api/example/{url}",
"ServiceName": "example-web",
"UpstreamHttpMethod": [ "Get"]
}
Then I check the source code, find k8s service discovery only select the first one :
services.AddRange(subset.Addresses.Select(address => new Service(endpoint.Metadata.Name,
new ServiceHostAndPort(address.Ip, subset.Ports.First().Port),
endpoint.Metadata.Uid, string.Empty, Enumerable.Empty<string>())));
It will be fine if we can use the port with specific name, like 'https' or 'http'.
from ocelot.
I don't understand you!
Describe your user scenario in details please!
Attach all artifacts!
from ocelot.
Is this issue a bug, a feature or an idea?
from ocelot.
@RaynaldM Any ideas?
What is this author talking about? ๐
from ocelot.
Thank you for explanation!
So, the problematic method:
Ocelot/src/Ocelot.Provider.Kubernetes/Kube.cs
Lines 42 to 54 in d54836d
and especially this line of the code:
where we read
subset.Ports.First().Port
from the 1st element of Ports
collection.So, the issue is clear now in general: the code works correctly if collection has single port only (count = 1), if count > 1 then the code can behave incorrectly.
But from the view point of the design it is unclear how to build
Service
object having multiple ports?Should we create a separate
Service
objects? And will these Service
object be mapped to DownstreamHostAndPort objects?A lot of questions...
Will you contribute to redesign Kube
provider? Do you have draft version of a new solution?
My understanding, we have to decouple Service
object creation logic to a new interface and inject it, or introduce a new interface with a new BuildServices
method, like this ๐
Design 1
using KubeClient.Models;
public interface IKubeServiceCreator
{
IEnumerable<Service> Create(EndpointsV1 endpoint, EndpointSubsetV1 subset);
}
// class Kube
private readonly IKubeServiceCreator _serviceCreator;
public Kube(
KubeRegistryConfiguration kubeRegistryConfiguration, IOcelotLoggerFactory factory, IKubeApiClient kubeApi, // old injections
IKubeServiceCreator serviceCreator) // new injected service object
{
// ...
_serviceCreator = serviceCreator;
}
// We have to rewrite Build method
private List<Service> BuildServices(EndpointsV1 endpoint)
{
var services = new List<Service>();
foreach (var subset in endpoint.Subsets)
{
services.AddRange(_serviceCreator.Create(endpoint, subset));
}
return services;
}
But... My personal preference is wrapping logic of entire BuildServices
method
Design 2
using KubeClient.Models;
public interface IKubeServiceBuilder
{
IEnumerable<Service> BuildServices(EndpointsV1 endpoint);
}
// class Kube
private readonly IKubeServiceBuilder _serviceBuilder;
public Kube(
KubeRegistryConfiguration kubeRegistryConfiguration, IOcelotLoggerFactory factory, IKubeApiClient kubeApi, // old injections
IKubeServiceBuilder serviceBuilder) // new injected service object
{
// ...
_serviceBuilder = serviceBuilder;
}
// We have to remove static Build method and rewrite GetAsync method
public async Task<List<Service>> GetAsync()
{
// ...
if (endpoint != null && endpoint.Subsets.Any())
{
services.AddRange(_serviceBuilder.BuildServices(endpoint));
}
// ...
return services;
}
@shcant
Which design do you like?
I have additional 3rd idea for Design 3... ๐ having an options of feature.
from ocelot.
Oh, I forgot about absolutely independent design and development by your own of a Custom Provider! ๐
You can develop new type of SD provider even without us. You need to copy-paste Kube
class and redevelop, or inherit Kube
class and override methods, and inject required objects by instructions in our docs
from ocelot.
But you define multiple downstream service ports of one route.
In theory one endpoint can have multiple bounded protocols (ports) but it is overhead deployments.
Seems it should be one route with multiple downstream pairs of host & port of this property of the DownstreamRoute
class:
public List<DownstreamHostAndPort> DownstreamAddresses { get; }
if the host will be the same part ports are different then it is a bit strange for load balancing scenario...
My understanding hosts should be different. But Yes, in theory one service instances have different ports of the same host...
Seems there is no issue...
from ocelot.
Hi @shcant! What's your full name and LinkedIn?
Did/Do not you have an intention to contribute?
I've decided to re-open the issue because I want to re-design K8s provider and introduce more flexibility in the provider. So, we will decouple the current default implementation into 1 or 2 additional interfaces with adding to DI.
My proposals are here in my past comment with draft design!
from ocelot.
Hi raman, thank you for your kindness again. I may not contribute due to my personal schedule, but still pay attention to the feature and provide feedback. I am very honored to your invitation. @raman-m
from ocelot.
@shcant Lazy bones! ๐
๐ I will open a PR when started work for March'24 release by my own. The issue is assigned to me. So, I'll care about...
But I will ask you to review hoping that you'll have enough time for that, cause you are the author of the issue.
from ocelot.
Related Issues (20)
- Use Polly v8 syntax HOT 4
- Authentication docs could do with a note around .NET 8 changes HOT 1
- The Getting Started document could be updated for .NET 8 HOT 5
- Use Ocelot / Identity Server4 JwtBearerEvents.OnAuthenticationFailed addHeaders not work HOT 9
- Apply rate limiting globally HOT 5
- Download file API causes Gateway memory to rise by fileSize HOT 15
- UpstreamHost not working HOT 8
- Routes containing attribute "UpstreamHost " cannot be found HOT 1
- Issue with Aggregator in Ocelot: Requires At Least Two Routes to Execute HOT 11
- ๅจไฝฟ็จๅผๆญฅๆต่ฟๅๆถ๏ผๅนถไธๆฏๅฎๆถๅทๆฐ้ๆก่ฟๅ็ปๆ๏ผ่ๆฏไธๆฌก่ฟๅ็ปๆ HOT 10
- How to Authorize with nested JWT claim generated from Keycloak
- Access to the path '/app/ocelot.json' is denied HOT 1
- Ocelot is missing NuGet package README file HOT 3
- FTP is raising Exception of Timeout but working in FileZilla and WinSCP HOT 3
- UnableToFindDownstreamRouteError, Failed to match Route configuration for upstream path: /, verb: GET HOT 8
- Rate Limiting issues in Ocelot HOT 6
- Ocelot Downstream Request Timeout HOT 5
- How to find servicename on PreAuthorizationMiddleware HOT 1
- Proposal to add ExtraProps to the configuration HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ocelot.