Reputation: 203
I'm running micro services on Kubernetes cluster, currently all my configurations are injected as environment variables at the time of deployment but few micro services require certain business configuration which can change any number of time over the lifetime of a pod, so I decided to keep them out of ENVs and here is what I could think of,
a configuration server which allows business to modify configs(via UI) and stores configs persistently(some k,v db).
now to update MSs config
the config server can push it.
but this is difficult because there are n
replicas of each MS and how to update them all?.
MSs can pull the config from the config server.
but this requires regular polling which is expensive.
So what is the better way to manage the dynamic configuration and update all replicas of required MS only when update happens to a configuration.
Upvotes: 0
Views: 1167
Reputation: 1282
It's pretty common to build a config service and then have your other services connect to it to pull down config & stream updates.
Examples are Netflix's https://github.com/Netflix/archaius, Amplitude's DynConf https://amplitude.com/blog/dynamic-configuration or Prefab offers it as-a-service https://prefab.cloud/features/config/
These all have different takes on how to solve the problem, but streaming updates over SSE is a good start.
Upvotes: 0
Reputation: 1
There are several ways to achieve your goal, but the one that seems most applicable in a k8s environment is by using a "CM" cluster service, such as etcd, zookeeper or consul.
This implies code changes to the applications (MSs). for example, they will register to changes in etcd nodes (key-value tree store) specific to each MSs configuration, and be notified once a node has changed, then make a call to retrieve the changes. This kind of design is usually done using a REST or (g)RPC protocols that etcd, zookeeper, consul etc. support. This "observer" pattern I think should answer your concern about expensive polling (also how often does the configuration change anyway? usually a rare event...)
Of course it also implies you will need to maintain a configuration schema for your MSs in that CM store and the application to support dynamic configuration changes.
Upvotes: 0