1
00:00:00,180 --> 00:00:03,370
Hello and welcome to this lecture in this lecture.

2
00:00:03,390 --> 00:00:09,870
We will discuss about namespaces in kubernetes, let us begin with an analogy.

3
00:00:09,920 --> 00:00:15,460
There are two boys named Mark to differentiate them from each other.

4
00:00:15,530 --> 00:00:17,580
We call them by their last names.

5
00:00:17,840 --> 00:00:21,760
Smith and Williams they come from different houses.

6
00:00:21,860 --> 00:00:28,320
Of course the Smiths and the Williams There are other members in the house.

7
00:00:28,320 --> 00:00:33,810
The individuals within the house address each other simply by their first names.

8
00:00:33,870 --> 00:00:38,740
For example the father addresses Mark simply as Mark.

9
00:00:38,910 --> 00:00:47,180
However if the father wishes to address the mark in the other house he would use the full name someone

10
00:00:47,180 --> 00:00:54,190
outside of these houses would also use the full name to refer to the boys or anyone within these houses.

11
00:00:55,910 --> 00:01:03,150
Each of these houses have their own set of rules that defines who does what each of these houses have

12
00:01:03,150 --> 00:01:08,280
their own set of resources that they can consume.

13
00:01:08,290 --> 00:01:16,200
Now let's get back to kubernetes these houses correspond to namespaces in kubernetes.

14
00:01:16,560 --> 00:01:23,000
So far in this course we've created objects such as pods deployments and services in our cluster.

15
00:01:23,430 --> 00:01:28,890
Whatever we have been doing we have been doing within a namespace.

16
00:01:28,950 --> 00:01:37,620
We were inside a house all this while this namespace is known as the default namespace and it is created

17
00:01:37,740 --> 00:01:45,150
automatically kubernetes, when the cluster is first set up kubernetes, creates a set of pods

18
00:01:45,150 --> 00:01:50,650
and services for its internal purpose such as those required by the networking solution.

19
00:01:50,820 --> 00:01:57,960
The DNS service etc. to isolate these from the user and to prevent you from accidentally deleting or

20
00:01:57,960 --> 00:02:04,890
modifying these services kubernetes creates them under another namespace created at cluster startup

21
00:02:05,310 --> 00:02:13,930
named Kube system a third namespace created by Coburn that is automatically is called kube public.

22
00:02:13,960 --> 00:02:18,450
This is where resources that should be made available to all users are created.

23
00:02:20,130 --> 00:02:25,980
If your environment is small or your learning and playing around with a small cluster you shouldn't

24
00:02:25,980 --> 00:02:31,990
really have to worry about namespaces you could continue to work in the default namespace.

25
00:02:32,070 --> 00:02:38,880
However as and when you grow and use a kubernetes cluster for enterprise or production purposes you

26
00:02:38,880 --> 00:02:46,430
may want to consider the use of namespace as you can create your own namespaces as well.

27
00:02:46,440 --> 00:02:52,890
For example, if you wanted to use the same cluster for both dev and production environment but at the

28
00:02:52,890 --> 00:02:59,860
same time isolate the resources between them you can create a different namespace for each of them.

29
00:02:59,970 --> 00:03:06,390
That way while working in the dev environment you don't accidentally modify a resources in production.

30
00:03:06,390 --> 00:03:12,300
Each of these namespace can have its own set of policies that define who can do what.

31
00:03:12,330 --> 00:03:19,560
You can also assign quota of resources to each of these named spaces that we each namespace is guaranteed

32
00:03:19,650 --> 00:03:22,920
a certain amount and does not use more than it's allowed.

33
00:03:22,920 --> 00:03:29,810
Limit going back to the default namespace that we have been working on just like how the members within

34
00:03:29,810 --> 00:03:32,840
the House refer to each other by their first names.

35
00:03:32,990 --> 00:03:38,190
The resources within a namespace can refer to each other simply by their names.

36
00:03:38,210 --> 00:03:47,630
In this case the web app part can reach the db service simply using the hostname db service if required.

37
00:03:47,710 --> 00:03:52,400
The Web app Pod can reach a service in another namespace as well.

38
00:03:52,420 --> 00:03:56,950
For this you must append the name of the namespace to the name of the service.

39
00:03:57,040 --> 00:04:02,950
For example for the web pod in the default namespace to connect to the database in the dev environment

40
00:04:03,300 --> 00:04:04,570
or namespace.

41
00:04:04,570 --> 00:04:13,320
Use the servicename.namespace.svc.cluste.local format that would be db service.

42
00:04:13,500 --> 00:04:22,260
Dev.SVC.cluster.local you're able to do this because when the service is created a DNS entry

