Container volume life cycle

In order to understand Kubernetes' volume management, you'll need to understand the Docker volume life cycle. The following example is how Docker behaves with a volume when a container restarts:

//run CentOS Container
$ docker run -it centos
# ls
anaconda-post.log dev home lib64 media opt root sbin sys usr
bin etc lib lost+found mnt proc run srv tmp var


//create one file (/I_WAS_HERE) at root directory
# touch /I_WAS_HERE
# ls /
I_WAS_HERE bin etc lib lost+found mnt proc run srv tmp
var
anaconda-post.log dev home lib64 media opt root sbin sys usr

//Exit container
# exit
exit


//re-run CentOS Container
# docker run -it centos


//previous file (/I_WAS_HERE) was disappeared
# ls /
anaconda-post.log dev home lib64 media opt root sbin sys usr
bin etc lib lost+found mnt proc run srv tmp var

In Kubernetes, you also need to take care of pod restart. In the case of a resource shortage, Kubernetes may stop a container and then restart a container on the same or another Kubernetes node.

The following example shows how Kubernetes behaves when there is a resource shortage. One pod is killed and restarted when an out of memory error is received:

//there are 2 pod on the same Node
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
Besteffort 1/1 Running 0 1h
guaranteed 1/1 Running 0 1h

//when application consumes a lot of memory, one Pod has been killed
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
Besteffort 0/1 Error 0 1h
guaranteed 1/1 Running 0 1h


//clashed Pod is restarting
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
Besteffort 0/1 CrashLoopBackOff 0 1h
guaranteed 1/1 Running 0 1h


//few moment later, Pod has been restarted
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
Besteffort 1/1 Running 1 1h
guaranteed 1/1 Running 0 1h
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset