Use Volume for Stateful Workload
Last updated
Last updated
In we learned how to setup port mappings to enable public access to pods. Now we'll look at how to persist data using .
First you'll need to create a volume:
Next, we will launch a busybox pod with this volume:
Now, let's create a file on the volume:
To demonstrate the data persistence, we'll delete the pod, and create another a new one with the same volume to see whether the file is still there:
For stateful applications, we suggest you to use volumes for persistent data. Even in the case of long-running batch jobs, such as data mining, machine learning, keep syncing the in-transit results to volumes is a best practice for fault tolerance.
Note on volume mount In the cases of pod recovery (recreated due to HW/SW errors, rescheduling, etc.), the new pod (same pod name, different pod id) will have identical mountpoints, which means that the same volumes will be automatically mounted onto the new pod. There is no action needed on your part.
Volumes are indepedent resources, and only removable when they are not mounted.
Volumes are billed per second. Therefore, it makes sense to delete them as soon as possible to save cost.