Skip to playerSkip to main content
  • 1 day ago
CI/ CD Pipeline, Docker and Kubernetes lecture series
Transcript
00:02Now next we are going to deploy our first application with kubernetes.
00:07That's why we will take a lot of classical example of mongodb, mongodb and mongexpress
00:11that same setup we will recreate, which we already created in the docker-compose lecture.
00:18So basically what we are going to have, we will create two containers.
00:23One will have mongodb database and second container will have ui.
00:29Ui means it is going to be mongoexpress which is basically our frontend.
00:34If someone has a request on the mongodb database, we will forward that request to mongodb database
00:40and within our database we will do changes which we will show on our frontend.
00:44So basically in this setup we will have one database and one frontend.
00:48We will set up these two separate pods.
00:51We will create a basic setup which we want to create a mon-based, frontend, backend-based
00:56and we will create a full stack project with our full stack project.
00:59So what we are going to have,
01:02because we have two applications which we want to deploy,
01:05two applications which we want to create pods.
01:08One is mongodb which is basically mongodb and the other is going to be mongodb.
01:13This is mongodb which is our frontend or our UI.
01:16So what do we do?
01:17We will create two pods.
01:19This is our pod one.
01:21This is our pod one.
01:22In which we will set up our MongoDB.
01:25And this is our pod two.
01:27In which we will set up our second application mongodb.
01:31We will set up our express.
01:33So we are going to have two different pods,
01:35which are two different applications which are set up.
01:38When we create pods,
01:40then we will also create a service.
01:41We will have one service which we will create here.
01:45This is our service one.
01:47And one service which we will create here.
01:50This is going to be our service two.
01:52Now because mongodb is our database,
01:55and when we create the database,
01:57then we have to store it with its credentials.
02:00So with mongodb we are going to create something called secret.
02:04We have already talked about the secret component.
02:06We have already talked about confidential information,
02:09confidential environment variables.
02:11They are all working to store it.
02:12In which we have mongodb's username and password
02:16store it.
02:18Now this secret will have access to pod one.
02:21because definitely if we want to access the database,
02:25we want to set up the database,
02:27then it should have access to the user name and password.
02:30With that access,
02:33it will also have pod two.
02:34Because,
02:36when there will be any request with mongodb,
02:38we will actually implement that request.
02:41In our mongodb database.
02:42If there will be any request in service two,
02:45then it will transfer to service one.
02:46And mongodb will actually change the actual database.
02:48and then we will change the changes.
02:49But,
02:50for those changes,
02:51we also need to have admin credentials.
02:54So,
02:54that credentials will have access to this secret.
02:58Plus,
02:59we also need to know that
03:01we need to redirect the request.
03:03If we actually need to access the database.
03:05I mean,
03:06mongodb is the actual database.
03:08This is just our front-end.
03:10But,
03:10we need to have database database also.
03:12So,
03:13we will directly define that URL.
03:16We will not define that URL.
03:17For storing the URL,
03:17we are basically going to create a config map.
03:21In our config map,
03:23this is our config map.
03:24Config map in our database,
03:26we will store the URL.
03:27And,
03:28this config map will have access to our pod two.
03:31So,
03:31the flow will be like,
03:31when we have any request for mongod express.
03:35Basically,
03:35it will have its service.
03:37This will be our external request,
03:38which will be our browser through.
03:40Now,
03:41external request,
03:42so,
03:42this service is also an external service.
03:45This service should be open to the internet,
03:48and should be able to accept all the incoming requests.
03:51So, it is an external service.
03:52By default,
03:53it will be our internal service,
03:54which we will use for internal communication.
03:55We will use it.
03:56Like the request of pod two,
03:58it will have Mongo Express.
03:59It will see the database URL and credentials.
04:02Then,
04:03the request will be forwarded.
04:04Our second service,
04:06i.e. mongodb actual database.
04:08The database will use these credentials,
04:10and in the database will actual changes.
04:12So,
04:13in this way,
04:13we have a full flow which we will set up.
04:15In this flow,
04:17we will create two pods.
04:19So,
04:20this is our pod one,
04:21this is our pod two.
04:22We will create two services.
04:24This is our internal service.
04:26This is our external service.
04:28With that,
04:28we will create a config map.
04:31Which is going to store the database URL.
04:34And,
04:34we will create a secret.
04:36In which we will store our username and password.
04:38Database admin credentials.
04:40So,
04:41this is the overall setup,
04:42that we are going to create with Kubernetes.
04:45If we are going to visualize this setup,
04:46so,
04:47the setup is going to look something like this.
04:49Which will be our incoming requests,
04:51they will come here.
04:53These are our incoming requests.
04:55And,
04:55where will it come from the browser.
04:58So,
04:58we will go to the browser.
04:59We will go to the browser,
05:00which we will access our service.
05:03This service will be connected with this pod.
05:05Which is the frontend pod.
05:07That means,
05:07the pod is Mongo Express.
05:08From here,
05:09we will know what is the database URL.
05:12We will go to the Mongo URL.
05:13Then,
05:13we will send the request.
05:15So,
05:15service to service communication,
05:16we will request our internal service.
05:18This request will be MongoDB.
05:20We will have username and password.
05:22We will have actual changes in our database.
05:24So,
05:25this is what the deployment flow is going to be.
05:28With that,
05:28we will discuss some of our steps.
05:30We have these different steps,
05:32which we will perform and complete our deployment.
05:36Now,
05:37in these steps,
05:37generally,
05:38what do we think?
05:39Generally,
05:39we think that I will create a pod.
05:41So,
05:42for the pod,
05:42I am going to have this deployment.
05:45In this deployment,
05:46there is a pod that will create.
05:48Similarly,
05:49this copy will be another deployment.
05:51And,
05:52this deployment will also be our pod.
05:53Which we will create.
05:55But,
05:55generally,
05:55when we talk about secrets,
05:57when we want to connect with a pod or deployment,
05:59with a secret.
06:01Or,
06:02we want to connect with a config map.
06:05So,
06:06before we create a deployment,
06:08we will create a secret.
06:09Similarly,
06:10before we create a deployment,
06:12we will create a config map.
06:14This is why,
06:14in our steps,
06:15even though,
06:16generally,
06:17we will create a deployment.
06:18But,
06:18before we create a secret,
06:21we will create a secret.
06:21Then,
06:22we are going to create the deployment.
06:23Then,
06:24the internal service of MongoDB,
06:26which is here.
06:27Then,
06:27the config map.
06:28The deployment for Mongo Express.
06:30Then,
06:31the external service for Mongo Express.
06:33So,
06:33in this way,
06:34we will complete our whole setup.
06:36complete.
06:37Now,
06:38the first part of the setup is to start with configuration files.
06:42First,
06:43we will start with MongoDB configuration file.
06:47First,
06:48we will set up with this pod.
06:50Then,
06:51we will set up with this pod.
06:51we will set up with this service.
06:53Plus,
06:54we will set up with our secret.
06:55These are three components.
06:56which we will create first.
07:02Now,
07:03to create these components,
07:04we will go to a folder.
07:05I am going to create a file.
07:07I am going to name it
07:11mongodb deployment.yaml.
07:26db deployment, here we are going to keep the name here, we are going to keep the mongodb
07:30in replicas we are going to create one pod, in the selector we are going to have the
07:35mongodb, in the template we will keep the mongodb, in the containers we will install
07:41which image we will install in our container, which we will run in the container, that is
07:45going to be the mongodb image, basically if i go on to docker hub, this is the mongodb
07:51image, which is called mongo, we can check them in the environment variables, these are the
07:59most important environment variables, root username and root password, here we have our
08:05name, the image is going to be, in fact here we are going to do mongodb instead of mongodb,
08:12mongodb is the image name, we will use the mongodb, in the ports, because we are using
08:18mongodb, there is a specific port that we have to use, and that port is 27017, so our incoming
08:25requests are on this port, because the mongodb server in the image listens on the standard
08:30mongodb port, so this is the same port which we will keep our container port, that we need
08:35all the mongodb requests on this port, now these are all our basic specifications, now the
08:41next thing we are going to define, that is going to be environment variables, when we are
08:45if we are going to work on our deployment, these are the two important environment variables
08:48that we have to define circumstance, environment variables, we will redefine
09:07mongodb init root username. So this is the first environment variable.
09:13Now we are going to leave the value away, because we will not directly write this value.
09:16We will define this value in our secret. Because the username of our database, the username
09:22plus let's copy this, our database of the password, these two information are
09:30which we will write secret. And it also makes sense. Because we have already talked about
09:35our configuration YAML files, we upload all of them in our common repository
09:40with our application code. So if we push something on GitHub,
09:44within our secret information, our credentials, our links, urls information
09:48should not be written directly. So we will never write our username and password
09:53because configuration file is something which can be publicly available. Now let us create
09:57the second resource which is going to be mongodb secret. So for mongodb secret
10:01we are going to create a new file which is mongodb secret.yaml.
10:07In this file, we also have our basic details, our API version
10:11kind. In the API version, we are going to keep v1.
10:15In the kind, this is a secret that we are creating. Meta data
10:19this will be mongodb secret. In the labels, we don't need to give
10:22as such anything. When we define the type in secret, we define the type
10:26opaque. Opaque basically means that this information is hidden
10:29and this is secret. And with that, we define our data
10:33So in the data, there are two pieces of information that we have to define
10:44So these are the two pieces of information which we have to define.
10:47Now I am going to call this mongoroot username and similarly this
10:52password is going to be mongoroot password. Now for the sake of simplicity
10:57we assume that in user name, we have to keep root
11:02and password inside, we have to keep password
11:04pass. These are the two information that we have to store.
11:07But here, when we store in secret information,
11:10this is the same thing which we have already discussed theoretically
11:12we have already discussed. When we store credentials
11:15we don't store credentials directly in the file
11:19We store credentials in base64
11:22encoded format. Basically, if our value is root
11:26then we convert this into some random characters
11:29Similarly, if value is password
11:31then we will convert this into random characters
11:33and we store those random characters
11:37And these random characters are not exactly random
11:40These are basically our base64 encoding
11:42which we perform. Here, when we talk about encoding
11:46Encoding is not equal to encryption
11:48Encryption means that when we form data
11:50we change the form of hashing function
11:52One time, we have encrypted data
11:54and decrypt it is very difficult
11:56without the exact hashing function
11:58But in encoding, if we have this value
12:01then the original value is very easy
12:03So encoding doesn't mean that we have security
12:06We have security for security
12:07We have to encrypt data
12:09But here, in file, we store data
12:11in encoded form
12:13In base64, we have some basic commands
12:16which we can use
12:17We basically echo
12:20For this particular word
12:22First of all, we encode our username
12:24So we want to encode the root
12:27in base64
12:28So this is a particular command
12:30As we enter, we have
12:32encoded format
12:33Now encoded format in base64
12:36is something which is fixed
12:37If we run the same command again,
12:39then we have the same output
12:39So here, the encoded format
12:42This is this value
12:43So we remove it
12:44And we store it
12:46Similarly, we run the same command
12:51For pass
12:52So pass
12:53That is this particular value
12:55So here, we save it
12:58So this is the base64 encoded format
13:02which we store
13:02Now generally, when we talk about
13:04production-level environments
13:05We use a secret manager
13:10Like AWS secrets manager
13:12So we have different services
13:13which are available with different cloud providers
13:16Like AWS, Azure, GCP
13:18Let us save it
13:19And in MongoDB deployment
13:20We will refer them
13:22Where do we refer them
13:23Where do we refer them?
13:25We will refer them
13:27Now to exactly define
13:29which way they will define
13:32We will use a attribute
13:34which is value from
13:36In value from, we will tell
13:37that these environment variables
13:39Where do we refer them?
13:40So these environment variables
13:42Basically, secret
13:43key reference
13:45Where we define a secret
13:47name
13:49and there
13:50and the exact key
13:53that we are going to use
13:54define that key
13:54So when we refer the value from
13:57we write value from
13:59secret key reference
14:01Then we write our secret name
14:02and that key
14:03So here the secret name
14:06is this name
14:08that we have given to our secret
14:10which is MongoDB secret
14:13and the key
14:14username key value
14:15is key say
14:16So this is the key
14:18Same cheease
14:19we are going to get the value from
14:24secret key reference
14:26We are using camel case everywhere
14:30jahaan per
14:30the name of the secret
14:32and the key
14:33that we are going to refer
14:34the name of the secret
14:36is this
14:38jihse we haan per paste kar sakte hai
14:39which is the same name
14:40and the key for password
14:41is this particular key
14:43jahaan se humara data
14:44humara data humare paas
14:44hae ga
14:45to this tariqe se in environment
14:47variables ko
14:47hum secret ke through refer
14:49now let us save this code
14:51and we have also
14:52saved the secret
14:53to yeh donoh humare paas
14:54humara deployment ready hai
14:56humare paas humara secret ready hai
14:57humare paas humara secret ready hai
14:57so sab se pehle
14:58let us clear this
15:00we are inside the same
15:01kubernetes folder
15:01jahaan per humare paas
15:02ribas humare paas hume
15:09gazo
15:11humare paas
15:14humane Doll
15:16ukee
15:27ahedi dh
15:29fields
15:32haver
15:32konon
15:32ho gaya, apne secret ko check karni ke liha, i can do kubectl get secret, so humare paas
15:38ek secret hai, single secret, mongodb secret, iska type hai opaque, this type was defined
15:44by us, in the yaml configuration, and iska ander do data hain, jinko im store kara raha
15:49hain, so these are the two pieces of information, ek data username hai, ek data password hai,
15:55next hum apply kareenge for mongodb deployment, dot yaml, to humare deployment create ho
16:01gaya, if i do kubectl get all, to ek to humare paas humare deployment create ho
16:08gaya hai, by default service humare paas hai hi, deployment ke saath mein this is the replica
16:13set, jho humare lihae create hoa hai, desired state one pod, current state one pod, and
16:18uske saath mein, i can also do kubectl get pods, to humare paas ye single pod hai, jho create
16:26ho gaya, it is in the running state, aur is pod ke ander humare paas humare mongodb database
16:30jho hai, vho run kar raha hai, infact i can also check details of this pod, to let's
16:35do kubectl, describe, pod, pod name, and these are all the pod related information, to here
16:46haan se humare jo information hai, wo print ho rahi hai, ye humare mongodb deployment pod
16:50ka naam hai, ye ip address hai us particular pod ka, the pod is in running state, and uske
16:56saath mein replica set ki, humare paas information aagahi hai, plus pod ke ander, environment
17:02variables mein, mongodb init root username, and ye, ye donoh humare environment variables
17:07hain, which are available out there, and if I look at the port number, so this is the
17:11port, jhaan per humare incoming request ari hoongi, 27017, jisse humane, yaha par container
17:17port ke ander define kiya tha, toh abhi humare poore set up ke ander, we have created the secret,
17:22we have created the deployment for mongodb, next thing that we are going to do is to create
17:27the internal service for mongodb, ab mongodb ki, let's clear this, mongodb ki internal service
17:35ko hum chahehen toh, ek different file bana sakte hai, called mongodb service, toh is tarikay
17:40se ek different file bhi bana sakte hai, vayase generally, jab bhi production environment ke
17:44ander koji deployment kreate hoata hai, compulsorili nahi, but almost har practical
17:48case ke ander, jab bhi hum ek deployment ko create karte hai, deployment ke saath, hum humayesha
17:52ek service ko create karte hi karte hai, chahe ho internal service ho, chahe ho external service ho,
17:57toh isi liye deployment and service ko hum chahehen toh same file ke ander bhi create
18:01kar sakte hai, kisi bhi yamil fil ke ander kisi bhi configuration file ke ander, zarru ji ni,
18:05amik single resource ka configuration de, hum multiple resources ke bhi configuration de sakte hai,
18:10just se single file ke ander hum deployment ko bhi configuration liek sakte hai, service ko bhi
18:13liek sakte hai, secret ko bhi liekak sakte hai, multiple different types, toh hum isi same deployment
18:17file ke ander, apne service ka configuration likhenye vaale hai hai, and different configuration ko
18:22likhen ke liye, we separate them with three dashes, then dash ke baad, hum hum bilkul naye sire sa
18:27we can write our service configuration. So we will copy the code for Nginx service and paste it here.
18:35We will keep the same API version. Kind is going to be service. Metadata, this is going to be mongodb
18:41service.
18:42We are going to connect with mongodb in the selector so that you know which pod is attached to this
18:49service.
18:49It is attached with this particular pod which is labeled mongodb and this particular deployment which is labeled mongodb.
18:56We will keep the protocol TCP. Now because it is fixed for mongodb, we will go to this port.
19:03We will keep our incoming port and target port. We will keep the same request to this port.
19:10We will redirect them to this same port in the container. So this is the basic information that we are
19:16going to describe with our service.
19:17We will save it. And which we have applied our deployment the first time via this command.
19:23We will run this same command again. So our deployment is unchanged because we have no change in deployment.
19:30But for us, there is a new service which is created.
19:33We want to check this service.
19:35We will check that.
19:36The service name is mongodb service.
19:44So our paas this service can the data get and this is our end point.
19:49Matlab service carry a key is endpoint but requests are redirect
19:52hoongi. Matlab this should be the pod IP address.
19:55Pod IP address check karne ke liay.
19:58Hum check kar leete hain.
20:00This should be the IP address.
20:03kubectl
20:05get pods
20:06hyphen o wide.
20:09So our paas this is the same IP address
20:12which is our endpoint here.
20:14And this pod is 27017
20:17which is the port number
20:18on our request redirect hoongi.
20:21Matlab our service successfully
20:22with our deployment and our pod connect ho chukia.
20:25So finally our third step
20:26that is complete ho gaya.
20:28Next we will do that is to create a deployment
20:31for mongo express and for config map.
20:33So now
20:35our internal service
20:36mongodb create ho gaya.
20:39Next we will create
20:40pod ko create karenge.
20:41And apne config map ko create karenge.
20:44So let us clear this and come back here.
20:47To yaha par next
20:48jho hum
20:49apna deployment karne wale hain.
20:51That will be for mongo express.
20:53Before we do that hum apni naming jho hai thodi si fix kar sakte hain.
20:56To ek baar
20:58let us
20:59delete all the existing
21:02setup. To cubectl
21:04we are going to delete hyphen f
21:06mongo db deployment dot yaml.
21:09And we are also going to delete
21:11the secret dot yaml.
21:13To abhi ke liye
21:14if i do cubectl get all
21:16i have nothing.
21:18Let's clear this.
21:19Hame is deployment ko rename karenge
21:21to
21:22let's call it mongo dot yaml.
21:25kyunki abhi say mongo db deployment kena is not very suitable.
21:28kyunki is kanda sirf deployment
21:29ni hai hai.
21:29It's kanda ab service ka bhi code hai.
21:31To humi say mongo yaml kane wale hain.
21:33And yaha par isse bhi hum reename kar denge.
21:37To mongo secret.
21:39To ye do pieces of information hai.
21:41Dubara say same setup create karne ke liye
21:43simply bus do commands hai.
21:44jin ko hume run karna hai.
21:46mongo apply hyphen f yad rakhna hai.
21:48Secret ko pehle hum create karenge.
21:50To we are going to have
21:53mongo secret dot yaml.
21:55And similarly we have
21:57mongo dot yaml.
21:59To hummari paas sari ki sari hummari services
22:01create ho gai hain.
22:07Next hum create karenge
22:08similar tariqe se mongo express dot yaml.
22:12Jaisi mongo dot yaml ke andar
22:14hummari deployment and service tha.
22:16Vaisi mongo express ke andar bhi
22:17hum deployment and service
22:18duno ko rakhhenge.
22:19And uske saath mein
22:20we are going to have
22:21mongo config map dot yaml.
22:26So sabse pehle let's come to mongo express.
22:28Mongo yaml ke andar hummari
22:30jitna bhi deployment ka code tha.
22:32Usse hum copy kar leete hai.
22:33And let's paste it in mongo express.
22:36Yaha par api version same hai.
22:38Kind is deployment.
22:39We are going to call it
22:40mongo express.
22:42So this is going to be the name.
22:44Uske saath mein label bhi humm same rakhenge.
22:47Yaha par selector mein we are going to have
22:49the same values.
22:50Toh yaha par bhi mongo express.
22:52Image ke andar bhi we have mongo express.
22:54If we go to the mongo express image on docker hub.
22:57Toh docker hub ke upar bhi we have different different
22:59specification related to mongo express.
23:01Toh yaha par port hamara 8081 hi ho na chahi hai.
23:04So this is something which is already specified.
23:07Port 8081 ho na chahi.
23:08Plus iske bhi kuch particular environment variables hai.
23:11Jais se environment variables mein.
23:12First important environment variable is me config mongodb admin username.
23:17Second one is admin password.
23:18Toh user name and password hai hummare paas.
23:20And third important variable hummare paas url ka hota hai.
23:23Which is the mongo db server.
23:24Which is this environment variable.
23:26Toh yeh tino environment variable hai.
23:27Jhunko mein set karna padega.
23:29Sabse pehle toh port ki baat kertte hai.
23:30The container port should be 8081.
23:33Uske saath mein abh hummare paas tine environment variables hai.
23:36Jho aane waale hai.
23:38The first environment variable will be me config mongodb server.
23:45Second environment variable will be this admin username.
23:50Yehaan par change kar leete hai.
23:52Third environment variable will be admin password.
23:58Toh yehaan par mongodb server ki value aai ki config map se.
24:02Matlab this is the database url.
24:03Par admin username and admin password ki value aai ki humare secret se.
24:07Toh admin username ki value.
24:09Agar hum secret mein jayen.
24:11Toh yehaan par username.
24:13This is the key.
24:14Jhaan se hummari value aane waale hai.
24:17And this is the key for password.
24:18Toh yeh dhonoh values already sahih hai.
24:21Ki agar humme username chahiye.
24:22Toh hum secret se lerek arayenge.
24:24MongoDB secret se.
24:25And is ki key ye hai.
24:26Agar humme password chahiye.
24:27Toh hummongoDB secret se lerek arayenge.
24:29And is ki key ye hai.
24:30Okay there is a small typo in the password.
24:33Which is basically that I've defined it as hyphen hyphen.
24:37Isko hum abhi ke liye itna hi rakh sakte hain.
24:38Kyunki yeh vyse bhi developer specific chiz hai.
24:42As a developer humme se define kar sakte hain.
24:43Although yaan par single hyphen hona chahiye tha.
24:45Par abhi ke liye I'm just going to leave it to double hyphen.
24:48Toh ek chiz jisko humne abhi tuk create nahin kiya hai.
24:51That is this part.
24:52Yeh jo value hai yeh secret se nahin aayegi.
24:54Yeh value basically humare config map se aayegi.
24:58So this value should come from config map ki ref.
25:01Toh yehaan par humara config map aayega.
25:03Yehaan par humari ki bhi config map ki aayegi.
25:05Toh secret se value ko copy kar leete hain ek baar.
25:08And config map ke andar.
25:10Apeni information ko store kerte hain.
25:12Config map me we are going to have v1.
25:14Yehaan par service ke andar we are going to have config map.
25:18Meta data ko hum rakhenge.
25:19Ok mongodb config map.
25:22Yehaan par hume type define karne ki zharurat niye hai.
25:25Data ke andar humara a ki data hai.
25:27Jisko hume store karna hai.
25:28Which is the database url.
25:31Database url ke andar humara kaunsa url jayega.
25:34Basically agar humari paas request aayegi.
25:36Toh wo request kahaan par forward honi chahi.
25:38If we look at our diagram.
25:40Toh basically hume define karna hai ki agar iske paas request aayegi.
25:43And yeh jo service hai.
25:44Isse request aayegi.
25:46Yehaan par forward karnei hai.
25:47Toh kaunsa link hai jahaan par yeh request forward honi chahi.
25:50This link, this mongo url is basically is service ka link.
25:54Request kahaan par forward honi chahi.
25:55Is internal service per.
25:57Toh yehaan par what will be the url.
25:58The url is going to be mongodb service.
26:04Toh yehaan par the url is going to be mongodb service.
26:09Yeh jo url hai.
26:10Yeh mongo yamil ke andar.
26:11Jho service ke andar humne naam rakhha hai.
26:13Yeh hi same naam.
26:14Yehaan par humare database url ke andar jana chahi.
26:16Let us save it.
26:18And yehaan par aaker.
26:19We basically define the name for the config map.
26:23The name for the config map is this.
26:28And the data is database url.
26:31This is the database url that we are defining.
26:34Which is basically the mongodb server.
26:36Toh isse save kar lete hai.
26:37Is tarikay se humne complete kar liya hai apna mongo express.
26:42And apne config map ke configurations ko.
26:45Toh sabse pehle ja kar.
26:47We are going to create the config map.
26:48qctl apply hyphen f mongo db.
26:57I think its mongo config map dot yamil.
27:00And similarly we are also going to create mongo express.
27:05Toh let us clear this and do cube ctl get all.
27:10Toh ab humare paas do deployments hai.
27:12Ek humarei mongo db pod ke andar.
27:14Ek humarei paas mongo express hai.
27:16And ek humarei paas mongo db ka pod hai.
27:18Uske saath mein services mein.
27:20Ek default service hai.
27:21Mongo db ki service hai.
27:23Replica sets hai.
27:23If I want I can do cube ctl get pods.
27:28Toh humarei paas yeh dono pods hai.
27:29And cube ctl logs.
27:32If I want the logs of let's suppose my mongo express.
27:37Toh sari ka sari logs are associated with my mongo express.
27:40Mongo express par kyunki hum apni request ko bhejihengi.
27:43Here pa sari incoming request haengi browser pe.
27:45Toh yaan par mongo express server is listening at this location.
27:50Toh server is open to allow connections from anyone.
27:52Toh is tarikai seh we can check if the services are running or not.
27:56To summarize.
27:56In tino portions ko in tino steps ko humane complete kar liya tha.
27:59Ab humane apne mongo config map ko bhe create kar liya hai.
28:02Deployment ko bhe create kar liya hai.
28:03Last thing that we have to do is to create an external service.
28:06Ta ki jitni bhi incoming requests ra raha hai.
28:08Unko humarei service serve kar seke.
28:10Toh uske lehi.
28:11We are going to create the external service in the mongo express yaml.
28:16Yehaan par ek new service hum create kar leete hai.
28:18And let's copy it from here.
28:23Toh same cheez hum copy kar leete hai.
28:24Api version same rahe ga kind service rahe ki.
28:27This is going to be mongo express service.
28:31And yehaan par humari jo application hai.
28:33That will be mongo express.
28:35Ab jab bhi hum external service create kar raha hai.
28:37Yehaan par we have to define something called the type.
28:39The type of the service is going to be load balancer.
28:44Toh this will come directly below selector.
28:47Toh humari jo service ka type hai.
28:48Kyunki external service hai.
28:49Yeek load balancer ho ga.
28:51Jho services ko redirect kar ne ka ka kaam kar ega.
28:53Ab mongo express ke liye hume pata hai.
28:55Humara port is fixed which is 8081.
28:57Toh hum service ke anndar yehaan par request ko accept karenge.
29:01Aur apne pod ke anndar bhi isi port par request ko redirect kar dhe.
29:06Ab jab bhi hum ek external service ko define kar raha hai.
29:08Minikube ke anndar.
29:09We have to also define a third port.
29:12Ports ke anndar ek humara normal port hai.
29:14Which is the incoming request port.
29:15Ek humara target port hai.
29:16Iske saath me we also have something called the node port.
29:20Node port is basically that port.
29:22Jisko browser ke anndar hum use karenge.
29:25Matlab jab bhi hum browser se apne kisi hi particular service ko access karenge.
29:28Apeni application ko access karenge.
29:30Toh hum ek port number jho define karenge.
29:32Woh port number is going to be this node port.
29:35Directly hum internal port 8081 ko access nahi karenge.
29:38Hum ek or external layer humari paas hai.
29:40Node port hi jhaan par hum request ko send karenge.
29:43And ye jo node port hai.
29:44Iske particular range hoti hai.
29:45Which is from 30,000 to 32,727.
29:50So this is the particular range for node ports.
29:53And humare jo node port ki value hai.
29:54Woh waise toh hum denge.
29:55Par woh value ishi range ke anndar hi honi chahiye.
29:58Toh yaan par for the sake of simplicity.
30:0030,000 hum de sakte hai.
30:0230,000 hum de sakte hai.
30:0230,000 one de sakte hai.
30:03Koi bhi simple si value ko hum de sakte hai.
30:05And this is how we are going to define our entire service.
30:08Let us save it.
30:10And yehaan par dubara se hum re apply kar denge.
30:14Apne mongoexpress.yaml ko.
30:16Toh humara mongoexpress deployment is unchanged.
30:19Humare liye ek nai service hai.
30:20Woh create ho gahi hai.
30:21Let us clear this.
30:22And do kubectl get services.
30:26Toh humare paas yeh toh default service hai.
30:28Yeh humaree mongodb ki service hai.
30:31And yeh humaree mongoexpress ki service hai.
30:33Ab by default joh services create ho tii hai.
30:35They are all internal services.
30:36Matlab sirf pod to pod communication hi allowed ho ta hai.
30:39Toh wahan par type me humaree paas cluster ip a gaya.
30:42Cluster ip matlab cluster ke anndar joh different nodes available hai.
30:46Thru these services.
30:47But jab bhi hum external access allow kerte hai.
30:50Ki browser se bhi request accept ho jaya.
30:51Joh basically humaree external service ho gaya.
30:53Toh wahan par type ke anndar humaree type is different.
30:56Which is load balancer.
30:57Acha jab bhi external service hum allow kerenge.
30:59Toh external kuch ip address bhi ho na chahiye.
31:01Why is that?
31:02Kyunki agar humaree request yehaan se a rhi hai.
31:04Toh request ko aane ke liye.
31:06Hame kuch ip address deena padeega.
31:08Jahaan par request a sake.
31:09And kuch port number deena padeega.
31:11Port number hume pata hai.
31:12Yeh joh port number hai.
31:13Yeh humaree node port number hai.
31:15Joh yaan par defined hai.
31:16Which is 3000.
31:17Kya humaree request hai.
31:18Woh aayen ki 3000 per.
31:19Per internally 8081 per redirect ho jayenge.
31:22Or or internally bhi pod 8081 ke port per redirect ho jayenge.
31:26Toh yaan par node port.
31:27Matlab port number hume pata hai.
31:28Which is going to be 30,000.
31:29But what is going to be the ip address.
31:32Jisko hume expose kareenge internet per.
31:34This ip address automatically.
31:35Jabb bhi hum kubernetes production environment ki baat kerti hai.
31:38Toh haan par automatically.
31:39Assign ho jata hai.
31:40Per yahaan par abhi yeh joh external ip address hai.
31:43Yeh assign nahi hua hai.
31:44It is in pending state.
31:46Toh minikube ke anndar.
31:47Yeh joh external ip address ho ta hai.
31:49For external services.
31:50Isko hume alag se ja kar assign kar na ho ta hai.
31:52With an additional command.
31:54Or yeh joh ip address ho ta hai.
31:55Sif external services ke liye ho ta hai.
31:57Internal service ke liye nahi ho ta.
31:58If we look at internal service ke anndar.
32:00If we look at internal service ke anndar.
32:00Toh yehaan par external ip address ki form me.
32:02Humare paas none available hai.
32:03Toh is ip address ko assign karne ke liye.
32:06Minikube ke anndar.
32:06We have this command.
32:07Minikube service.
32:09Annd jis bhi service ke liye hume assign karna hai.
32:12Which is mongo express service.
32:14Jaisi hume enter karne ke.
32:16Vaisi hi by default.
32:17Humare liye humare jo url hai.
32:19Woh open ho jayega.
32:20In fact if we look here.
32:22Toh yehaan par this was the service.
32:23Yeh humare target port tha.
32:25Yeh humare url hai.
32:26Toh humare liye yeh joh ip address hai.
32:28Assign ho gaya.
32:29And this was our 30,000 port number.
32:31Toh sari cheize ab defined hai.
32:33Hum jab first time log in kar rahe hai mongo express par.
32:36We have to log in.
32:37With username as admin.
32:39And password as p-a-s-s.
32:41Hum sign in kar deenge.
32:42And we are now inside mongo express.
32:45Toh this is the front end.
32:46And this mongo express is actually connected with the database.
32:50Is ko verify karne ke liye hum kya karne ke liye.
32:51Naya database create karne ke.
32:53With the name apna college.
32:57And this database is created for us.
33:00Hum chahehen toh is database ke anndar.
33:01Apna ek naya collection create kar sakte hai.
33:04Let's call this sigma.
33:05Hum naya collection create kar diya.
33:07And this is our new collection sigma.
33:10We can go back to our databases.
33:12And this is our database here.
33:14Toh finally humari jo poori application hai.
33:16Jis mein humara poora UI hai.
33:18Which is our dashboard.
33:19And humara jo database hai.
33:20Wo host ho gai hai.
33:21Wo deploy ho gai hai.
33:22With the help of kubernetes.
33:23Now we can also deploy the entire setup.
33:26We can stop it.
33:27And let's clear this.
33:28Yeha param kar sakte hai.
33:29kubectl get all.
33:31There are different different resources hain.
33:33Humare liye jo create ho gai hain.
33:35In saare resources ko delete karne ke liye.
33:38We can do kubectl delete hyphen f.
33:43We have the mongo dot yaml.
33:47Uske saath mein we have mongo secret dot yaml.
33:51We have mongo express dot yaml.
33:56And we have mongo config map dot yaml.
34:00Toh if I do kubectl get all.
34:03I am going to get the default service.
34:06Which was already available there.
34:07And in fact kubhi bhi.
34:08Agar am minikube ko stop karna chaathe hai.
34:10Toh we can stop it like this.
34:11Toh joh humara last step tha.
34:13Which was to create an external service for mongo express.
34:16Yeh bhi humare liye complete ho gai hai.
34:18Up to summarize.
34:19Humane apna jo poora deployment tha.
34:21Isko complete ka diya hai.
34:22Humare jo requests hain.
34:23Woh basically yaha par a rhea hai.
34:25Humare browser ke an dar.
34:26Jab bhi hum external service ko request bhej rahe hai.
34:28Toh humare liye humara dashboard khul raha hai.
34:30Yeh dashboard kaise khul raha hai.
34:31Humara ek external IP address hai.
34:34Jho humare liye assign hua hai.
34:35Which is this IP address.
34:37And this port number.
34:38This URL.
34:39Jhaan par jaysay hi request aeggi.
34:40Woh 8081 par redirect ho raha hai.
34:42Phir yaha par.
34:448081 se.
34:45Humare jo mongo url hai.
34:46Matlab jo internal service hai.
34:47Waha par request redirect ho raha hai.
34:49Toh 7017 par.
34:51And waha se humare mongodb database.
34:53We am access kar pa raha hai.
34:54Is database ko access karne ke liye.
34:55We are using this username and password.
34:57So this is the entire setup.
34:59Which we have created.
35:00Jiske andder humare containers me.
35:02Successfully mongodb and mongo express.
35:04Are running inside minikube.
35:06Which is our kubernetes cluster.
35:07So I hope ki aataka mehi detail mein samaj mein aayoga.
35:09Ki kubernetes ke different components ki.
35:11Kya importance hai.
35:12Kya usage hai.
35:13Or kis tarikai se real life practical scenarios ke andder.
35:16Hum apni applications ko kubernetes ke oopper deploy kar sakta hai.
35:23Now next thing that we are going to learn about.
35:25Are namespaces in kubernetes.
35:27Basically namespaces are something which are used in kubernetes.
35:31To organize our resources.
35:32Jisai abhi ke liye jitne bhi clusters ka humne example liya hai.
35:36Un clusters me hum chahe toh kitne bhi deployments, services, pods, config map, secret.
35:41Kitne bhi chahe toh resources ko create kar sakte hai.
35:43And yeh sare ki sare joh resources create hoate hai.
35:45Yeh randomly within the same cluster space create hoare hai.
35:49Jisai for example if we are creating a deployment.
35:52Toh deployment ke saath jitne bhi humare pods create hoare hai hai.
35:54They are getting created in the same space.
35:56Similarly agar hum apne services ki baat kere hai.
35:59Toh services bhi create hoare hai within the same space.
36:01But kabhi kabhi humare paas eisai kaafi sari requirements hothi hai.
36:05Where we need to organize our resources.
36:07Kyunki abhi toh humne kubernetes ko use karna start kiya hai.
36:10But after a point in our cluster we are going to set up a lot of resources.
36:13A lot of deployments, a lot of config map.
36:16Jitna zyada hum kubernetes ko use karenge.
36:17In fact, jihse jihse haamari application ka size bhi badeega.
36:21Waisse waisse jitne component, jitne resources hume create karne hai.
36:24Woh bhi increase hoonge.
36:25Toh humare paas koji eak tariqa hoona chahiye aapne sare resources ko organize karne ke lihe.
36:29It basically is like saying ki humne apne computer par ek folder create kiya hai.
36:33Aur ushi folder ke anndar hum different different different different files ko add karte ja rhe hai.
36:37So after a lot of files there will come a point jab hume need hoogi of organizing those files.
36:42Toh vaisse hi, jihse humare computer mein humare paas folders hoote hai.
36:45Folders ke anndar humare paas eak option hoona chahiye to create some kind of a sub folder structure.
36:51Ta ki hum cheezo ko aur zyada sub folders ke anndar organize kar sake.
36:55And wahi tariqa name spaces hume kubernetes cluster ke anndar deete hai.
36:59Jab bhi hum resources ko club karna chaathe, combine karna chaathe,
37:03Ek separate space ke anndar rakhna jate hai.
37:05Waha par hum name spaces ko use karta hai.
37:07And by default there are four name spaces in kubernetes which are already existent for us.
37:12Jiasse if I go to my terminal and type cube ctl, get name spaces.
37:17Toh I am going to get four default name spaces
37:20joh by default kubernetes humare liye create karta hai.
37:22Jismei hai default, kube no release, kube public and kube system.
37:27Ab yeh 4 ho by default humare mini kube ke anndar exist kareengi.
37:30Hum chahehen toh aur apni taraf se bhi name spaces create kar sakta hai.
37:35So, if we talk about these four name spaces.
37:38So, if we talk about these four name spaces.
37:39So, let's talk about these four namespaces.
37:40And then we are going to create our own custom namespace.
37:42Kisi bhi kubernetes cluster ke anndar,
37:44yeh 4 default namespaces hain joh hamisha exist kerti hai.
37:46Jismei se first hai kube system.
37:48Kube system is basically for system related components.
37:51Jitne bhi humare kubernetes system se related components hote hain.
37:54Woh sare ki sare components.
37:56Jahan par kube system namespace ke anndar aate hain.
37:58Matlab this is the particular space jaha par woh sare components exist kerti hai.
38:03And this is a namespace which is not really meant for the general user.
38:07Hum as a developer jab kubernetes ko use kareenge.
38:09Toh kube system ke anndar generally hum kohi modifications nahi kerti hai.
38:12So, we don't really touch this namespace unless and until it is very necessary.
38:17Second namespace jo amare pas exist kerti hai.
38:19That is kube public.
38:20Kube public ke anndar publicly accessible resources ya components.
38:24Jise for example humare jitne bhi cluster related information hai.
38:28Jisko koi bhi user access kar sakta hai.
38:30As such koi authorization nahi chahiye.
38:32Koi authentication nahi chahiye.
38:33Woh sari ki sari information is stored in kube public.
38:36Jise we can go to the terminal and type kubectl.
38:40Cluster info.
38:42And this is going to give me the information regarding my cluster.
38:45And where is this information coming from?
38:47This information is coming from kube public.
38:49Iske saath mein humare pas ek or namespace hota hai.
38:52Which is called cube node lease.
38:54In namespaces com subfolders ki tarah samaj sakta hai.
38:56Jynke anndar kuch na kuch component stored hai.
38:59Ab har ek node ke paas apni kuch lease objects hoti hai.
39:02And in lease objects ki jo hardbeets hoti hai.
39:04Uska data is stored in this particular namespace.
39:07This particular namespace has the information regarding a node's availability and a cluster node's health.
39:12Uske saath mein humare pas ek default namespace hoti hai.
39:16By default agar hum koi bhi resource create karte hai.
39:19Jise hum koi deployment create kar rahe hai.
39:20Koi stateful set create kar rahe hai.
39:22Config map create kar rahe hai.
39:23Secret create kar rahe hai.
39:24Or uske saath agar humne koi bhi namespace defying nai kiya.
39:27Toh by default wohh sare ke sare resources ha.
39:30Hamaari is default namespace ke anndar aate hai.
39:32Jise for example.
39:33If we want to get all of the namespaces.
39:36Toh yaa toh hum licksakta hai cubectl get namespaces.
39:43Toh yaha par humare paas sare ke sare namespaces ha jayenge.
39:47Agar hum chaatay hai ki hume kisi particular namespace ke resources ko check karna hai.
39:51Toh uske liye hum licksakta hai cubectl.
39:55Get let's suppose I want to check for not for deployments but for services.
40:00Get services off the namespace default.
40:02Hama default ke anndar jho jho humare paas services exist kar rye hai.
40:06Wohh check karna chate hai.
40:06Toh uske liye we have this flag.
40:08Jaisi hum enter karayenge.
40:09Toh humare paas ek jho by default humare service create ho kar aati hai.
40:12That service is available to us.
40:14Agar hum aisa nahi likte hai.
40:16If we don't define a flag.
40:17Toh by default jitni bhi commands aaj tak humne run ki hai.
40:20Wohh sari ki sari default namespace ke liye hi check kerti hai.
40:24This command is equal to this particular command.
40:27Toh jab bhi koji namespace define nahi hota.
40:29By default humare jho resources hai.
40:31Wohh default namespace ke resources fetch kiya jate hai.
40:34Or hunki information humare paas display ho kar aati hai.
40:36If we want we can also verify this information.
40:38Just say if I do ls.
40:40We have this nginx deployment dot yaml.
40:43Which is available to us.
40:45Ab nginx deployment yaml mein agar hum create karayenge se.
40:50Let's do kubectl apply engine hyphen f nginx deployment yaml.
41:00So we have a new deployment which is created for us.
41:02And if I do kubectl get deployments.
41:07We are going to get the deployment.
41:09And if I do hyphen n default.
41:11Then we are going to get the same deployment.
41:14Kyunki yeh jho deployment hai.
41:15Yeh humare liye default namespace ke andre create hua hai.
41:20Ab jab bhi hum namespaces ki baat kar raha hai.
41:22Namespace ke kaafi sare practical and real life uses hai.
41:25Jho samajna baut important hai.
41:26Sab se pela in sab se important use case of having namespace.
41:29Is having separation of concerns.
41:31Separation of concerns kehne ka matlab hai ki.
41:33Let us suppose humare paas yeh a cluster hai jho exist karta hai.
41:36Ab apne is cluster ke andre agar hum directly apne resources ko create karte jayenge.
41:40To we'll have a lot of resources.
41:42But hum chahayen tohu apne un resources ko kisi bhi particular application ke lihe logically segregate kar sakte hai.
41:47For example if we are building a mern based application.
41:51Jiske andre database me hum mongo db use karayenge.
41:54And uske saath me humne caching ke lihe redix ko use kiya hai.
41:58To hum apne is mern application ke lihe.
42:00Do name spaces ko create kar sakte hai.
42:03Eek ke andre humari jho mern application related.
42:06Sara ka sara humare back end ka code hai.
42:08Front end ka code hai.
42:09Woh sare ki sare resources aa jayenge.
42:10Usse related haemari paas.
42:11Sports aa jayenge.
42:12Services aa jayenge.
42:13Secrets aa jayenge.
42:15Config maps aa jayenge.
42:16And dousare name space ko hum naam de sakte hai.
42:18Data related services.
42:19Toh jitani bhi humari database related services hai.
42:22Humari caching related.
42:23Redis related services hai.
42:25Resources hai.
42:26Woh sare ki sarei cheezo ko hum yahaan per rakhye.
42:28Toh is tariqe se humari application ke anndar hi humari paas separation of concerns ho gaya.
42:32Abh ye joh separation of concerns hai.
42:34Imeh normal day to day project ke anndar nahin chahehi ho ta.
42:36Par jab bhi hum kisi organization ke anndar baat kerne ki baat kertai hai.
42:39Toh wahan per separation of concerns bhoat zyadha important ho jata hai.
42:42Second benefit of namespace is application grouping.
42:44Ab generally kubernetes ko jab bhi teams ke anndar use kiya jata hai.
42:48Organizations ke anndar use kiya jata hai.
42:49Toh wahan per minimum 8 to 10 to 12 members at least team mein hoote hai.
42:53Kyunki bhoat chote size ke teams per kubernetes ko use karne ka utna zyadha sense nahin bantah.
42:57Ab jab bhi hum application grouping ki baat kerre hai.
42:59It basically means ki let us suppose humari paas ek single application hai.
43:03Jis per 2 different teams hai joh work karee hai.
43:05Now this is team a joh humari ek application ke part ke ooper work karee hai.
43:09And this is team b joh usi application ke kisi dousaray part ke ooper work karee hai.
43:13Ab jab tak humari paas koji particular namespace nahin hai.
43:16Team a chahe toh koji bhi resource create kar sakti hai.
43:19Jyase for example jab tak humari paas namespaces exist nahin karte hai.
43:22Team a na let us suppose koji pod create kiya called pod application.
43:27And team b ne bhi same pod create karne ki kooshish ki.
43:30But since they are working on different parts of the application,
43:33they don't actually know about what the other team is doing.
43:35Toh yaha paas jab bhi resource creation ki baat hati hai.
43:38Bekut sare conflicts arise kar sakti hai.
43:40Toh in conflicts se bachne ke liye hum kya kar sakti hai.
43:43Agar humari large scale application hai.
43:45And uske and the same application ke ooper multiple teams kam kar rahe hai.
43:48Toh hum un individual teams ko apne apne namespaces day sakti hai.
43:52So that all the resources that are being created
43:53are being created in these particular namespaces.
43:56Isse humari joh conflicts arise hoote hai,
43:58wo cancel out chayenge.
43:59Third important use case namespaces ka hota hai environment separation.
44:02Jab bhi hum kisi bhi application ko build karte hai.
44:05Us application ke liye hume multiple environments ko create karna hoote hai.
44:07A very general example of this ki humari paas ek dev environment hai.
44:11Ek staging environment hai.
44:12And ek humari paas prod environment hai.
44:14Ab jab any teen environment se related hume resources ko create karna hooga.
44:18Unko segregate karne ka, separate karne ka,
44:20humari paas name spaces hai.
44:21Jai se agar hum kisi bhi mon based application ki baat kari hai.
44:24In fact non mon based application ki baat kari hai.
44:26In fact non mon based application ki baat kari.
44:27Humari paas kuch front end code hooga,
44:28kuch back end code hooga,
44:29humari paas koi admin panel ho saktai ha,
44:31humari paas database ho saktai ha.
44:32Abh ye sare ki sare resources,
44:34development ke andder bhi honi chahi ha,
44:35staging ke andder bhi honi chahi ha,
44:37prod ke andder bhi honi chahi ha.
44:38Toh is basis par hum kya kar sakte hai.
44:40For the different environments,
44:42we can create different name spaces,
44:45jinkai andder us environment se related particular resources humari paas ho.
44:49So this could be a name space for dev,
44:51this could be a name space for staging
44:53and this could be a name space for production level setup.
44:57Next use case of name spaces is versioning.
44:59Jabbhi hum kisi bhi application ko build karte hai,
45:01usse hum different versions ke andder build karte hai.
45:03Ab let us suppose humari paas kisi application ka
45:06koi current version hai jo already exist karte hai.
45:08This humari application hai.
45:10Is application ka,
45:11this humari paas current version hai.
45:13Ab hum chahate hai,
45:14kal ko humari application ka,
45:15ek new version hai,
45:16jisko hum deploy kare hai.
45:18Toh new version ke liye,
45:19hum chahehen toh new resources hai,
45:20jinko create kar sakte hai.
45:22Toh in particular resources ko,
45:23for the different versions of the same application,
45:26hum different name spaces ke andder create kar sakte hai.
45:28This is also something which will be beneficial
45:30for blue green deployment.
45:32Blue green deployment kanehi ka matlab hai,
45:34blue basically stands for the current version of our application
45:37and green stands for the new version of the application.
45:39Jabbhi hum application ka koi nya version rilease karna chahate hai,
45:42toh hum chahate hai,
45:42bich mein jo down time hai,
45:43woh bilkul minimum rai.
45:44Matlab agar users humari current version ko abhi use karre hai.
45:48Toh jab hum nya version rilease karenge,
45:49toh asa niya ki bich mein build banne ka jo time ho ta,
45:52deploi honne ka jo time ho ta hai.
45:53Us time tak hum humane current version ko show hi na kare
45:56or us time tak humari app na available ho.
45:58Toh, humi application ki availability ko badaani ke liye,
46:00this is a type of deployment that sometimes is used,
46:03which is called blue green deployment,
46:04jisme hum same application ke do version ko create karte hai,
46:07aur new version ko ekdom se switch kar deyte hai,
46:09from the old version,
46:11which leads to minimization of downtime.
46:12Toh is tarikai ki versioning,
46:14agar hum kubernetes ke andder karna chahate hai,
46:15toh waha par hum namespaces ko different rakh sakte hai,
46:17and this will help us a lot.
46:20Next, joh humare paas benefit ho ta hai of using namespaces,
46:22that is security policy.
46:24Ab kabhi bhi, agar humari a large organization hai,
46:27jisme application bhi,
46:28and application ke kai sare components hai,
46:30jisme same cluster par kai sare log ka am kar rahe hai.
46:32Toh waha par we don't want everybody to have access to all of the resources.
46:36Toh aise me hum kya kar sakte hai,
46:37humare joh resources hai,
46:39unko hum different namespaces ke andder divide kar sakte hai,
46:42and sare users ko pure cluster ke resources ki jage,
46:44hum sif kisih particular namespace ke resources ki access de sakte hai.
46:48Toh is tarikai se koi bhi agar user hai,
46:50toh woh apne particular namespace ke resources ko access kar payenge,
46:53par dousari namespaces ke resources ko access nahin kar payenge.
46:56Toh is tarikai se hum kaafi sari security policies ko implement kar sakte hai,
46:59by only giving access to the required users of the required resources.
47:03Next benefit humare paas ho ta hai,
47:05for resource, limits and quotas.
47:06Hum chahi toho kisi bhi kubernetes cluster me,
47:08kisi particular namespace ke lihe kuchh quota set kar sakte hai,
47:11yaani resource ki kuch limit set kar sakte hai.
47:13For example, resource limits me kisi bhi namespace ke lihe hum define kar sakte hai,
47:18ki woh kitna CPU utilize kar sakte hai,
47:20kitni RAM utilize kar sakte hai,
47:21kitni storage utilize kar sakte hai.
47:23Toh is tarikai se humari ek particular joh resource limit setting hai,
47:27usko bhi hum implement kar sakte hai with the help of namespaces.
47:29Toh is component ko system ke kitne resource ki access malni chahi,
47:32uske lihe hum hunne kini particular namespace ke under create kar sakte hai.
47:35So these are all the important benefits,
47:38as well as the use cases of having namespace in kubernetes clusters.
47:50Ab abhi tak humne jo baat ki woh default namespaces ki baat ki,
47:53par hum chahi toh humne khud ke custom namespaces ko bhi create kar sakte hai.
47:56By using the create command,
47:58we can simply write kubectl create namespace.
48:04Uske baad hum apne namespace ka naam le sakte hai.
48:06Let us call it custom namespace.
48:08So this is our own namespace just ko humne create ki hai.
48:11Now if I do kubectl get ns,
48:14I am going to get my own namespace jisko humne abhi create ki hai.
48:18Ab is namespace ke under hum particular resources ko create kar sakte hai.
48:21Just for example humne nginx deployment ka example liya tha.
48:26If I do ls and do kubectl,
48:30apply hyphen f nginx deployment.
48:33Toh isi same nginx deployment ko humne custom namespace ke under create kar sakte hai.
48:38Instead of using the default namespace.
48:40Matlab instead of this we can create it here.
48:42Uske le hai humne yaan par define karna padega apne is particular deployment me.
48:46Ki hum kaha par apne is deployment ko create karna chaate hai.
48:49Toh iske humare paas do ways hote hai.
48:50Sab se pahla is through command line.
48:52Command line ke under humare paas ek option hota hai which is called namespace.
48:55Jiske under hum kisi bhi existing namespace ka naam de sakte hai.
48:59Toh existing namespace humare paas ye hai.
49:01I am going to define it here.
49:03And we are going to create a deployment in this particular namespace.
49:07Now if I do kubectl get deployments.
49:12Something interesting is going to happen.
49:14We are not going to get anything.
49:16But if I do hyphen n custom namespace.
49:22Then I am going to get this particular deployment.
49:25Toh ye jo command hai amne already discuss ki hai by default.
49:29Default namespace ke under check kata hai.
49:31But jaise hi humne define kar diya.
49:32We don't wanted to check in the default namespace.
49:34Hum custom namespace ke under access karna chaathe hai deployments ko.
49:37Toh humare paas humare jo nginx ki new deployment hai.
49:39Woh create o kara gai.
49:41Ab kyunki real life practical scenarios ke under.
49:43Hume koi single deployment create nhi karna ho ta.
49:45Uske saath me hume aur bhi bhout saare resources create karna ho ta hai.
49:48Toh command line per is tarikai se.
49:49Flag define kar ki namespace me.
49:51Resources create karna ka jo idea hai.
49:53That is not very good.
49:54Because hume yad nahi rehga ek point ke baad.
49:56Jab hum 10 resources, 15 components,
49:58Bees components ko create karna ga ki ki kaunse component ko humne kis namespace me create ki hai.
50:02Toh ab better way of doing this is defining it in the configuration file.
50:07Configuration file ke under jo bhi humare paas meta data ho ta hai.
50:10Meta data me name ke saath hum apne namespace ko be define kar saakta hai.
50:13Toh agar hum apne kisibhi deployment ko, kisibhi pod ko, kisibhi service ko,
50:17Secret ko, config map ko, kisi particular namespace ke under create karna chata hai.
50:21Toh we can define that information in the meta data.
50:24Or wahan par hum apne kisibhi custom namespace ka jo name hai usko define kar sakta hai.
50:28Ab agar namespaces related sari ki sari cheize humne dhyhan se padi hai.
50:31Toh a common sawaal hai joh abhi emare dhamag ke under.
50:34Which is ki agar humne bokalt sari namespaces ko create kar liya.
50:38Jiasse for example if I have this namespace 1.
50:40If this is namespace 2, namespace 3.
50:44In fact we also have the default namespace.
50:46Toh is tarikai se agar humare paas bohut sari ek point ke baad different namespaces ho gai.
50:50And in different namespaces ke under, humne alag-alag-alag-alag components ko create kar liya.
50:54Ab let's suppose humare joh application hai,
50:56Uske major components is namespace 1 ke under exist karte hai.
50:59Aur yahan par hum baar baar baar aapne components ko access karna chate hai.
51:03Toh baar baar kya hume is option ko use karna padega to define the namespace.
51:07I mean by default, humne patak command line se, humne default namespace waale components milte hai.
51:11Par agar hume kisii dousari namespace waale components ke saath ek saath work karna ho ga.
51:15Toh kya har command ke saath hum apni namespace ko define karenge.
51:18Toh simple terms mein uska answer hai yes.
51:19Agar hum koi extra tool use nahin kar rahe.
51:21Toh kisi bhi particular namespace ke resources ko baar baar baar baar access karne ke liya.
51:25Hume baar baar namespace waala option use karna padega.
51:28Par yahan par ek tool hai, joh hume kaafi zyadha help karta hai.
51:31Which is called Cubans.
51:33Cubans ko aage jaa kar hum install karenge and set up karenge.
51:36And dekhenge usse hum kis tariqe se use kar sakte hai.
51:38Par Cubans humare hi problem ko kaafi hat-tak simplify karte ta hai.
51:41Jisse default namespace ke alawa, agar hum kisi or namespace ke resources ko access karna chate hai.
51:45Unko use karke apna kaam karna chaate hai.
51:47Toh Cubans hume humare hi default namespace ko change karne mein help karta hai.
51:51So later in this section we are going to look into Cubans and we are also going to set it
51:56up.
52:12Whenever we are talking about namespaces, wahan par scope ka concept hai, joh kaafi important hai.
52:17Let's take an example of a cluster.
52:20Jiske under let us suppose humne do namespaces ko create kar diya.
52:24This is our namespace 1.
52:27And this is our namespace 2.
52:30In fact, ishi cluster ke andar humare hi paas kaafi sare or components hai which are available to us.
52:35So this is our cluster.
52:37Iske andar let us suppose humare hi paas ek, humne ek pod ya ek deployment create kar diya hai.
52:42Jiske andar we have our database.
52:44Ab yahaan par namespace 1 ke andar let us suppose humare hi paas koi application 1 hai ya uska koi
52:49component hai.
52:50Namespace 2 ke andar application ka koi dousra component hai.
52:53Namespace 1 ke andar hum let us suppose hume config map hai jisko create kar diya.
52:58Ab is config map ke andar sara ka sara database ka access ho ga.
53:02Toh ye config map yahaan par humare is database ke saath connect kar sakta hai.
53:06Ab yahhi kaam agar hum namespace 2 se bhi karna chawate hai.
53:08Maitlab hum chaathen ki application 2 bhi humare database ko same tariqe se access kar paai.
53:13Toh iska sab se simple tariqa ho ga ki yahaan par joh application hai.
53:17Woh ishi config map ko access kar hai.
53:19Yahaan se url le, yaha se username and password le database ke lihe.
53:22And directly jaa ka database ko use kar le.
53:25Maitlab the simplest way is ki application 2 humare application 1 ke config map ko access kar paai.
53:30But this is something which is not allowed in kubernetes.
53:33Basically harik joh resource create ho ta hai.
53:36Us particular resource ka eek scope ho ta hai.
53:38Scope matlab kahaan par woh resource accessible hai.
53:41Javascript ke andar already humne kai baar scope ki baat ki hai.
53:44Toh each particular component has a particular scope.
53:46Toh jitne bhi humare config maps ho ta hai.
53:49Agar hum config map ki baat karay.
53:51Hum secret ki baat karay.
53:52Hum pods ki baat karay.
53:54Hum deployments ki baat karay.
53:55In fact hum services ki bhi agar baat karay.
53:58Toh ye sare ke sare humare woh components ho ta hai.
54:01Jinka scope ho ta hai namespace.
54:03So they are namespaced components.
54:06Namespaced components ka nne ka matlab hai.
54:08Ki jis bhi namespace ke andar humne config map ko create kiya hai.
54:11Us namespace se baahar ke joh components hai.
54:13Woh usse access nahi kar saktay.
54:15Use nahi kar saktay.
54:16Services ko access karne ka use karne ka eek indirect tarikah ho ta hai.
54:20But ye bhi namespace components ke andar hi aate hai.
54:22Vahin dousari taraf humare paas aise kuch components ho ta hai.
54:24Jinka global scope ho ta hai.
54:25Global scope ka nne ka matlab hai ki all over the cluster.
54:28Unhne koi bhi component ja kar use kar saktay.
54:30Iske andar humari volumes a jati hai.
54:32Toh jitne bhi volume components ho ta hai.
54:34Unhne ham here par use kar saktay.
54:35Iske andar humara node a jati hai.
54:37Iske andar humara node a jati hai.
54:37Iske andar humara node a jati hai.
54:38Koi bhi component access kar saktay.
54:40If we want to get detailed information about each particular component scope.
54:44Toh there is a simple command that we can use.
54:46cube ctl api resources.
54:50We can simply do name spaced equals true.
54:56Name spaced equal true.
55:18If we want to check the global scoped components.
55:22Toh here we can use false.
55:24And global scope ke andar humari volume attachment.
55:28We also have the nodes.
55:30In fact we also have the namespaces themselves.
55:33Toh here humari wo sare resources hain.
55:35Jhinne koi bhi component kahin se bhi access kar saktay.
55:45Now next we are going to talk about the installation and usage of cubins.
55:49Ab shiruaat mein if I look at all of my namespaces.
55:53I have these namespaces.
55:54I have a custom namespace.
55:55Ham shahe toh is custom namespace ko in fact delete bhi kar saktay.
55:58To delete a particular namespace.
56:00I have to write cube ctl delete namespace.
56:04And then the namespace name which is custom namespace.
56:10Tojaisi humari namespace delete ho jayega.
56:12Ho humari namespaces list se hat jayega.
56:14And uske saath mein if I want to create it again.
56:17Toh I can do cube ctl create namespace.
56:21And let's call it my namespace.
56:25Toh humari paas yeh sare ke sare namespaces hain.
56:28Which will be available to us.
56:29Now next we are going to install kubin.
56:32Ab kubins ko install karne ke lihe.
56:33We have to type a command which is called brew install kubectx.
56:38Jaisi humis command ko run kareenge.
56:39Hamara installation start ho jayega.
56:41And along with installing kubectx.
56:43Our kubins will be installed.
56:46So once the installation is complete I can just clear it.
56:49And now we are going to type the command which is kubins.
56:52Jaisi hum kubins ko type kareenge.
56:54Humari paas sare ke sare namespaces ki list a jayega.
56:56Ab is list ke ander we can specifically see ki
56:59Humari jo default namespace hain.
57:01That is highlighted with the yellow color.
57:03Jo bhi namespace humari highlighted ho ti hai.
57:05Woh abhi current me.
57:06Humari default namespace hain.
57:08Matlab jitni bhi general hum commands likhenge.
57:10Woh hume is particular yellow highlighted namespace ke resources la kar deegi.
57:14Now to change this particular default namespace.
57:17We can write the command kubins.
57:19And uske baad jis bhi namespace com default namespace banana chaathe hain.
57:22Us namespace ko mention karte hain.
57:24And jaisi hum is command ko run kareenge.
57:26And if we run kubins again.
57:27To now we can see that my namespace is highlighted now.
57:31Which basically means ki abh hum jo bhi normal command run kareenge.
57:34Jaisi v2 kubectl get deployments.
57:36Toh humari paas by default my namespace wale deployments hain.
57:40Default wale deployments nahin hain.
57:42To is tarikay se jab hum kisi bhi particular application ko kisi ek particular namespace ke ander build karre.
57:48Maha par uske sare k sare components hain.
57:49And we want to access or we want to use those components specifically.
57:53Toh temporarily hum chahi toh upni default namespaces ko change kar sakte hain.
57:56And we can work with the application.

Recommended