I'm using k8s to deploy image with Ocelot. I need to change route configs without restart Ocelot. So, from docs I found that:
.AddJsonFile(Path.Combine("configurations", "ocelot.json"), true, true)
should work, but it doesn't.
private static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile(Path.Combine("configurations", "ocelot.json"), true, true)
.AddEnvironmentVariables();
})
.UseStartup<Startup>();
}
apiVersion: v1
kind: ConfigMap
metadata:
name: ocelot-api
labels:
module: ocelot
app: api
data:
ocelot: '{
"ReRoutes": [
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "users-api",
"Port": 7511
}
],
"UpstreamPathTemplate": "/users/{everything}"
}
]
}'
spec:
containers:
- name: master
env:
- name: ASPNETCORE_ENVIRONMENT
value: Development
image: apigateway-ocelot
ports:
- containerPort: 80
volumeMounts:
- name: config
mountPath: /app/configurations
volumes:
- name: config
configMap:
name: ocelot-api
items:
- key: ocelot
path: ocelot.json
"UpstreamPathTemplate": "/usersnew/{everything}"
any suggestions?
@Marusyk Simply adding reloadOnChange: true won't actually update the configuration unless you add the property to the IoC container.
Every configuration file specified gets loaded into IConfigurationRoot. You can do this in order to see the changes made to the configuration file in runtime.
services.AddSingleton(_ => Configuration);
Does this answer your question?
Please also see https://github.com/ThreeMammals/Ocelot/issues/663
@briansantura Thanks but it is still not working when I change ConfigMap 馃槙
/k8s
what does it mean?
In kubernetes a change to a config map isn't seen by any running pods until they are restarted, therefore updating it wont take effect until ocelot is restarted.
You can however tell a deployment to reboot the pods when the attached configmap changes
seen the note about subpaths here https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap#mounted-configmaps-are-updated-automatically
Thanks for the info @sharpn I will close this issue now.