0

I have docker and kubernetes (enable kubernetes checked on docker settings) installed on my local macbook. I create containers using docker and after my machine restarts, these exactly same containers are still present. However, if I create containers within pods using kubernetes and machine is restarted, then I do see the containers but those are like freshly created containers and not the same containers prior to restart. What changes do I need to make so that even after machine restart my containers within the pods remain the same same before restart.

Puri
  • 11
  • 2

1 Answers1

4

Even at runtime, Kubernetes may move Pods at will (e.g. during scaling, cluster upgrades, adding and removing nodes, etc.).

It is a good idea to try to treat containers as 'cattle, not pets', i.e. don't expect them to be long-lived.

If you need a container to be 'the same' after restart, consider using Persisent Volumes to store their state. Depending on your requirements, StatefulSets may also be worth considering.

Or consider having them reload / recompute any additional data they need after startup. The mechanism for this will depend on your code.

Paul J
  • 799
  • 1
  • 6
  • 16
  • Got it, I did explore the Persistent volumes but the issue is if I provide the mount path of an existing folder within the container, the existing files and folders get deleted in the container. Persistent Volumes work only if we are providing an empty mount path within the container. How to provide mount path for existing folder? – Puri May 29 '20 at 01:13
  • @Puri Do you still require assistance with this? – Wytrzymały Wiktor Jun 03 '20 at 08:56
  • Yes, currently PV get mounted to empty directories only, looking to mount PV to existing directory inside container that has the data in it. – Puri Jun 03 '20 at 16:15
  • @Puri Does [this](https://stackoverflow.com/questions/58128591/kubernetes-mount-volume-on-existing-directory-with-files-inside-the-container) help? Looks like the [subPath](https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath) might do the trick. – Wytrzymały Wiktor Jun 05 '20 at 08:59