1
00:00:00,000 --> 00:00:10,700
Hi let us understand about Namespace. Namespace is nothing but a way of

2
00:00:10,700 --> 00:00:15,400
consolidating the objects together, so that the management is going to be

3
00:00:15,400 --> 00:00:20,400
much easier. I can consolidate all the similar objects or the object needs to be

4
00:00:20,400 --> 00:00:26,266
accessed by a team or a group of users, I can put in within a namespace. So

5
00:00:26,266 --> 00:00:30,799
namespace going to act like an abstract layer where I can apply the permissions

6
00:00:30,800 --> 00:00:35,933
or resource utilization all such criterias I can apply against the namespace and all

7
00:00:35,933 --> 00:00:41,266
the objects within the namespace will adhere to that particular policy. Let us

8
00:00:41,266 --> 00:00:46,399
understand more about namespace, let's go ahead and do a demo. I am into the

9
00:00:46,400 --> 00:00:52,366
minikube installation I can use the command kubectl get ns or namespace

10
00:00:52,366 --> 00:00:56,166
that's going to list all the name space available within the installation. These are

11
00:00:56,166 --> 00:01:01,966
all the default installation got installed during the installation of minikube and

12
00:01:01,966 --> 00:01:07,399
by default all the objects will get added into the default namespace. I can go

13
00:01:07,400 --> 00:01:11,966
ahead and create my own namespace as well and I can get all the objects

14
00:01:11,966 --> 00:01:18,599
within all the namespace for example if I want to get all the pods, I can say get

15
00:01:18,600 --> 00:01:26,666
pods and provide all namespace -namespaces. So  it's going to list all the pods available across

16
00:01:26,666 --> 00:01:31,932
all namespaces and it's going to list the namespace as well, for example this

17
00:01:31,933 --> 00:01:38,133
particular pod is available as a part of the kube system namespace. I can

18
00:01:38,133 --> 00:01:42,299
go ahead and create my own namespace and make the default

19
00:01:42,300 --> 00:01:46,966
namespace as a different one than the default. Let's go ahead and check the

20
00:01:46,966 --> 00:01:53,366
yaml file to create the namespace. I do have a yaml file where I have mentioned

21
00:01:53,366 --> 00:01:57,899
the kind as namespace and I have provided the name as well. So a

22
00:01:57,900 --> 00:02:04,100
namespace with this specific name my-ns-1 will get created. Let me go ahead and

23
00:02:04,100 --> 00:02:08,133
create the namespace using this specific file, I'll provide the command

24
00:02:08,133 --> 00:02:15,099
kubectl create-f and then the yaml file name. The namespace got created. Now

25
00:02:15,100 --> 00:02:22,366
I'm going to use another yaml file where it is going to create a namespace my-ns-2

26
00:02:22,366 --> 00:02:27,766
Let me go ahead and execute the yaml file, so the name space would have got

27
00:02:27,766 --> 00:02:32,799
created. I can go ahead and list the namespaces available. I do have these

28
00:02:32,800 --> 00:02:38,933
two namespaces, that got created very recently and I can go ahead and start a

29
00:02:38,933 --> 00:02:43,499
pod or any object within the specific namespace. If I doesn't provide the

30
00:02:43,500 --> 00:02:48,000
namespace parameter it will get created within the default namespace, I'm going

31
00:02:48,000 --> 00:02:55,100
to create a pod with the name my-redis and it is going to use the image redis and

32
00:02:55,100 --> 00:03:01,966
it'll get created within the namespace my-ns-1, don't worry about the deprecated

33
00:03:01,966 --> 00:03:07,299
warning or otherwise I can go ahead and use the option create. I'm going to create

34
00:03:07,300 --> 00:03:12,900
another object with the name my-nginx that will get created within another

35
00:03:12,900 --> 00:03:20,400
namespace my-ns-2. Now I can go ahead and get all the deployments the

36
00:03:20,400 --> 00:03:23,333
run command would have created a deployment, now let me go ahead and list

37
00:03:23,333 --> 00:03:27,366
the deployments available. There are no deployments the reason because if I

38
00:03:27,366 --> 00:03:30,966
doesn't provide the name space it is going to list the deployments available

39
00:03:30,966 --> 00:03:36,066
within the default namespace but the deployments got created in a specific

40
00:03:36,066 --> 00:03:42,266
name space and I can provide the option --all namespace, so that its going to list all

41
00:03:42,266 --> 00:03:46,966
the deployments in all the namespace. Here I do have a deployment and that is

42
00:03:46,966 --> 00:03:52,399
available in this specific name space and I can get the deployment specific to

43
00:03:52,400 --> 00:03:57,700
a namespace by providing the parameter --namespace and then the name of the

44
00:03:57,700 --> 00:04:02,233
namespace. So it's going to list the deployment available within this specific

45
00:04:02,233 --> 00:04:08,299
namespace and whenever I'm working on the kubectl by default it is going to

46
00:04:08,300 --> 00:04:12,033
point to the default namespace, I can go ahead and change that default

47
00:04:12,033 --> 00:04:16,565
namespace to a different namespace. For that I will be setting a context let me

48
00:04:16,565 --> 00:04:22,832
go ahead and set the context and that can be viewed from the config command

49
00:04:22,833 --> 00:04:27,799
let me go ahead and view the default config available using the command

