1
00:00:00,000 --> 00:00:10,800
Hi let us understand about volumes. Whenever I am starting a pod there may be

2
00:00:10,800 --> 00:00:15,900
a requirement to store the data within the pod for permanent or for temporary

3
00:00:15,900 --> 00:00:21,000
purpose and to store the data I need something called a volume. Volume is

4
00:00:21,000 --> 00:00:27,233
nothing but it's like a virtual hard disk and I need to get the volume resources either

5
00:00:27,233 --> 00:00:32,698
from the host system or it could be some other NFS like network file system or

6
00:00:32,700 --> 00:00:37,733
some other storage like block storage available within the cloud environment.

7
00:00:37,733 --> 00:00:42,599
Let's take this from the simple scenario to the complex scenario for that we need to

8
00:00:42,600 --> 00:00:47,800
have understanding on the ephemeral storage. While starting a pod there may be

9
00:00:47,800 --> 00:00:52,433
a requirement to store the data for temporary purpose, let's assume I'm going

10
00:00:52,433 --> 00:00:57,133
to do some image processing to store the intermediate data, I need this ephemeral

11
00:00:57,133 --> 00:01:01,399
storage and this is going to share the resources from the underlying host

12
00:01:01,400 --> 00:01:07,466
system and while creating the pod I can define, how I wanted to have this

13
00:01:07,466 --> 00:01:11,932
particular ephemeral storage and the scope of this particular storage is

14
00:01:11,933 --> 00:01:17,433
as long as the scope of the pod is existing that means once the pods life cycle

15
00:01:17,433 --> 00:01:22,699
gets over the ephemeral storage will also get deleted. So the user should be

16
00:01:22,700 --> 00:01:27,000
very careful enough not to store any permanent data only the ephemeral data

17
00:01:27,000 --> 00:01:31,600
or the temporary data can be stored within this ephemeral storage and that is

18
00:01:31,600 --> 00:01:36,333
called as an empty directory. Let's go ahead and create a pod with

19
00:01:36,333 --> 00:01:41,566
empty directory and see how it's going to behave I have minikube running within my

20
00:01:41,566 --> 00:01:48,332
system and I'm going to use a yaml file that's going to have the content like this.

21
00:01:48,333 --> 00:01:53,066
So I am mentioning kind as pod and within the specification of the pod I am

22
00:01:53,066 --> 00:01:57,399
going to mention the volume. I am going to give a name I will mention that as

23
00:01:57,400 --> 00:02:03,200
emptydir, the yaml content gets over over here and this particular volume will be

24
00:02:03,200 --> 00:02:07,700
mounted over here using the volume mounts within the container, so within the

25
00:02:07,700 --> 00:02:12,966
container I am having the key volume mounts and I am mentioning against

26
00:02:12,966 --> 00:02:19,499
which folder this particular emptydir volume will get mounted. Let me go ahead

27
00:02:19,500 --> 00:02:25,400
and create the pod using this yaml file, I'll use kubectl apply and I will mention the

28
00:02:25,400 --> 00:02:30,333
file name the pod should get created. So it's going to create the pod this is this

29
00:02:30,333 --> 00:02:36,166
specific pod, let me go ahead and get the pod and its status. So one pod is up and

30
00:02:36,166 --> 00:02:41,499
running, let me go ahead and get details about this specific pod. So here's where I

31
00:02:41,500 --> 00:02:46,366
do have the container that got created, this is the container ID and I'm going to

32
00:02:46,366 --> 00:02:51,032
use this specific container ID to get into the container ID and check the volumes

33
00:02:51,033 --> 00:02:56,899
that got created. So here's where the mounts available and it is mounting or it

34
00:02:56,900 --> 00:03:02,200
is going to share this specific location as a part of the host system. Let me go ahead

35
00:03:02,200 --> 00:03:08,333
and get the details about the file system using df command. So I'll provide the

36
00:03:08,333 --> 00:03:12,633
exec command with kubectl and I'll provide the pod name and I'm going to

37
00:03:12,633 --> 00:03:18,166
execute the command df. That will get me the file system here I do have the file

38
00:03:18,166 --> 00:03:24,366
system mention/cache and that's going to get mapped to the host file system. So

39
00:03:24,366 --> 00:03:30,199
that means this particular host file system is mounted against this cache. Now I can

40
00:03:30,200 --> 00:03:37,200
get into this specific pod and execute the bash shell. So it's going to get into the pod

41
00:03:37,200 --> 00:03:42,166
So I am into this specific pod into the root directory, here I can check the

42
00:03:42,166 --> 00:03:47,299
cache directory. I don't have any content so what I'm going to do I am going to create

