Persist a Single Value Kubernetes & Golang

4/14/2021

I have a Golang application running in Kubernetes which needs to persist a single string value outside of it's memory. In other words, if the application is redeployed or the pod is restarted - the value is not lost. I also need to be able to read and write this from golang regularly.

What is a good way to do this?

So far I've thought about: 1. ConfigMap: Would this be considered misuse to utilize a config map, and are they even persistent? 2. PersistentVolume: This seems appropriate, but can I store a single value or a file with this, rather than setting up an entire database?

Thank you!

-- Induction
configmap
go
kubernetes
persistent-volumes

1 Answer

4/14/2021

In Kubernetes, you have the following options to store data outside the POD (or actually to share data between PODs).

  1. Persistent Volume: a shared filesystem, you share data as files
  2. ConfigMap/Secret: Kubernetes-based shared objects, you use Kubernetes API to store data; Kubernetes uses etcd under the hood and the consensus algorithm is applied to every data change, so the size of data needs to be small and the performance is not great
  3. 3rd-party tool: Hazelcast, Redis, TiKV; you use their client (or REST API) to store your values

I'm not sure about your exact use case, but I'd start from a 3-rd party software. They are very simple to deploy with Helm Chart of Operators. Another option is Persistent Volume. ConfigMap/Secret, I'd treat it as last resort.

-- RafaƂ Leszko
Source: StackOverflow