43
00:04:22,290 --> 00:04:29,000
is added automatically in this format looking closely at the DNS name of the service.

44
00:04:29,000 --> 00:04:37,810
The last part Cluster.local is the default domain name of the kubernetes cluster SVC is the subdomain

45
00:04:37,870 --> 00:04:42,490
for service followed by the namespace and then the name of the service itself.

46
00:04:46,190 --> 00:04:50,080
Let us now look at some of the operational aspects of namespace.

47
00:04:50,140 --> 00:04:52,290
Let's start with a Kube control commands.

48
00:04:52,430 --> 00:05:00,020
For example, this command is used to list all the pods but it only lists the pods in the default namespace

49
00:05:00,860 --> 00:05:03,330
to list pods in another namespace.

50
00:05:03,350 --> 00:05:08,000
Use the namespace option in the command along with the name of the namespace.

51
00:05:08,000 --> 00:05:16,830
In this case Kube system here I have a pod definition file when you create a pod using this file.

52
00:05:16,910 --> 00:05:22,400
The pod is created in the default namespace to create a pod in another namespace.

53
00:05:22,400 --> 00:05:30,340
Use the namespace option if you want to make sure that this board gets created in the dev environment

54
00:05:30,400 --> 00:05:31,480
all the time.

55
00:05:31,570 --> 00:05:37,450
Even if you don't specify the namespace in the command line you can move the namespace definition into

56
00:05:37,450 --> 00:05:42,300
the pod definition file like this under the metadata section.

57
00:05:42,310 --> 00:05:48,530
This is a good way to ensure your resources are always created in the same namespace.

58
00:05:48,640 --> 00:05:52,910
So how do you create a new namespace like any other object.

59
00:05:53,020 --> 00:06:01,390
Use an namespace definition  file the API version is V1  kind is namespace and under metadata specify

60
00:06:01,390 --> 00:06:02,410
the name.

61
00:06:02,410 --> 00:06:03,100
In this case.

62
00:06:03,100 --> 00:06:07,900
Dev run the Kube control create command to create the namespace.

63
00:06:07,930 --> 00:06:12,790
Another way to create a namespace is by simply running the command Kube control.

64
00:06:12,790 --> 00:06:20,560
Create namespace followed by the name of the namespace now say we're working in three namespaces.

65
00:06:20,770 --> 00:06:27,070
As we discussed before by default we are in the default namespace which is why we can see the resources

66
00:06:27,130 --> 00:06:34,240
inside the default namespace using the kube control get pods command and to view those in the dev namespace.

67
00:06:34,240 --> 00:06:41,410
We have to use the namespace option but what if we want to switch to the dev namespace permanently so

68
00:06:41,410 --> 00:06:45,320
that we don't have to specify the namespace option anymore.

69
00:06:45,340 --> 00:06:52,210
Well, in that case, use the Kube control config command to set the namespace in the current context.

70
00:06:52,210 --> 00:06:59,810
Dev you can then simply run the Kube control get pods command without the namespace option to list pods

71
00:06:59,900 --> 00:07:06,590
in the dev environment but you will need to specify the option for other environments such as default

72
00:07:06,710 --> 00:07:12,010
or prod similarly you can switch to the prod namespace the same way.

73
00:07:13,310 --> 00:07:20,390
Finally to view pods in all namespace use the all namespace option in the command.

74
00:07:20,390 --> 00:07:26,320
This will list all the pods in all of the namespace is taking a closer look at the command.

75
00:07:26,420 --> 00:07:33,740
This command first identifies the current context and then sets the namespace to the desired one for

76
00:07:33,740 --> 00:07:35,840
that current context.

77
00:07:35,840 --> 00:07:41,660
Well contexts are used to manage multiple clusters in multiple environments from the same management

78
00:07:41,660 --> 00:07:42,610
system.

79
00:07:42,740 --> 00:07:49,100
It is a totally separate topic to discuss and requires its own lecture so we will discuss context in

80
00:07:49,100 --> 00:07:52,460
another lecture to limit resources in a namespace.

81
00:07:52,460 --> 00:07:56,490
Create a resource quota to create one.

82
00:07:56,510 --> 00:08:02,570
Start with a definition file for resource quota specify the namespace for which you want to create the

83
00:08:02,570 --> 00:08:10,940
quota and then under spec provide your limits such as 10 pods 10 CPU units 10 GB byte of memory

84
00:08:10,940 --> 00:08:12,260
etc..

85
00:08:12,410 --> 00:08:14,570
Well that's it for this lecture.

86
00:08:14,570 --> 00:08:20,660
Head over to the coding exercise and section and practice working with namespaces and I will see you

87
00:08:20,870 --> 00:08:21,770
in the next lecture.