43
00:03:47,300 --> 00:03:53,000
a sample text within this specific folder, so I'm adding a text emptydir test and

44
00:03:53,000 --> 00:04:01,600
echo that into a file empty dir test.txt So I do have a text file within the folder that is

45
00:04:01,600 --> 00:04:06,866
mounted and that's going to get mounted against the host file system. Let me go

46
00:04:06,866 --> 00:04:12,466
ahead and get the container ID, let me come out of this particular pod and

47
00:04:12,466 --> 00:04:17,298
I'm going to execute the kubectl describe and the pod name. Here I do have the

48
00:04:17,300 --> 00:04:23,533
container ID. I'm going to do the docker inspect command using this specific

49
00:04:23,533 --> 00:04:28,866
container ID where I will get the details about this specific docker container that

50
00:04:28,866 --> 00:04:34,299
is running within the pod, docker inspect and then the container ID. Here I'm going

51
00:04:34,300 --> 00:04:38,700
to have information on the networking and the volumes that is hosted against

52
00:04:38,700 --> 00:04:44,433
the container that is running. So if you get into the container details here I should be

53
00:04:44,433 --> 00:04:49,666
having the details on the hard disk or the volumes that got mounted. So here are the

54
00:04:49,666 --> 00:04:55,199
mounts array available and I'm going to check the mount that is mounted against

55
00:04:55,200 --> 00:05:03,200
the /cache folder, so here's where the  /cache available and that is having or

56
00:05:03,200 --> 00:05:08,800
going to map against this specific folder location within the host file system. Let me

57
00:05:08,800 --> 00:05:14,200
open another terminal, I'm going to get into this specific location and here

58
00:05:14,200 --> 00:05:19,366
I should have this specific file that got created as a part of the container

59
00:05:19,366 --> 00:05:24,866
so I do have that text. So what did we do? We created an empty dir and we made

60
00:05:24,866 --> 00:05:30,099
that to get mapped or mounted against cache folder and that is going to get

61
00:05:30,100 --> 00:05:35,466
mapped to a host storage and a temporary folder got created and the

62
00:05:35,466 --> 00:05:40,466
lifespan of this particular cache folder is as long as this particular pod is existing

63
00:05:40,466 --> 00:05:44,866
and whenever I am adding a content into this cache folder that will be sharing the

64
00:05:44,866 --> 00:05:49,699
space available within the host file system. If I create a file called f1.txt the

65
00:05:49,700 --> 00:05:53,433
same will get created within the host file system as well. Let me go ahead and do

66
00:05:53,433 --> 00:06:00,033
that let me go ahead and create another file within the pod, now I am into the pod

67
00:06:00,033 --> 00:06:09,633
let me get into the cache folder and create a file called file1.txt with the

68
00:06:09,633 --> 00:06:16,699
content file one. So I have created a file file1.txt. let me go ahead and list the files

69
00:06:16,700 --> 00:06:22,400
available within the host file system, yes the same file is available. Now I am going

70
00:06:22,400 --> 00:06:25,966
to terminate this particular pod and see what's going to happen to this

71
00:06:25,966 --> 00:06:32,299
specific folder. Let me come out of the pod and I'm going to execute the command

72
00:06:32,300 --> 00:06:41,200
kubectl delete pod and then the pod name. The pod should get deleted, let me

73
00:06:41,200 --> 00:06:47,200
check whether the pods got deleted or not? Yes, there is no pods available. Now let

74
00:06:47,200 --> 00:06:53,800
me list the files available within this specific pods directory. This entire ID and

75
00:06:53,800 --> 00:07:02,000
the volume should also get deleted. So I'm going to list ed ID is not existing even

76
00:07:02,000 --> 00:07:08,300
within this particular folder there should not be any files available and the entire folder

77
00:07:08,300 --> 00:07:14,066
content from this specific path will get deleted. So in a quick summary we had

78
00:07:14,066 --> 00:07:19,599
seen what is emptydir volume type and how that's going to get mapped against the

79
00:07:19,600 --> 00:07:24,200
pod. The similar way there are different type of volumes available and the list it

80
00:07:24,200 --> 00:07:29,100
keeps on growing, these are all the list of volumes available at the time of recording

81
00:07:29,100 --> 00:07:33,166
and we are going to see another important type that is host path where

82
00:07:33,166 --> 00:07:38,466
we will be using it more frequently within the pods. So as a part of this particular

83
00:07:38,466 --> 00:07:43,066
session we saw how to create the empty dir and what are all its scope within the

84
00:07:43,066 --> 00:07:47,499
pod and how that's going to share the storage within the

85
00:07:47,500 --> 00:07:53,466
host file system when the emptydir volume is getting created.

