emptyDir vs hostPath volume type usage on a kubernetes deployment

1/29/2020

emptyDir vs hostPath (and other) volume type usage on a kubernetes deployment

As read from official documentation it is stated that when using emptyDir with a POD. Container crashing does NOT remove a Pod from a node, so the data in an emptyDir volume is safe across Container crashes.

So i was questioning can we somehow force the content of POD survive on upgrade (rollout) using emptyDir volume type along with (node selector/affinity) usage forcing a POD to be pinned to a given node ? or hostPath (or other volume type )is what we will need consider at design to make sure data is persisted even during rollout where POD is recreated regardless of node pinning (we have flexibility to pin this app to a large node in cluster)

-- DT.
kubernetes

2 Answers

1/30/2020

As you may know, when you upgrade a deployment, it creates a new POD and once running it terminates your previous POD. In such case, the emptyDir is going to be removed (termination of a pod). As you mention, you could use a hostPath in case you have the node selector/affinity and in such scenario the folder would be shared with all the instances of your pod (if replicas > 1). This is actually the answer from @Matt.

The emptyDir is more or less a temporary folder that you use for the life-cycle of your application. You shouldn't store data required when restarting. Somewhere in the documentation of Kubernetes, it is stated that pod could be removed from a node or killed in case of issue (E.g.: Auto-healing).

-- Nordes
Source: StackOverflow

1/29/2020

A deployment will create new pods with a new emptyDir.

You will need a persistent volume for previous data to be mounted into the new Pod, be it local storage with node pinning or shared storage.

-- Matt
Source: StackOverflow