'How to keep a variable value across pod restarts?

I'm trying to build an application that stores the specs of certain Kubernetes resources in a variable.

It then sleeps for a pre-defined time like 7 days, then the application runs again, and compares the specs of the same resources now to the specs previously stored in a variable.

The problems are:

  1. If the application pod restarts for any reason, like a node rotation, it will lose its stored specs and won't be able to compare them.

  2. How to make sure that the application will return to the exact point it was when it died? For example, what if the application's pod dies right during the sleep function?

I've heard that StatefulSet is the answer, but does it guarantee problem number 2 doesn't happen?



Solution 1:[1]

Going to need more details about your case, but in general k8s is not for managing pod's internal states as in have the capability of "hibernation".

You might want to consider approaches listed in https://github.com/spf13/viper#remote-keyvalue-store-example---unencrypted

For example by leveraging consul, etcd, firestore, etc.

In general you need to look at on how to maintain the states at application level regardless whether if you are going to use "remote config" or k8s volume approach.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ardhitama