Dynamic values in ConfigMap

839 views
Skip to first unread message

themanw...@gmail.com

unread,
Aug 19, 2017, 5:33:31 PM8/19/17
to Kubernetes user discussion and Q&A
Hello All,

I have a rather specific usecase and was looking for some suggestions on how to tackle it.

We have a java application that reads a configuration file on start up. We can run multiple copies of this application for horizontal scaling however it requires we give each a unique ID between 1 and 1023. This ID needs to be preset at startup and cannot be set after.

For the moment we hacked a awful bash script to inject a random number into the file on pod start. Ideally we want to move the entire config file into a ConfigMap so we don't have to version the container image for every change. Ideally we need a way to have the ConfigMap generate the ID or call something external that does. Eventually we'll need to ensure this ID is actually unique, right now we're relying on random chance.

Is this something possible with kubernetes? We've been reading all the documentation we can find but so far have not come up with a real solution.

Thanks,
Andy

Tim Hockin

unread,
Aug 19, 2017, 7:57:21 PM8/19/17
to Kubernetes user discussion and Q&A
Publish the base configmap into a volume. Run a sidecar container
that consumes that and merges it with the unique ID (which you get
from StatefulSet or somewhere else - different problem) and publish
THAT to a shared emptyDir volume. When the base configmap changes,
the sidecar wakes up (e.g. inotify or just compare checksum) and
repeats the process.

There isn't a generic "template this data on the way to becoming a file" logic.
> --
> You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-use...@googlegroups.com.
> To post to this group, send email to kubernet...@googlegroups.com.
> Visit this group at https://groups.google.com/group/kubernetes-users.
> For more options, visit https://groups.google.com/d/optout.

Rodrigo Campos

unread,
Aug 19, 2017, 11:53:56 PM8/19/17
to kubernet...@googlegroups.com
Do you need the id to be on the same file? Can't that be in another file? If it can be in another file, and not in the configmap, I think it will be way more easy (and easier to share a configmap, etc.)

Because, maybe if you use a stateful set and a init container, you can just place it in an emptyDir at init. Not beautiful, but might work for a first step.

Or maybe just an env variable or file with the index of the stateful set is possible with the downward api? Don't remember.

But wouldn't that do the trick? Or am I missing something?

Reply all
Reply to author
Forward
0 new messages