How Can I Reload Secrets in a Kubernetes Controller When They Change?

0
9
Asked By TechyTurtle42 On

I'm developing a Kubernetes controller in Go, and I'm facing a challenge with how to reload tokens when the Secrets change. Right now, the tokens are read from environment variables, but they don't automatically update when the Secrets are modified, resulting in using outdated values. I've considered a few approaches: 1) Mount the Secret as files and use inotify for changes, 2) Always read from the mounted files without caching values, or 3) Use a Secret reference to read and watch the Secrets via the Kubernetes API, keeping in mind that this option would require read permissions on the Secrets. How would you recommend solving this issue, and is there a better platform for discussing these technical challenges?

3 Answers

Answered By GoDevMaster On

I think option 2 could work well. If you're concerned about performance, you could even cache the file in memory for a short while instead of reading from it constantly.

Answered By CoderGuy87 On

You can actually give read access to specific Secrets without needing to grant access to all of them. Watching the Secret object and reloading upon changes sounds like a solid plan to me!

Answered By BuildItRight On

Option 3 would be the most real-time approach. Remember, it takes time for Secrets to propagate to a mounted file in the pod. Plus, using the Kubernetes API makes it more aligned with how a controller should function.

QuickFix99 -

That's a good point! If you really need real-time updates, option 3 sounds like the most native solution.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.