From 246f2046b38593cca14bec49ab03839cb4ad6f66 Mon Sep 17 00:00:00 2001 From: geffzhang Date: Wed, 30 Jan 2019 09:50:54 +0800 Subject: [PATCH] feat : add pollkube docs --- docs/features/kubernetes.rst | 23 +++++++++++-------- .../KubernetesProviderFactory.cs | 8 +++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/docs/features/kubernetes.rst b/docs/features/kubernetes.rst index 30b57a9b..df393b5a 100644 --- a/docs/features/kubernetes.rst +++ b/docs/features/kubernetes.rst @@ -31,18 +31,10 @@ The example below is taken from the samples folder so please check it if this do "DownstreamScheme": "http", "UpstreamPathTemplate": "/values", "ServiceName": "downstreamservice", - "UpstreamHttpMethod": [ "Get" ], - "QoSOptions": { - "ExceptionsAllowedBeforeBreaking": 3, - "DurationOfBreak": 10000, - "TimeoutValue": 5000 - }, - "FileCacheOptions": { "TtlSeconds": 15 } + "UpstreamHttpMethod": [ "Get" ] } ], "GlobalConfiguration": { - "RequestIdKey": "OcRequestId", - "AdministrationPath": "/administration", "ServiceDiscoveryProvider": { "Host": "192.168.0.13", "Port": 443, @@ -53,4 +45,17 @@ The example below is taken from the samples folder so please check it if this do } } +You also can use Ocelot polls kubernetes for latest service information rather than per request. If you want to poll kubernetes for the latest services rather than per request (default behaviour) then you need to set the following configuration. + +"ServiceDiscoveryProvider": { + "Host": "192.168.0.13", + "Port": 443, + "Token": "txpc696iUhbVoudg164r93CxDTrKRVWG", + "Namespace": "dev", + "Type": "pollkube" + "PollingInterval": 100 +} +The polling interval is in milliseconds and tells Ocelot how often to call kubernetes for changes in service configuration. + +Please note there are tradeoffs here. If you poll kubernetes it is possible Ocelot will not know if a service is down depending on your polling interval and you might get more errors than if you get the latest services per request. This really depends on how volatile your services are. I doubt it will matter for most people and polling may give a tiny performance improvement over calling kubernetes per request. There is no way for Ocelot to work these out for you. diff --git a/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs b/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs index 7abd7805..735e1116 100644 --- a/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs +++ b/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs @@ -11,11 +11,9 @@ namespace Ocelot.Provider.Kubernetes public static ServiceDiscoveryFinderDelegate Get = (provider, config, name) => { var factory = provider.GetService(); - if (config.Type?.ToLower() == "kube") - { - return GetkubeProvider(provider, config, name, factory); - } - return null; + + return GetkubeProvider(provider, config, name, factory); + }; private static ServiceDiscovery.Providers.IServiceDiscoveryProvider GetkubeProvider(IServiceProvider provider, Configuration.ServiceProviderConfiguration config, string name, IOcelotLoggerFactory factory)