/Kubernetes-Volume

This repository is about kubernetes volume, their types and necessary labs .

Kubernetes-Volume

If one create a pod and there is a container , It will get volume. Somehow this running container stop it's working then a new container will be created to replace the old one . The newly created container will get the same volume with same name. Actually the volume owner is pod not the container and that is the reason a new container get the same volume untill the pod is crashed. If the pod is crashed , then the volume will be deleted.Containers in same the pod can share each others volume



Some interesting points

  1. Containers are short lived in nature.
  2. All data stored inside a container is deleted if the container crashed(this point is for only the general container, not for a container running in a pod)

    However the kubelet will restart it eith a clean state, ehich means that it will not have any of the old data.

  3. To overcome this problem, kubernetes uaes volume . A volume ia essentially a directory backed by a storage medium. The storage medium and it's contents are determined by the bvolume type.
  4. In kubernetes , a volume is attached to a pod and shared among the containers of that pod.
  5. The volume has the same life span as the pod and it outlives the containers of the pod. This allowes to be preserved container restarts .

Volume Types

A volume type decides the properties of the directory like size, context etc.

some example of volume types are:

  1. node-local type such as emptydir and hostpath
  2. File sharing types such as nfs ( network File system )
  3. Cloud provider-specific types like aws elastic storage azure disk.
  4. Distributed file system types
  5. Special purpose types like secret, gitrepo

Empty Dir

If somehow pod crashed then the volume attached to pod will get deleted and no data will be founded . After Crashed, the pod will recreates and new volume will reinitialize. The newly created volume will be empty and that is called empty dir.<br/ >

some key points about Empty Dir

  1. Use this when we want to share contents between multiple containers on the same pod and no to the host machine.
  2. AN empty Dir volume is firstcreates when a pod assign to a node and exist as long as that pod running on that node.
  3. As the name says , it is initially empty.
  4. Containers in the pod can all read and write the same files in the empty dir volume, through that volume can be mounted at the same or different paths in each containers.
  5. When a pod is removed from a node for any reason, the data in the empty dir is deleted forever.
  6. A container crashing does not remove a pod from a node, so the data in a empty dir volume is safe across container crashes.

HostPath

Hostpath is for mapping pod's volume to host volume. If there something change is occured in pod's volume, something will be happened on the host volume.

some key points about Host Path

  1. Use this when we want to access the contents of pod/container from host machine.
  2. A hostpath volume mounts a file on directory from the host nodes's file system into your pod