50
00:04:27,800 --> 00:04:35,033
kubectl config view, so here what cluster the kubectl is going to work on and what

51
00:04:35,033 --> 00:04:39,966
are all the context, so the cluster name, user all the details will be available. I can

52
00:04:39,966 --> 00:04:45,732
set and create a new context by using the config command, let me go

53
00:04:45,733 --> 00:04:50,366
ahead and create a new config for the namespace. So I'm using the command

54
00:04:50,366 --> 00:04:57,066
kubectl config and set the context to my context 1 where it is going to use the

55
00:04:57,066 --> 00:05:03,066
my-ns-1 as the default namespace and minikube as the cluster and user as

56
00:05:03,066 --> 00:05:08,099
minikube. So the context is not available, so it's going to get created, I can see the

57
00:05:08,100 --> 00:05:15,300
details about this specific context and I can change the current context to this

58
00:05:15,300 --> 00:05:23,000
specific custom context. Let me go ahead and check the current context that is

59
00:05:23,000 --> 00:05:28,866
minikube, I am going to change that to context 1. So I am changing or switching

60
00:05:28,866 --> 00:05:33,832
the context from minikube to my context 1 the one that we created. Now let me go

61
00:05:33,833 --> 00:05:38,599
ahead and list the deployments, so it's going to list the deployments available in

62
00:05:38,600 --> 00:05:45,466
the context, that is the current context that I am using. So in case if I wanted to

63
00:05:45,466 --> 00:05:50,932
see what context or the configuration I am working on I can use the option

64
00:05:50,933 --> 00:05:56,566
kubectl config view. So that's going to provide the information on what context

65
00:05:56,566 --> 00:06:01,966
that, this particular shell is pointing it to and the cluster, username other details

66
00:06:01,966 --> 00:06:05,699
will be available. The same way I can go ahead and create multiple context as

67
00:06:05,700 --> 00:06:10,700
well and this is very similar to the workspace we are creating for individual

68
00:06:10,700 --> 00:06:15,500
users or for the team. Let me go ahead and create another context which is

69
00:06:15,500 --> 00:06:21,566
going to point to the namespace 2. So I have created another context and the

70
00:06:21,566 --> 00:06:26,399
shell is using the context 1 and whenever I wanted to see the objects

71
00:06:26,400 --> 00:06:31,500
available within that specific context I should be in a position to see that.

72
00:06:31,500 --> 00:06:36,166
In case if I wanted to see any objects available in another namespace then

73
00:06:36,166 --> 00:06:42,332
I have to provide the parameter --namespace, the same way if I try to see

74
00:06:42,333 --> 00:06:47,966
details about an object available in another namespace, I'm going to get the

75
00:06:47,966 --> 00:06:53,199
error message because currently it is pointing to the namespace 1 and

76
00:06:53,200 --> 00:07:00,666
my nginx is available as a part of namespace 2. So if I change the context

77
00:07:00,666 --> 00:07:05,199
and if I see the details about that specific deployment my nginx then it

78
00:07:05,200 --> 00:07:12,400
should be visible. So this is very similar to how we have the user object or the home

79
00:07:12,400 --> 00:07:17,466
directory available as a part of operating system and I can go ahead and delete

80
00:07:17,466 --> 00:07:22,866
any specific namespace and see what's going to happen? Let me go ahead and

81
00:07:22,866 --> 00:07:28,699
delete the name space 2. I'm trying to list all the deployments and all the

82
00:07:28,700 --> 00:07:32,500
namespace and I will not have the deployment as well, so deleting a

83
00:07:32,500 --> 00:07:37,166
namespace is equivalent to deleting all other objects available as a part of the

84
00:07:37,166 --> 00:07:41,799
namespace as well. So handling the namespace should be very careful

85
00:07:41,800 --> 00:07:46,466
reason because while deleting the name space it is going to delete all the objects

86
00:07:46,466 --> 00:07:52,032
available within the namespace as well. For cleaning purpose let me go ahead and

87
00:07:52,033 --> 00:07:58,766
delete the other namespace as well and namespace 1 is also deleted and I can go

88
00:07:58,766 --> 00:08:02,666
ahead and get the deployments available as a part of minikube

89
00:08:02,666 --> 00:08:07,299
installation minikube context is the default context. I can go ahead and the switch

90
00:08:07,300 --> 00:08:13,633
the context to minikube using the option use context and the context will get

91
00:08:13,633 --> 00:08:19,533
switched to minikube. Now all the commands by default it is going to point

92
00:08:19,533 --> 00:08:24,599
to the default namespace. As a part of advanced configurations we can go

93
00:08:24,600 --> 00:08:29,200
ahead and do the resource limitations for the namespace as well as updating

94
00:08:29,200 --> 00:08:33,732
and changing the name space, resource utilization and access control to the

95
00:08:33,732 --> 00:08:37,533
namespaces all these details we will be seeing it as a part of advanced

96
00:08:37,533 --> 00:08:41,599
discussion of namespace. So in a quick summary we have seen how to use

97
00:08:41,600 --> 00:08:46,000
namespace, create a new namespace and switch the context to the new

98
00:08:46,000 --> 00:08:49,133
namespace and the consequence of deleting a namepace

99
00:08:49,133 --> 00:08:53,633
by having some objects within the namespace.

