Ocelot: Doesn't reload config file in k8s

Created on 13 Nov 2018  路  8Comments  路  Source: ThreeMammals/Ocelot

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.

Steps to Reproduce the Problem

  1. Program.cs
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>();
}
  1. Create ConfigMap
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}"
    }
  ]
}'
  1. A part of my Deployment
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 
  1. Run. Everything works. But now I need to change a route in configMap and apply
"UpstreamPathTemplate": "/usersnew/{everything}"
  1. The mounted file is changed. But Ocelot returns 404 and old route works.

Specifications

  • Version: 11.0.2
  • Platform: docker
  • Subsystem: k8s
bug needs validation

All 8 comments

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.

Was this page helpful?
0 / 5 - 0 ratings