0:00 Have you ever copied a Kubernetes YAML file from internet, change its image name and hope for it that it should work? Then this video is for you because in the next 30 hour you won't be just running the bunch of YAML files. You will understand each and every line of it. So hello everyone, my name is Shubham and I welcome you to Kubernetes on one short video because in this video we are going to start with Kubernetes from absolute zero and by the end of this video you will be installing, you will be scaling, you will be securing your application in your own Kubernetes cluster. This is not your regular course where you will be just running few bunch of commands. Here you will be writing your manifest file from scratch. And when I say scratch, it will be from zero. You will be writing the YAML file line by line and whenever something is getting break at the time we are going to debug it because that's the place where actual job looks like. So before we begin let me be clear about one thing that this video is not a CK course here I'm not teaching you about exam tricks. This is pure hands-on Kubernetes. So if you are a DevOps engineer, if you are a developer, if you are a cloud engineer 1:01 then this video is for you. Now what are the prerequisite for this video? So basically you should have fundamental knowledge the basic understanding of docker. Now don't worry if you don't know what exactly docker is and what are the fundamentals of docker you can find a link in the description first complete that video and then you can continue with this course. So now let me just tell you what all things we are going to cover right we are going to start with the architecture of Kubernetes because that will give us the clarity what thing we are dealing with right and then we are going to move forward with the cluster setup now don't worry about the cost I have designed these codes keeping in mind that you don't have to pay a single penny from your pocket but again I have also discussed about the alternatives that you can do right now then we are going to move forward with pods and yaml right now again don't worry if you don't know what exactly yl is we have a dedicated section where we would be discussing about YAML. Now once you are comfortable with the YAML then we are going to move forward with deployments. We are going to learn about demons set. We are going to learn about 1:56 jobs stateful set. Then we are going to move forward with services. Then we are going to learn about ingress gateway API and then finally we are going to cover stoages. We are going to learn about config map and secret. We are going to learn about probes, autoscaling, rback, network policies. We are even going to cover helm. And the last point that we would be sticking up would be TRD that is nothing but custom resource definition. 30 hours might sound a lot right but don't worry you don't have to cover the entire course in a single day. All you have to do is just take out one hour per day and in a month you will be done with Kubernetes. Then all you have to do is just put up your focus put up your dedication in the course in the section that you're learning and then things will be good for you. For your ease, I have added multiple chapters in the video. So you exactly know what is your starting point. Also one more suggestion. Now since this is a big video, what you can do is once you are done learning, just add the time stamp in the comment. So the next time when you're coming back to the video, you exactly know where you left. Now again since you are learning Kubernetes maybe 2:57 for the first time or maybe since you are revising the concept, you might get doubt. Again remember one more thing that no question is a silly question. I will be more than happy to clarify all your doubts, all your concept. So it will be a good learning for all of us. Right? One more thing, if you like this video, if you like this sort of format, make sure you are liking the channel, you are subscribing to the channel, sharing the video with the peers so that it reaches to maximum people. This will actually give me motivation to create content like this. So open your terminal, grab your notebook and let's get started for writing the manifest and let's get started with Kubernetes. Hey everyone and welcome to the world of Kubernetes. So before even we do a deep dive on Kubernetes, it is very much important for us to understand why that technology was created because we already had Docker for containerization. Then why we should learn this technology. Now see in software industry every tool is created to resolve one problem and Kubernetes was created to resolve a very big problem into the 3:57 software department. Now in this video we are going to understand why docker was not able to support us right what were the problem with docker what were the issues that the companies were facing and why kubernetes was needed right and don't worry I am going to keep it very much simpler so that you can even understand even someone who is learning kubernetes for the very first time this video will make sense for you so let's get started by understanding why the technology kubernetes was created so it is rightly said in In order to understand Kubernetes, the very first thing that you should understand is Docker. So here we are going to discuss how did Docker came as a revolution into software development journey. What problems did uh Docker solved and then we are going to understand what was the demerit of Docker and why we should consider Kubernetes. So before Docker application deployment was very difficult. It was very messy because developers used to say that it works on my machine and let's say when the application was moved 4:58 from one server to another suddenly there used to be many issues many things that used to break the application and it can be due to many reason it can be due to different software version it can be due to different operating system or it can be due to different dependency that are actually missing and this created huge problems and that's the reason docker came into the picture and what docker did docker allowed the develop help us to package everything into a single container. That's the reason the application was not crashing whenever they are moved to another server because here we were dealing with images and container. Everything clubed into a single place. Now imagine ordering food online from Zonato and you don't have to worry about the food because everything is carried by the container and that's what Docker was doing over here. Docker was packing the application, the libraries, the configuration and the dependencies everything into one container and because of this deployment became faster, application became portable and resource usage became better than the 5:58 virtual machine because here we were only using the resources that were actually required and due to that reason Docker was extremely popular into software development. Now since docker solved these many problem there were few demerits and here we are going to discuss top five issues development team was facing during the deployment with docker. Let's discuss problem number one. So now docker was amazing but up to a certain scale. Now let's say you are running two containers or maybe five containers. Managing them manually is easy. But let's say companies like Netflix, Amazon or Uber they run thousands of container. Now suddenly the question appears and what can be those question it's just like which server should run which container how many copies of the application should run and what happens during high traffic and how do we monitor everything imagine managing 500 containers manually. It is almost impossible. It's just like trying to control the traffic in an entire city without the traffic lights. So 6:59 everything became chaotic. Problem number two, manual container management. So without Kubernetes, engineers have to do everything manually. Start the container, they have to stop the container, they have to restart the container manually, they have to deploy the updates manually and they have to scale the dinner manually. Imagine the situation uh where the website suddenly gets huge traffic during a sale. Now the engineer need to manually create the containers quickly and if they react slow the application will crash. Now this will create obviously the human errors. The application deployment cycle will get slow and there will be operational stress. Now let's discuss problem number three that is load balancing. Now let's talk about traffic distribution. Suppose application has five running containers. Thousands of the users are opening your website. Now how do you distribute the traffic equally into the container? What if one container gets overloaded and another container stays idle and one containers crashes completely without 8:01 proper orchestration of this traffic. Managing the container was very much difficult. Now imagine five billing counters in a mall and all the customers go into one counter. That counter will become very overloaded while other will stay empty. The same thing happened with the container. uh this can make the application slow, unstable and sometime they become completely unavailable because of the stress that we are giving. Let's go to problem number four and that is nothing but container crashing. Sometimes container failed any time and that can be due to multiple reason. It can be due to application work, it can be due to memory issues, it can be due to network problem or it can be due to server failures. Now here's the problem. Docker alone does not automatically heal the application. If a container crashes, someone has to manually restart it. Now imagine a situation where it is happening at 3:00 a.m. in the night in the production. The website is slow, the customers are getting angry and the engineers, the DevOps engineers are getting continuous 9:02 fall. This is why modern system needed something called self-healing. Meaning something even after failing it should heal the system automatically. It should fix the system automatically by itself. Problem number five. Now things become even more difficult when application run across multiple server. Imagine a company running 10 server 500 containers and multiple application. Now the challenge for the engineers is to they have to manage uh which container runs where CPU and memory usage communication between those containers server health and networking. So very quickly the infrastructure becomes very much complicated and it's just like managing an entire city manually. And at this point company realized that we need automation and that's the reason company started looking for a better solution. So they needed a platform. So what they actually searching for companies actually started to look for a solution that uh that can help them in the cloud platform such as automatically scaling 10:03 up the application uh whenever a container is filled. It should restart the container. It should distribute the traffic properly. it should manage the server automatically and it should keep the application highly available. Basically they wanted a system that could intelligently manage the containers automatically and this gave birth to Kubernetes and Kubernetes was originally created by Google based on their experience of running massive application internally. So now that we understand why there is a need for Kubernetes, let's first discuss before we conclude what actually Kubernetes is. So a very simple definition Kubernetes is nothing but it is an orchestration platform. Now orchestration simply means managing everything automatically the very smart way. Uh now Kubernetes came into the picture. It was taking care of multiple thing. It take care of the deployment of the container, scaling of the container. Whenever a container fail it is to restart the container, load balancing, networking and managing containers across the server. So think 11:03 of docker as creating the containers and think of kubernetes as managing those containers as m massive scale the biggest difference. Now let us take the final summary. So docker solved the problem of containerization it make the application portable and easy to use. But when the application started to growing at massive scale, companies faced new issues, new problem uh such as scaling, manual management, load balancing, container crashing and multi-erver complexity. And Kubernetes was created to solve all these problem. In simpler words, if I want to say, if I want to conclude it, Docker creates container, Kubernetes manages them automatically at scale. And that is why Kubernetes became one of the most important technologies in modern DevOps and cloud computing. So that was all. I hope you understood why there is a need and why we should consider this technology for Kubernetes. So yeah, that was all and I will see you in the next one. So now we are already aware why 12:05 Kubernetes was created. So in this video we are going to understand what Kubernetes actually does. So if you are someone who knows docker even if a little bit this video will give you the clarity what kubernetes does and what power kubernetes bring us into the plate right because many of the people get confused between docker and kubernetes and most of them even think kubernetes replace docker but that's not actually the case kubernetes and docker both work together both are equally important too so today we are going to understand what docker does what kubernetes does and why kubernetes became important when application started to grow at scale. So let's get started. First of all, let us clear the biggest confusion upon Docker and Kubernetes. So Docker is responsible for creating and running the containers and Kubernetes is responsible to manage it. On that note, let's first understand what Docker helps us with, right? So let's consider that you have an application and where does Docker fits into that situation. So Docker will help you in packaging that application, run that application inside a container and 13:06 create an isolated environment for it. So Docker is mainly focused on creating and running the containers. Now when does Kubernetes come into the picture? Kubernetes come into the picture when you have many containers to manage. Now for example you have hundred of containers, you have thousands of users or you have multiple servers. At that point managing those containers manually will be a very big headache and Kubernetes solves that problem. It handles the automatic scaling. It does the self-filling. It restart the containers. It does the load balancing and it manages the uh containers across the server. So the simplest line to remember is docker creates the container and kubernetes manages them. One more thing uh you might be aware of it orchestration. So what is the meaning of orchestration? So basically just remember when I say kubernetes manage them it basically it orchestrates them. So what does orchestration mean actually? So let's take this example and by that you will be able to understand. Now imagine you own a food delivery company and initially you have only two 14:08 employees working with you. There are two delivery boy and there are few customer. So everything is manageable manually that time. So now consider your startup grows eventually. Now instead of few customers there are thousands of customers and instead of two delivery boys there are many delivery boys and instead of a single city you have expanded and your business is there in multiple location. Now suddenly the problem will start appearing and there will be questions like who should deliver which order? What if Wonderboy is unavailable? How should we handle the rush hours and how do we balance the work group? Same thing exactly happens with containers. Now let's consider that you are running a company and here instead of running mult multiple people you have to run 200 containers and there are multiple servers and there are millions of user annually management of those becomes very difficult it becomes an headache. Now engineers start to face the problem 15:09 and what are those problem problems like server should run which container what if a container crashes and how do how to scale during high traffic hours and how do you update the application without the downtime and Kubernetes solves all this problem automatically we don't need to do anything these are the default features that Kubernetes comes with it so let's understand what is container orchestration So now let's understand the very important term orchestration. So it sounds very much complicated but the idea is literally very simple. You might have seen the orchestra right just like in the warehouse they does the orchestration like this. Okay. Kubernetes performs the same. So uh what does container orchestration means? Container orchestration means that the containers are automatically managed by the Kubernetes. Right? Automatically management of containers is called orchestration. That's it. Instead of 16:10 human doing the manual task, instead of human handling everything, Kubernetes automates them. Right? So what Kubernetes can do? Kubernetes can deploy the containers automatically. Kubernetes can scale the application automatically. It can restart the failed containers automatically. It can distribute the traffic automatically. It can monitor the application health automatically. Now let's understand with a very simple analogy. Now imagine that doctor is just like driving one car manually. You can control the speed, you can control the direction, you can control the brakes and you can literally control everything. You can even control yourself. Now imagine managing the traffic in an entire city manually. It is impossible, right? Because you can just take care of yourself. You won't be able to take care of many people, right? So that's where Kubernetes comes in. So Kubernetes is just like a smart traffic control system and it it will automatically manage the traffic, the signal, the road routing and it will also manage the emergency handling. 17:12 Similarly, Kubernetes manages the containers at a massive scale. Now what Kubernetes actually does? So you can think Kubernetes is like a very smart managers of yours. It continuously monitors the entire infrastructure and it keeps checking are the containers healthy? uh did any container crashed? Is the traffic increasing or are the server overloaded? Based on this, Kunetics takes automatic actions. Let's take an example to understand. Now, if a traffic suddenly increases, Kubernetes can automatically create one more container. If the traffic decreases, Kubernetes remove the extra containers and save the container, save the resources. Now, here is the most important concept that is desired state management. Now this is the actual heart of Kubernetes. Let's say you want five containers to run every time and Kubernetes treats this as a desired state. Even if one container crashes, one server fails, Kubernetes will be responsible to make sure that the five containers that are desired by the user 18:13 are up and running. Anyhow, it continuously works to maintain the state that you requested and this automation is what's make Kubernetes powerful. Right? So that was all in this video. I hope you understand why we are considering Kubernetes. How Kubernetes is different from Docker. Kubernetes is managing the containers created by Docker and Docker is responsible for creating and running the containers. Right? I hope this gave you the clarity and I will see you in the next one. Next episode is going to be very much important because in the next episode we are going to learn we are going to understand how this Kubernetes works internally and yes we are talking about Kubernetes architecture. Yeah, that was all and I will see you in the next one. Thank you very much. Now that we understand what exactly Kubernetes is, let us do a deep dive into the heart of Kubernetes. And here we are talking about the architecture of Kubernetes. This is one of the most important topic from interview perspective and it is literally very much important for everyone who started the journey with Kubernetes. This video 19:15 is dedicatedly created for all the people who are learning Kubernetes for the very first time and I will make sure that the analogy is very much simpler so that it won't be very much difficult for you to understand. Right? Here we are going to take multiple example that will literally make the cubernetes architecture simplified for you. Right? Don't worry it might look very difficult maybe for the very first time but if you revisit the cubernetes architecture diagram once twice or thrice it will literally make sense for you because here we have covered the cubernetes architecture into a very simplified manner. By the end of this video you will be very much confident and you will be able to create the architecture diagram of Kubernetes by your own end. So yes without further ado let's get started. Let's start by understanding the Kubernetes architecture and by the end of this video you will be very much comfortable with this diagram. I know for starters it might be overwhelming to see this architecture diagram for the very first time. But don't worry this video is exactly created uh in keeping in mind that you are learning this tool 20:15 for the very first time and believe me by the end of this video you will be able to create even wonderful architecture diagram of Kubernetes and the important thing of this video is like uh this is something that has been asked into the interview question. So definitely just look out to this video two to three times and definitely uh you will learn a lot in this video. So if you want to see a simplified version that is also created right. So here we have the cubernetes architecture overview where it has multiple components and that we are about to see right. So instead of going through the diagram that is already been created why not let's create our own cubernetes diagram. So let's get started with it. So uh let's understand whenever we are dealing with Kubernetes architecture there are multiple components which are involved in it right and here you will also get a clarity like how does fit into the Kubernetes architecture right so the first thing first is the cluster what exactly is a cluster cluster is nothing but a bunch of machines that are actually doing the actual job of Kubernetes now it consists of multiple 21:16 components for example here uh let's say we have something called master node. Okay, the brain of Kubernetes. And let me just mark it as green. And here we have one more component that is called worker node. Now master node is also called control plane and worker node is also called as data plane. Right? So let me just mark the label so that it would be easier for us to understand. So this is cluster and within this cluster we have something called this is master node or control plane and let me just move it to the center and then again we have something called over this side and this is nothing but worker node or data plane. Okay. So far so good. Nothing no confusion right. Just imagine 22:17 there is a big cluster and in that cluster we have something called two machines. One one of them is a master node that is the brain of Kubernetes and the another machine is nothing but a worker node or data plane. Right? There can be multiple nodes but for now we are just imagining that we have one master and one right. So this uh what exactly is a master node? Right? So master node is basically a collection of various components that helps us in managing all the codes. Basically it helps us in managing all the health of the cluster right let's go with the component of master first. So I will do a little bit of zoom over here so it would be easier for you to view. Okay let's talk with the first component and that is nothing but API server. So here I'll just add APS server and here I will add the text API server. Now what exactly is the API server? So it just it is a basically the front door for Kubernetes. Now let's say 23:18 there is a client who is making a request from outside. So let's say this is the person who is making the request from outside world. So let me just mark it as yellow that that works. So this is client and the client can access the cubernetes cluster with two modes. So one is CLA and second is graphical. But here mostly we would be dealing with the CLA interface. So let's just think that someone from outside the world is trying to access the Kubernetes cluster. So the very first component that he or she gets interacted with is API server. Now API server as I said it's nothing but the front door of Kubernetes. But the API server acts as the front door of Kubernetes cluster. So every communication that happens within the Kubernetes that actually flows through the API server. So whenever we run any sort of commands let's say cube cuttle get ports cube cuttle get nodes. So these commands are actually been fired through API support. So basically these are what actually API server is. So if 24:19 you want to understand API server just think about APIs. And what are APIs? APIs are nothing but the requests that we make right? get request, post request, right? So likewise, uh what actually API server does, it deals with the request made by the client and it sort of validates the requests, process them and then we can communicate with the other component and like you can think of it like an API server is like a receptionist in the hotel that helps us in receiving the request. It verifies the permission whether this person is authenticated or not. And third it sends the instruction to the right components that is the right department right so uh what will happen if we don't have API server API server is not there basically the entire communication mechanism will break into notice right so here we have the bfest component we talked about that is API server all right now let's move forward with the next one let me again do a zoom and yes we are back now next component over here is 25:21 HCD. E T C D and what actually is HCD? Let's break down HCD first. So what exactly is HCD? HCD is nothing but uh the brain of the system, right? The memory of the system. So if you want if you further want to break HCD, what exactly is HCD? So if you remember uh whenever there are any sort of configuration, we store it into /c directory. Likewise here we have a distributed directory called HCD that is actually acts as a brain of the uh cubernetes right which stores all sort of information in key value p right so HCD is a distributed key value database used by kubernetes to store all the cluster information. So it can be the health of the p number of ports that we are storing it can store the details of the ports it can be config map it can be the cluster state. Now what are those thing? These are something that we are going to cover in the later part of the videos. But for now just understand HCD is a database which store all the information regarding the pods that are 26:22 running on the worker node. Right? If FCD is not present basically the cluster will lose all of its memory and then he won't have the details of the pods itself. So HCD is nothing but the hard disk that attached to a computer and it stores the information for the pods. If Kubernetes loses HCD so basically it loses it complete memory because if HCD slots now think of it HCD as in a hard disc uh that is attached to a computer and that has multiple information of the cluster right so let's it had information about the pod will check the HCD it will first see the desired state and then it will recreate the pod so this is the place where all the data of the cluster has been present so that's why HCD are most important component in the kubernetes and that's The reason it's it is said as the memory of Kubernetes if Kubernetes loses the HCD data basically all the information regarding Kubernetes lost right uh then we won't be having the top track of pod like what is the desired state right so all the data rel related to the pods are actually stored in the HCD that two 27:23 within k value pair and second most important thing is backups so that's the reason uh hcd backups are most important uh when it comes to the production environment so here we came across two components of kubernetes is API server that actually handles the communication and HCD that's act as a database that stores all the information of the parts. Now let's talk about scheduleuler right so let me just create a section for scheduleuler now what scheduleuler is so if I want to put it into a single line scheduleuler is nothing but the person who makes the decision scheduleuler is someone who decides uh in which node what sort of port should be run now you might wonder what exactly is a node so node is nothing but a virtual machine a server where you execute your docker images and what exactly is a pod. A pod is nothing but just imagine at uh the lowest possible unit that we have in Kubernetes is a pod and within that pod we actually execute the container. Just like in 28:23 Docker we have the smallest unit as container. Likewise in Kubernetes we have something called pod and within that pod inside that pod we actually run the containers. Right? So whenever a new pod is created the scheduleuler will analyze the CPU availability, the memory usage, the node health and then based on these metrics uh it will select the best worker nodes. Now let's consider there are multiple worker nodes that we have created in the system. Now how do kubernetes know which node is the best node to run that container. Right? So based on this metrics that we have, it selects the best worker node and then it will allocate that node to it. Right? Now think of scheduleuler like a hotel room allocator. And now what it actually does uh it actually checks multiple rooms and the manager uh will then decide uh which guest get which right so similarly scheduleuler uh things intelligently it places the pods on the nodes right now let's move on with the next component and this is the last component in the master node and that is 29:25 nothing but controller manager. So here I will write controller manager. Now controller manager as the name suggest manager. It manages something. So what it manages? It manages the auto healing of the orders. Right? So uh control managers it's a uh component in Kubernetes that actually monitors the cluster and it ensures that the desired states match the actual state. So whenever you are running any container in a port right so basically there is one thing that you will be asked what is the desired state that you want to run the container. See when we were running uh the things with docker it was very difficult for us because we manually were executing the commands right but here in kubernetes you can actually define the number of desired or the number of desired container that you want to run during the runtime. So here you will just define your desired state and here the control manager is actually responsible to maintain that desired state right so let's say for something goes wrong your part crashes so here it 30:26 will be responsible the control manager will be responsible to spin up another part so that it maintains the desired result that you actually wanted right and this is something uh which we can call as selfhealing right so let's take an example so you requested uh three bot replicas and due to some reason due to some spikes or due to some issues uh one part crashed down. So the control manager which actually notice it why because it is monitoring the parts and it will again create a new part and this is something which we call as self right. So think of it as a supervisor that constantly check is everything is running as expected. So that was all about the master node or the control plane. Now let's move to the next section that is the worker node. Right. So in the worker node we have one very important component that actually makes the life easier and here we are talking about nothing but cubelet cublet. So what actually cublets? Cublet is 31:26 nothing but the node agent right. So here cublet basically what it does it is an agent running on every worker node and its job is very much simple. It receives the instruction from API server that is from here and then it ensures that all the containers are running properly and it report the node status and everything back to the control plane the master node and it actually makes that everything runs fines on the worker node. Now think of cublet as the person uh as their team lead who actually manages the job and once everything is done it reports back everything all the report to the manager and that is nothing but the master node we are talking about. So cubelet interacts with container runtime and here there are multiple container runtime that are going to be present. It can be docker, it can be containerd, it can be cryo. Right? For now, just imagine that cublet is someone who actually executes the things in the worker mode. Right? Now let's move forward to the next component and that is nothing but cube proxy. 32:31 Now when we say when we are talking about proxy, what is the first thing that comes into your mind? Yes, we are dealing with network prover here. So you proxy what it does? It handles the network inside the kubernetes. Now let's say there are multiple containers that you're running in a pod. Then who is responsible for the networking? It's nothing but the cube proxy. So cube proxy is responsible for service networking. It is responsible for load balancing. It is responsible for routing the traffic to the pods. Right? So suppose you have multiple pod replicas and what actually cube proxy does over here? Cube proxy will ensure that the all the incoming traffic gets distributed correctly. So it manages the networking rules. uh using IP tables or ipvs. So think of cube proxy as a traffic uh distributing routing rule and that actually helps us in flowing the traffic into distributed pods. Right? And it is responsible for distributing the traffic. So here we have completed with the worker node. So the most important thing that we have in the worker node is cube and cube proxy. And 33:32 third thing that we talked about was the type and here it can be docker or it can be cryo or it can be container right. So let us go back and let me just show you everything that we have created so far. So this is something that we have created. So what we have in the basically we have a cluster and cluster what it does it has two components two machine it has one master and it has one worker node. Master node has API server. Now what API server does API server receive the information from the client. API server acts as a communication barrier that actually helps us in maintaining the communication from the outer world. Now HCD it's it stores the key value pair and it is respon it is actually the brain of Kubernetes. So all the information regarding the parts are actually stored over here. Schedule it's responsible to schedule the parts based on the available metrics and control 34:32 manager make sure that that the parts are running fine. Now when we move to worker node we have cublet. Cublet is responsible for doing the job onto the worker node. Cube proxy is responsible for networking. And then we have the runtime environment. And the runtime can be docker cryo or kinetic. For now this theme uh it needs an exeutor that actually runs the docker images. So that is nothing but the runtime environment. So let us take an example. Let us understand what happens when the actual request has been received. So here is the thing. User sends the request to the API server using cubectl and then the API server received the request and then the request goes to HCD. HCD stores the cluster information and then uh scheduleuler selects the best node based on the metrics available. Control manager make sure that the desired state is matched that is let's say if the replica is three that was uh the desired state and it makes sure that those desired states have been maintained then what we have we have cubate that 35:32 actually runs the container on the node and then it is running with the help of the container runtime it can be docker it can be cryo it can be containerd and then finally cube proxy what it does it manages the networking and traffic so that is basically the architecture of cubernetes I when we actually see the cubernetes architecture diagram for the very first time. It becomes very much difficult for a beginner to understand it. Now how do we expand this? So basically it is nothing but let's say right now I just simplified in a very simple manner. But how does actually the scene looks like? I will just copy this entire worker node over here. And here we have see container runtime and here let me copy. So what is the meaning of this? So this 36:33 means nothing. Basically we have a cluster okay which consist of one master node and there are two worker nodes. Right now I just wanted to simplify the things for you so that it makes sense to you. Now if I go back to this diagram now it will make complete sense to you. Now if you see we have all the components that we have been learning so far. We have API server, we have HCD, we have scheduleuler, we have control manager and then what we learned in the worker node. We have publate, pube proxy and the pod which were running right. We usually don't mention the runtime environment because it is already assumed but for now for our understanding we actually add it into the architecture diagram. Right? Now I will take an example and that will literally help you to understand how does the architecture of Kubernetes looks like. So uh let us take the example from here itself. Imagine Kubernetes as a massive hotel where the hotels have multiple components. It can be the manager, the receptionist, the security guard, service room and the maintenance. So all of them work together and that actually uh says that 37:34 the hotels is working fine. Right? So similarly Kubernetes have multiple components. They work together and form a good cloudnative system. Right? So now imagine that a complete futile is equals to a complete Kubernetes cluster. Now when I talk about Kubernetes cluster if you remember Kubernetes cluster just remember uh there are few bunch of servers that are running to do the job right so basically those uh job can be to run the application here in the Kubernetes cluster we have two components the control plane and the worker nodes right now let's focus on the control plane so the first component that we covered was API server and API server imagine it as the receptionist where the guest come and take the information for. So API server is just like the hotel receptionist text and whenever the guest says uh arrives and says uh I need a room the receptionist will handle the request and similarly in bubernetes handles the request the same way here the API server will tell the 38:35 user whether the room are present or not by running the command and the user may run the command cube petal get port cube cube kettle get nodes right so what happens so this request first goes to the API server and then the API server will uh receive the request and then it will verify them and it will send the instruction to the right components and what is the right component at a time and that is nothing but the HCD database. So what is HCD? So just imagine a database where all the information was stored. Now if we talk about hotel analogy so HCD is the database where all the information about the rooms the vacate rooms the which have occupied the room everything is actually present in that database. So now imagine the hotel has a master DB and this database stores which rooms are occupied, guest details, the room status and the reservation. So this is exactly what XCD does. It stores the entire information of the Kubernetes cluster and it actually tells us what pods are running, which nodes are healthy, uh the service configuration and the secrets and configs. So if hotel loses its 39:37 database, the chaos will happen. Similarly, if HCD is lost in Kubernetes cluster, the Kubernetes we use lose is primary and that's the reason it is said uh whenever we are dealing with Kubernetes cluster, a backup of HCD should be kept into the production. Right? Now once HCD tells all the information, the next thing that comes is the scheduleuler. Now scheduleuler it's nothing but the room allocator, right? So now the gets needs a room, right? So who will decide which room to assign? It's nothing but the scheduleuler who does the job. So scheduleuler will check which rooms are available, which room matches the requirement and what which floor has that capacity. So it assigns the best room based on the guest request. Right? So similarly in Kubernetes uh the scheduleuler will decide which worker node should run this part and it checks uh this thing based on the multiple metrics that is it will check the CPU. It will check the memory. It will check the node health. It will check the policies and based on that it will actually place it will run that container and code. Now let's move to 40:38 the next component. The last component in master that is control manager. And control manager is nothing but that supervisor who actually checks whether everything is running fine or not. Control manager is the supervisor that checks everything that everything runs fine. So for example, if there are three housekeeping staff which are actually required but due to some reason there are only two staffs are present then the supervisor will immediately make sure that one housekeeper is attached is present so that the work won't stop and everything is runs fine. That's exactly what control manager does. Suppose you have three pod replicas and one pod uh crashes due to some reason. So the control manager will notice it and it will check the mismatch and it will automatically create a new part itself. And this is nothing but self. So this was all about the control manager. Now let's move to the next section that is worker node. For now just focus on this first box because this is this is something that will give you the clarity. Now what exactly is the worker node? So let's just imagine that each 41:38 node each machine in the worker node represent one floor. So here this box entirely represent one floor. This box represent another floor. So this is floor one. This is floor two. Now let us break down all the components of the worker node. So what exactly is a worker node? It just like a floor where the guest actually stay right. Application doesn't run into the management office. It runs in a dedicated row. Likewise, the pod and the containers runs on the worker node connect with the first worker node and that is nothing but cublet. So what actually cublet does? Cublet is nothing but the floor manager. Now what actually floor manager does? So floor manager uh is just like every hotel has a dedicated floor manager which is responsible. A room should be clean, the guest are comfortable and the services are running properly. So cublet is nothing but a floor manager that is responsible to make sure that all the rooms are clean, all the services are working fine and the guests are satisfied with the thing. Right? Every hotel in every floor there is a 42:39 dedicated floor manager which is responsible for making sure that the guests are comfortable. The rooms are clean and the services are running properly. So likewise in Kubernetes the cublet runs on every worker node and it starts the container it stops the container it reports the health status and it talks with the control plane that is nothing but the master. So it ensures that everything works fine on the node properly. And next finally is the cube proxy. Let's talk about cube proxy. Now what exactly the cube proxy does? Basically it's nothing but a hotel navigation person who actually routes the perfect staff into the perfect room. Say a guest orders the food. So the staff routes the request to the correct kitchen uh or it directs the visitor to the correct room. So that is nothing but the role of cube proxy and similarly cube proxy what it does it manages the networking and traffic uh inside the cubernetes and it is responsible uh that all the requests are reaching to the correct parts right so that exactly proxy does and this is the pod actually the work has been done so let us take 43:41 the full flow of the uh kubernetes that we have done so far so what happens so the guest arrives into the counter and he asks uh do we have one room an API server will check into the HCD. The receptionist will check into the hotel DB whether there are any vacant room or not. Right? Then if there is any vacant room present then it will go to scheduleuler. Now what scheduleuler does? It will actually allocate a dedicated room based on the requirement that has been given by the guest and then it will go to control manager. Now what control manager does it basically it is a supervisor that make sure that the requested services exist and then it goes to the floor manager. And here when we are talking about floor manager we are talking about the cublet. Now what cublet does it prepares the room and it makes sure that all the things are running fine and then it moves to cube proxy. What basically cube proxy does it basically navigates the services so that the services are working fine. It maintains the communication of all the system within the cubernetes cluster and that is exactly how the cubernetes architecture looks like. Now if I go back this will actually make sense to 44:41 you. So when we started it might have looked very overwhelming for few people but now you will actually understand what exactly this architecture diagram is trying to say. So let me explain it one more time. Take the example from this diagram. So when we actually started it might have been it might be overwhelming for few people but now I believe that it is very much easier for anyone to understand. So we have control plane and worker node. Within control plane we have API server, HCD, scheduleuler and control manager. API server basically it is the entry point for all the cluster operation and it validates the request and processes them. Second is the HCD. HCD what it does basically it stores the cluster state and the configuration. It is the source of truth for the entire cluster right it's the brain of the cubernetes. Then we have scheduleuler. It finds the best node for the new pod and it consider the resource policies and constraints based on the requirement that has been given by the given by the client. It makes sure that dedicated no dedicated part has been allocated and 45:41 then we move to control manager. It runs the controller like uh node the replica set and it ensures that the actual uh the desired state matches with the actual state right. Then we move forward with the worker node. Here we have cubate and cube proxy. Cubate works with the container runtime. Now what is container net time? For now just remember container runtime is nothing but docker and it makes sure that the pod are running healthy. Next is qroxy. It handles the networking for services. It implemented rules for the routing traffic. I hope in this video you learned about the Kubernetes architecture. Understanding Kubernetes architecture is very much important for the person who is learning Kubernetes because that actually gives us the idea how does the internal mechanism or the component work together. Right? So yes that was all in this video and I will see you in the next one. Till then keep learning and thank you very much and yes if you have any question do let me know in the discussion section and I will make sure that every doubt has been solved. So yes I will see you in the next one. Thank you. 46:43 Hey everyone, welcome back. So today we are going to install Kubernetes into our instances and this will help us to proceed forward or learning with Kubernetes. But before even we move forward, there is very important question that is like which installation method should we proceed with. Right? In this video we are going to cover top three installation method uh that will help us to install Kubernetes. Right? That is kind, mini cube and qPDM. Right? Now what exactly is kind? What is cube padm and what is mini cube? Let's get started with it. What exactly is kind? So kind is nothing but kubernetes running in docker. So here we are running the kubernetes nodes in docker containers. Now it is actually used for the people who are learning kubernetes. It is used for testing purpose. It gives a very lightweight environment for us to run the cubectl command. So if you are someone who is exploring Kubernetes then you should give it a shot with kind because it will give you the clarity how does kubernetes works and it will give you the hands-on that you actually require. So if you are someone who want to runs the command and see what 47:44 actually happens when you run this cubectl command. So basically kind is something that will help you out with that same right and since it is lightwe it won't consume that much of resources and you can definitely give it a shot with kind mini cube. So mini cube is also another popular option that we have. So it uses docker virtual machines or any virtual machine technologies and it helps us to learn kubernetes and also uh with the help of plugins it helps us to visualize it helps us with the visualization and that is nothing but the kubernetes dashboard. So again if you want to run something into locally then you can prefer mini cube as well. So now I have also executed mini cube into my local system and it works absolutely fine. So yeah, if you are someone who want to run Kubernetes locally into your system, then you can prefer mini cube as well and also due to multiple add-ons that it has such as the dashboard for Kubernetes, it will give you the GUI for you to understand what actually is happening behind the scene. Now comes the final one that is Cubedm. So unlike mini cube and kind here we are not dealing with any virtual machines 48:45 here we are actually dealing with the actual machines, actual servers, right? So here we will be dealing with control plane and worker nodes. And here in this specific demonstration here we will be creating one master and multiple worker nodes. And here uh for our understanding itself I've created multiple scripts that will help us to do the installation faster and that will help us to understand what actually is happening behind the scene. Right? And don't worry everything is documented into the readme file. Just go through it and all the things that are created into the MD file is actually created from the official documentation itself. So you don't need to worry about where the information is coming from. I will request you to before even you start with this video. Go forward with the official documentation. Just go through it. It will give you the clarity then follow the readme.md it will again clear each and everything for you. So right if you want to uh experience production grade setup you can go forward with the cubeadm setup. So just like production here we will have the setup for one master and multiple worker nodes and that is actually important for us to 49:44 understand why we are dealing with cubeadm. Now in this specific video we are going to start with the basic installation with the help of kind then followed by mini cube setup that will be helpful for us to understand how does kubernetes works in local environment and if you are a beginner who want to explore cubernetes you can give it a shot with kind and mini cube and finally we are going to see how does production grade system looks like and that's the reason we are learning cube so by the end of this video you will not only know how does kubernetes works and how to do the installation you will be aware like which setup to use in which sort of environment if you want to go forward with learning development or if you want to go with production you will get a clarity which setup to use in which set of scenarios right and for all the setup that we are going to use we will need docker as an prerequisite for all the three installation method we will need docker so let's start by installing docker and then we are going to proceed forward with the installation for all the three methods however for the installation of docker there is also a script present and that will actually 50:42 make sure all the things are present into our plate right so you don't need to worry about the installation. Everything is present in this video. All you have to do is pay attention and follow the instruction given in the readmd file and then execute the scripts you will get the definite result. And if you face any issue, feel free to ping me. I will be able to help you out with that. So yeah, without further ado, let's get started. Let's start with the installation for Kubernetes. For this specific demonstration purpose, uh we would be using this repository that you will find on my GitHub repository. Feel free to check out. If you go to repository uh one hyphen install kubernetes you will find all the three installation methods that I just told you. First is kind installation, second is mini cube and third is QBDM. And here you will find the documentation for all the installation type. Why you should use it? Uh what uh things does it bring into the plate and what is the purpose of each of them, right? So whenever you are working into local environment and you want to learn Kubernetes for local development, feel free to check out kind installation method and mini cube 51:40 installation method. And if you want to explore and if you want to experience production grade uh environment, feel free to move forward with cubem installation. This specific video will cover all the three installation methods. You don't have to worry and search for the documentation here and there. Everything is present in this single video. Right? So all you have to do is follow along with this video and whatever issue you will face feel free to check out and if you face any issue do let me know in the comments and I will help you out with that. Right? So let's explore the first installation method that is using kind. Uh what exactly is kind? Kind is nothing but kubernetes running in docker and that's something that we are going to use. Now when we should consider kind so whenever you want to experience Kubernetes whenever you want to learn Kubernetes whenever you are a beginner and you want to experience how does Kubernetes works how does the architecture works like so in that case you can make use of kind you can make use of miniQ but you want to make use now let's say if you want to experience production make sure that you're using QVDM for now since we are 52:38 learning make sure that you are following the installation step for kind right going forward we are going to try it with miniq right for this specific specific demonstration purpose we are making use of AWC2 instance and that will be helpful for us for learning Kubernetes right and here whatever commands that we are going to use it is actually coming from the actual information from the documentation itself now if I go to Google and search for client installed Ubuntu here is the first quick start link that you will find you have to open it and here if you click on installation you will find the installation step for client on Linux based environment right now here based on your architecture type you have to install Kubernetes provide the permission and then you have to move it into the bin binary when so whenever you are going to run kind commands it will be easily available for the execution now now this is the command that is present for uh installation of the kind but what is the prerequisite for running the kind you will need docker for installation of the same so here uh I have created the entire documentation 53:40 let me uh walk you through what exactly this uh documentation says so if you scroll Here it says that you will find docker install.sh that is responsible for installing docker into your system and it is responsible for adding your current user into the docker boot. That's it. Now the main thing that is present over here is install.sh that will take care of installing kind into your e2 instance and it will give you complete setup how does kind works on cubernetes. So here what exactly we are doing behind the deck that is something that I have documented over here. Now if you want to understand what is happening behind the scene feel free to check out this documentation because believe me I have made sure that everything is present into a single place so that you don't have to uh like jump through multiple documentation because this is actually created by referring documentation and that will actually help you to understand what exactly is happening behind the deck. Okay. So the first thing is whenever you are installing a kind on kubernetes the first thing is to update the package list and install the available updates 54:40 post that we have we are actually installing docker and that has been taken care by docker install.sh it will enable docker it will start docker service and then finally it will make sure that your user is added to the docker group right and that is something docker install.sh does now following uh what exactly install.sh SH does it actually make sure that it downloads the kind of binary and then based on your architecture it executes it and moves it to the path where it can act as a binary and then we can actually run guide into our server. So this is something that I have taken from the official documentation. If you go over here I have taken the same instructions from the official documentation which I have added into the readme.md file. So everything is actually present over here. You don't have to refer multiple document. One thing before even we move forward uh just one request whenever you are doing any sort of installation make sure that you are actually checking out the official documentation. Now why I am saying so because everything every update changes things and that's the 55:41 reason this MD file is applicable for current setup for current day. So let's say the date today is 30th May 2026 but it won't be applicable in future. That's the reason follow along with this video you will get the clarity what actually needs to be done and make sure that you are following the documentation each and every time. So let's say something got changed in the future. You can just actually refer that documentation update as per this instruction and you will be good to go. Now let's move forward. Now once the installation is done we are going to verify whether the installation is completely done and that that has been done and that will be done with the help of time version. Now post that once kind is installed there is one communicator that we'll need that will help us to run the pods into the system and that is nothing but cubectl. Now we will be installing cubectl that's stable client version. Again this is taken from the official documentation. We are executing it and moving it into the binary. Then we are verifying the cubectl version. Finally we are creating the cluster. Now whenever you are 56:43 installing kind the default behavior of kind is it will just create one control plane but we want to experience the real world scenario and that's the reason we are creating one control plane and two worker nodes and that will give us the clarity how does this the kubernetes works right so here it actually creates a kind config.ml that creates a cluster which has one control plane and two worker node followed by it creates a dev cluster by referring the file named client- config.ml Finally it is verifying the cluster and then we are verifying the nodes. Now once everything is done uh you will be good to go to start with uh kind. Now here one more thing whenever you are dealing with client you have to expose all these ports. So I have already created launch vizard aid where all the ports are exposed. Now since this will be a single short video for the installation I made sure that we are not wasting time on exposing the ports. I have created a single launch vizard aid where all the ports are exposed. Make sure that you are following the documentation. You are exposing all of these post and it will 57:43 be actually helpful for your installation. Right now once everything is done then you will be able to access the service and then then things will be forward for you. Now let's go to EC2 instance and I will go to EC2 and here I will create one instance. So I will click on launch instance and I will launch it without a walk through. I will name it as Dubernetes. And then here make sure that you're selecting the AMI as 2.2. And scroll down the architecture type instead of ARM it should be x86 64bit. Scroll down the instant type should be T2 medium because here it will give you two virtual CPU and 4 GB of memory. Scroll down here you have to create a new key pair. So how do you create a key pair? Click on create new key pair. Write the name of the key pair and then click on create. Now it will download a a pen file. Now that pen file will be useful for the authentications whenever you are using whenever you are taking the SSH. 58:46 So here I already have one pile created. I will make use of Ubuntu local followed by let's keep everything by default and here I will make use of launch vizard 8 the security group. Now what is exactly present? Let me just show you that as well. So let me first select launch vizard 8. And here in the configuration storage make sure that you're making it uh minimum to 25 to 30 GB. So I will mark it as 30 GB for now. And the root volume is of type GP3. Now let us keep everything by default as is and I will click on launch instance. Now here it will prepare our EC2 instance. Meanwhile let me just show you my security group. So security group. So if I go over here, I will show you my launch wizard 8. And here in the inbound rule, I have already made sure that all the necessary ports are required. Now since uh I am using AWS uh instance for multiple instances, but make sure that you are only exposing the ports that are 59:48 required for this demonstration. Right? So proceed forward with the installation for kind. I will go to my EC2 instance and here I will click on connect and I will take the SSH. Now here I have my Now here I have my terminal. I will take the SSH. I am inside downloads where my Ubuntu local pam file is present in the current working directory. I will click on yes. And here uh we are inside the EC2 instance as you can see. Now here I am doing nothing. We are going to make use of the shell script that I have prepared and that will make our life very much easier. So if I go to the repository, if I go to docker install.sh. Let me walk you through what exactly is happening. Here we are installing the packages. Then we are installing docker and then finally we are adding the user to docker group and finally the docker installation is completed. Followed by install.sh. What it does? Basically it is installing kind. It is marking it as an executable. Finally we are moving into binary for the execution. After kind is installed, 1:00:49 we are verifying it. We are installing cubectl which is responsible for the communication within the nodes that is actually helping us to run the things into the worker nodes. When you go inside when you scroll downwards, you will see that is kindig. ML which creates one control plane and two worker node. And finally we are creating a dev cluster followed by we are verifying the cluster. Now once everything is done we are uh actually if you want to delete any cluster by any chance I have added the command for deletion of the same but I won't recommend you to delete it because this is something that uh we are learning for this setup but let's say if something goes wrong you want to delete your cluster let's say you want to increase instead of two worker you want to make sure that there are three workers uh that you want to run so in that case uh you can delete the cluster and you can recreate the cluster right so enough theory let's get started so here I will copy the URL and I will go to my instance. So I will run get clone followed by the repo URL. Okay, here my 1:01:50 instead. So here there is a typo. I will just add G over here. And here it says it does not exist. So now what I will do? I will take a clone of this repository. I will go over here. Click on here. Uh the link is copied. So get clone followed by the repo URL. It is cloning the Kubernetes tutorial repository. Now I will go inside Kubernetes tutorial inside one install Kubernetes and we are making use of kind. That's the reason I will go inside kind installation. Right? When I clear the screen and when I do a long list here you can see there are three files which are present. Right? Redmi.md contains the instruction for all the installation that we have already gone through. The main file that we are referring over here is docker installation.s. sh and install.sh. Let me just mark it as an executable. So, chmod plus x star.sh. Now what it will do? It will mark all the sh file as an executable. When I do a long list, now 1:02:52 you can see the color of docker install.sh and install.sh is changed. Now the first thing that I have to do is I will first install docker into my system. For that what I have done, I just executed the command. Let me just do a little bit zoom over here so it would be visible for you to Okay. So what I did I basically executed the command dot forward/ docker install.sh enter. Now what it is actually doing it is updating the package. It is updating the list. It is upgrading the system followed by it is installing docker into a system and then what it will do it will add the current user that is Ubuntu into the group of docker and finally we are refreshing the docker group so that the entry is populated by this we are making sure that no permission denied issues will occur. So let's say if you're directly uh installing kind at that time uh at a point in time you will face some issue called permission denied. So how do you mitigate that? Basically you just have to add your current user into docker group. A few 1:03:52 people will say uh I have added the user into the docker group but still I'm getting permission denied error. Why? Because your files are not refreshed. So there are two method. First is quickly restart your machine and second is just refresh your docker uh files. Right? So new group docker will actually refresh your uh docker configuration and your user will be listed into the docker group. Right? Now here once the installation is completed we will make sure uh that the kind installation has been started right so let us wait for the installation to get completed I won't pause the video because I want you to go through the entire installation step and let's see if there is any issue that I face going through I will actually record it and help you to troubleshoot but before even I was creating this video I made sure that all the issues will get resolved through the scripts so you don't have to worry about installation because here we are actually present to learn kubernetes not installation right but installation is also a part of learning kubernetes right so that's the reason I have created the shell script that's the reason I have 1:04:52 added the readmd file so for each and every step I am there with you if there is any issue I am there with you helping you out with all the issues that you will face right so once the installation for docker is completed we would proceed forward with installation for kind right so let us wait for some time and one more thing like uh before even we move forward Docker install.sh file is present in all the three subreository. Make sure whenever you are installing each of them. The first thing that you have to execute is installation of docker itself. This instruction is excluding for cubeadm installation because that is a different setup. Right? So docker installation is completed and let me just verify. So docker - version and here you can see docker version is populated and when I do docker ps here it is giving me the output because here we are not facing any permission issues. Now when I do a long list, we are good to start with the installation for kind. And how do I install kind into my system? Just execute install.sh. And then here it will download the binaries for kind for 1:05:53 cubectl. It will execute it and it will actually create a cluster. Right now let's say if you want to change the number of worker nodes where do I make a change? Basically you have to make change into this specific file. If you go to kind installation, if you scroll down over install.sh SH here there is a file that I have created here just add one more rule and it will actually add one more node as a worker and then the configuration will be like one control plane and three worker nodes but we are keeping everything by default that is one control plane and two worker node that is a standard configuration for learning anything now if I go back here what exactly it is doing it is creating the dev cluster now here you don't have to worry about everything because everything is actually created by that script right so whenever you are practicing ing it. You just have to run the docker install.sh followed by install.sh. Make sure you are forking this repository because going forward all the documentation and the notes will be added in this repository. Right? And let's say if you are facing any issue 1:06:54 feel free to add the issue with the error into the description so that I will go through it and I will actually able to help you out with that. Now here one more thing to make sure that is like whenever you are done with the installation done with the execution of the script you will get a output like this but here you have to to see one thing that is in the status it says not ready right so don't worry it is not an error it is it is actually making sure that our nodes are getting ready at the back end so for that what you have to run just run cubectl get nodes enter so cubect htl get nodes and now here you can see all the cluster are ready and here the cluster is of type one control plane and two worker nodes and here depth cluster is the name of the cluster that we have created followed by the nodes. So here we have control plane and here we have worker nodes worker one and worker two right and that is how we have 1:07:55 successfully done the installation of Kubernetes. I hope this first section made sense for you. Now we will proceed forward with the next installation step that is with the help of mini cube. So once everything is done we are going to move forward with the second installation step that is mini cube installation. Now what I will do uh now let's say if your work is done and uh like you want to delete the cluster there is a delete command given into the doc install.sh SH scroll down downwards and here you can actually delete the cluster right and since here we are using now since we are using uh T2.mmedium it will actually give up some amount so make sure once your work is done you're stopping the instance or you or you're terminating the instance now since my work is done I will make sure that the instance is actually terminated so I will go over here and I will terminate the instance because the section one the agenda for section one is completed now I will show you how because the installation for mini cube is done. So let's start with the second installation step and here let me just 1:08:56 terminate my instance and the termination is completed. So now let's move forward and start with the installation for mini cube and that is the second section of this video. Let's move forward with the section two of this video uh where we are going to learn how you can do how you can actually install cubernetes with the help of mini cube. Right. So here you can again follow the readme.md file where all the requirements are mentioned. Again I will directly move forward with the installation step. So the steps remain the same that is the first thing that we will need to install is docker and then finally we are going to install mini cube and then cubectl that will help us to do the navigation that will help us to interact with the worker nodes right. So here we are going to install mini cube. Now from where I have taken this commands again I will just open a new tab mini cube install Ubuntu just search this and I will go with the first link that is mini cube start with Kubernetes and here you can actually start with the uh based on your operating system you can just 1:09:56 select it right now since we are on Linux now based on your architecture type it forward with that and then finally you're going to get this command and that is exactly what I have used in the MD file. So nothing something that I've added from my own and everything has been taken from your documentation itself. Now again whenever you are doing any sort of installation please follow the documentation from the official guides because let's say if some updates come in future you will have the upto-date packages right but for now this package is up to date as per 2026. Now post that uh we are verifying the installation. Finally we are starting the mini cube with the driver named dropper and that's the reason we need docker before even we install mini cube and here we are defining the nodes three. Now here it will give us the clarity that there will be the three nodes that we would be interacting with. Finally we are going to get the node we'll be able to print the cluster information by running the command cube ctl cluster hyperen info. Finally what all ports are required. So whenever you are making the security group make sure all of these ports are exposed right I 1:10:55 already showed you my uh launch visa date that is my security group that is again the same thing that I'm going to use in this specific video right now once everything is done things will be good for us and here we don't even have to worry about the commands because again we have created the shell script that will make our life easier so let us go to the EC2 instance and let me launch a new machine so here I will write mini cube and kubernetes here I will select ami of Ubuntu and I will make sure that the architecture type is x8664 and then and here again it's m make sure it is it it doesn't match the architecture type as arm because there are few packages that does not support ARM architecture type that's the reason we are proceeding with 64-bit of architecture now here EC2 instance type again t2 domedium uh t3 dot medium with two virtual CPU and 4 GB of memory. the key pair again I will make use of Ubuntu local and here I'm going to make use of launch visa 1:11:57 date the security group that I made use of now again if you're not sure for this specific demonstration purpose if you want to make use of security groups and whenever you are creating a new security group you're not sure what port to expose make sure you go to the repository itself and here you scroll all the way to the bottom these are the ports that you have to expose and you're done and you are actually done with the setup for security groups now I will go back again and here in the configuration option I will make it as 25 GBs with GP3 type of root volume and then I will click on launch instance. Now once the instance is launched then we would be very much ready to start with the installation of mini cube in the local EC2 instance and that will make our life easier whenever we are dealing with hubernetes mostly people use mini cube for learning purpose instead of kind. So there are two set of people's u many prefer kind many prefer mini cube might depends upon your use case your machine type right so based on that you can proceed forward with the installation 1:12:58 but personally I felt mini cube very much handy because that actually gave me the complete idea how does kubernetes works so going forward even if you're using mini cube that will definitely help you out in learning kubernetes they're interested in understanding how does kubernetes works how does the application interact what are services and how does kubernetes cluster work together in sync. Right now enough theory I will just go over here and I will just take the SSH with the same temp file which I just created. So I'll go over here and the p file that I'm using is Ubuntu local. I'll click on connect. Click on SSH. Here I will take my SSH 1:13:46 and here I will run get clone followed by the repo we just copy. I will go to Kubernetes report tutorial first installation Kubernetes and the second method is Kubernetes installer mini cube. Here I will just do a little bit of zoom out and when I do a long list you can see there are three puls which are present again a readme.md file where all the instructions are written. Secondly is docker install.sh and third is install.sh. First thing that I will have to do is I will in it is installing docker system. There is one more thing that I want extension.sh. If you even follow the documentation which are mentioned into the MD file of uh inside the repository itself, it will literally help you uh to install mini cube as it is as it is doing with the help of scripts because after this documentation was completed. I created those scripts so that like it will save our time. But if you are someone who want to understand what all commands are run and if I want to run each command manually just to see how does and what does the 1:14:46 system refers to what sort of output will I get feel free to follow the readme.md file everything is tried and tested you can actually go and then you can perform the installation manually by following the documentation itself and I would recommend you to just practice each and everything once twice and thrice and that will give you the clarity how those things are working even if it is installation even if it is a single command. If you are running those things multiple times, that will give you the clarity based on the errors that you will face that will actually add into your experience. Right? So here uh once the installation for docker is completed, we will proceed forward with installation of mini cube. Now what is exactly present in mini cube? If I go to install.sh here you can see it is first installing cubectl. Now what exactly is cubectl? We are already aware of it. Then finally we are verifying the version and then finally we are installing mini cube. We are verifying the version of mini cube. Then we are starting mini cube uh with the uh driver docker and here we are making sure that there are three nodes which are running. 1:15:47 If I go over here once the installation for docker is completed we will proceed forward with the mini cube installation. All right. So let's wait for the installation for docker to get completed and then we are going to install mini cube. All right. So here we go. Okay. Now Docker is installed. Let me clear the screen and I run docker version. Here docker is installed. And when I do docker ps here it it states that our user the current user ubuntu is added into the group of docker. Let me clear everything. And when I do long list I will run install.sh this time because that is something that will install cube cubectl. and mini cube into my system and once the installation is completed it will make sure that my cubernetes cluster is created with the help of mini cube and there are three nodes which are currently present. So once the download 1:16:48 is completed it will move it into the binary section so that it will act as an executable and finally our cluster will be ready and we will be able to run kubernetes to our server and that will make our life very much easier. Basically what exactly it is doing it will pull multiple images and here you can see there are two CPU that is that it is utilizing and that's the reason whenever we are booting any sort of EC2 instance make sure at least you are uh using T3.mmedium because here we are because there we are getting two virtual CPU along with 4 GB of uh memory right so here uh that's the reason uh we are choosing that sort of architecture right um now one more thing like should we proceed with the free tier account. Well, definitely you can try but uh like it won't give you that much output because uh being into free tier account it will uh lag your system in at a point in time. So better uh go with the upgraded plan because if it is learning 1:17:49 then uh you can definitely spend some amount and like when you spend some amount I believe like you will actually focus more into that thing because something is going out from your pocket right so if you want to learn seriously then definitely go with the upgraded plan of AWS right and secondly if you don't want to spend no worries uh you can install mini cube into your local and it will work fine as it is working right now over here right all you have to do is just install docker desktop And you can uh do the setup for mini cube. How do you do it? Basically go to Google and search for mini cube download. And here uh go to the mini cube start kubernetes the first result and here based on your setup now let's say if you're on Mac OS select your architecture type and then you can just download the binary. If you want to install it with homebrew you can click on homerew and it will give you the package for homerew. And if you want to download a package uh just like you install any sort of uh application into Mac, you can just click on download and your work will get started. But again, if you are into Windows, then click over 1:18:50 here and here it will give you a .exe file and that will help you to run mini cube into your Windows machine. Right. But I will request you to run everything into Linux environment because there are two reason. First is your Linux experience will add on to maximum people into enterprise users Linux and that will give you the hands-on. I personally would request you to like go forward with the uh instances because that will give you the production grade experience and that will actually help you to learn Kubernetes. Now if you go over here you can see it says that mini cube is ready when I run one second. Let me just clear the screen. uh cubectl get nodes and here if you remember we mentioned that we want three nodes and when I run the command here we have three nodes which are present out of which one is control plane and we can mark the other two as worker node so here we are done with the second setup that is completed and that is nothing but for mini cube now let's start with this third section the third module 1:19:51 where we are going to proceed forward with the third installation step that will give us the production grade experience experience and that is nothing but with the help of cubedm to start with the section number three. Now if you want to experience how does a production looks like whenever we are dealing with cubernetes then you can proceed forward with cubedm installation. Now again follow the same repository uh in the sub repository number three you will find the entire documentation. Now the specialtity of this specific one is you can even try it with the free tier uh machine types and uh I already have performed the same with T3 small and T3 medium and it works really fine and the best part of this uh cluster setup is you can even uh perform it with multiple number of worker nodes. First is I already tried it with one master and two worker node but since we have been doing it as a standard configuration this time we would be doing it as with one master and three worker nodes and that is something that will help us to understand how does cubem works. Now here the architecture will look like as one master with multiple worker nodes. Now the AWS 1:20:53 configuration where I have already tested the script is it works fine on T3 small and T3 medium. And these are the configuration that you have to make sure whenever you're dealing with it, right? But still I would suggest you to go with T3 medium because that is something that will give you a good experience when you're dealing with Kubernetes. Now again with the security group make sure that all of the mentioned ports are exposed and then we are good to start with the installation. Now again if I open the master node setup what actually is happening behind the scene. I've added one uh line over here. Uh so basically what this expression does whenever the script gets any sort of error it exists with uh error code and it actually helps us to exit from that specific point. Secondly we are uh we are setting the host name for the machine to identify uh the master node. Second is we are disabling the swap and that is actually needed whenever we are dealing with cubem. Now simum how do you actually know when do we turn on the swap and when do we turn off the swap. So again I am making use of the official documentation. So if I write cube adm 1:21:54 install on Ubuntu here the first result that you will get is from cubernetes.io and there itself it is written that you have to turn on this swap so that the cubeadm can actually work and here it says the swap configuration make sure that you are following everything as it is written. So the script that I have created it is very much flexible and you don't even have to worry about everything because it takes care automatically by itself. Right? So the installation is really very simple and finally we are installing few packages that are actually required. Finally we are installing containerd enabling the system croup and finally we are starting the containerd and then we are adding all the packages into the cubernetes repo and finally the cluster has been initialized and since here we are making use of qdm we need to initialize the repository with qvdm. Then finally we are going to join it with the qbadm comma that is something that we are going to do today. So now let us uh create the configuration for Kubernetes. Let me create the instance for the same. Here I will write it as mastery node and 1:22:56 the number of machines that I will be needing is four and y4 basically I will need one master and three worker node. Even here you can try it with multiple nodes. Now since we have been doing it with the standard configuration that is one master and two worker node. I think that this time we should try it with any number of node. Now again here the AMI that we would be using is2 and if I scroll down here uh you can try it with T3 micro T3 small it's what it works fine but if you want better result make sure you are writing T3 dot medium because again it gives you two virtual CPU with 4 GB of memory and then scroll down after the selection is completed yeah here select the key pair again I will make use of Ubuntu local and Then uh when it comes to security group, I will make use of branch visa date. And here uh you can uh if you're creating a new security group, make sure that the inbound rule follows the set of rules that are mentioned into the readmd. You 1:23:57 have to expose all the in all the all the ports that are mentioned into the reader. MD file so that it will work fine for you. So if I just scroll down, I am just searching for launch visa date and the security group configuration is also done. And make sure in the configuration storage you are marking it as 30 GB of memory with GP3 type of root volume storage. And then finally click on launch instance. And then our work is done. Now at the back end what it will do it will initialize the machine where it will create four machines for us with the configuration as one master and three worker mode. And these are all the machines that we would be using for creating our Kubernetes cluster. and then we will be good to start with Kubernetes itself right now here meantime what I will do I will create four more tabs now here uh I will change the part to downloads because that's the place where all my pam file are stored so CD 1:24:59 downloads and I go over here okay first one is completed. 1:25:28 So now I will go inside the downloads folder. I will do a little bit of zoom because that's the place where all my files are stored. Uh all my pam file are stored. So I will change the path for all of them. So CD downloads again and here I will change the path to CD downloads. Now I will do it parallelly because it will give you the clarity how does things are working right and that's the reason I have created all the four tabs. Don't worry if it creates confusion we are going to mark it with the label so that it will be easier for you to identify which one is master and which one is worker. Right now uh I think the instances are up. I'll go over here and this time I will first configure the master. So the meantime we can do the configuration for the worker. Right? So here I will set the filter to running so that we only focus on the ones which are actually running. Right? So let me just go over here and I will take the SSH to the master node. So connect copy and here I'll paste it to the main 1:26:29 one. Yes. Okay. So, we are inside the master node. Now, let me just first rename it to master. So, this will be called as master tab. And here I will set the default color to say green this time. Okay. So, it would be easier for us to do the identification. Now, let's now here comes the interesting part. I will go to the repository and here we will do the installation for the same. I will go to my repo and here I will run the command get clone followed by the repo. I will go to cubernetes in the first folder and inside here we are going to do the installation with the help of cubeddm that's why I'm inside the third folder when I do a long list here all the sh files are present. So ch + x star.sh and this will make sure that all the files are into execution mode and here I will I'm doing the configuration for master node. So here I will first 1:27:29 run the master node dot setup and enter. And by the time it configures the master 1:27:43 node let us do the SSH for the remaining ones. So I'll go over here and into the instances I'll open it to a new tab. I will uh take the SSH of the worker nodes too. And meantime here we will do the labeling too. so that it will be easier for us to identify which instance is for which worker right so now I'll set the filter to running and we will get all the instances which are currently running over here now let me just rename all my machines so here it will go 1:28:30 Then once again because here is all the files which are currently present. So get clone followed by the repo URL. CD cubernetes one install Kubernetes and three QVD installation ch MOD + XAR dosh and here is the command basically it's the same command that I executed earlier on the master node and here this time instead of running master node setup I will execute worker node setup.sh. So dot forward/worker node setup.sh SH and meantime I will just rename this tab to worker one and I will mark this as blue. Now I will go to other instance and I will take SSH for the and I will go to instances once again and again I will mark this as color blue for our identification. And now I will go to the third machine and here I will again run the SSH to the third one. So I go back 1:29:43 once again I will think and once the SSH is completed I will run the same command in the worker node right and this is actually creating our life easier because here we don't have to worry about doing the configuration manually again and again because the scripts are actually taking care of each and everything. So, Kubernetes tutorial and then final one installation and then third cubed installation chmod plus x star.sh and then finally I will run the worker node setup.sh message. Right? Now, once everything is done, the last thing that is left is to install Docker. Right? And here you can see the next step is written as we need to run the sugu command into the master mode. Right? That can be done. But before even we do that, the first thing that we need to do is to install Docker. >> Enter. So meantime it will install Docker into the system. And here again I will run docker install.sh. And in the third one too uh I will install I will run docker install.sh. So that docker is installed into the root system. Now here 1:30:45 I will rename it as worker- 3 and this will be marked as viewing color for our identification. Now here we have three worker node and one master node. Now here we have that join command that will actually connect our machine into the worker nodes right and before even that here again we will need to install docker right. So yeah now I will go to worker I will press enter and I will go to worker two. Here it is uh waiting for an action. I'll press enter and then here again an action is pending. I'll press enter. Now once everything is done docker will be installed into the system based on the configuration of QBDM. Right now here you can actually uh perform the same into the different type of instance. Right. Since this has already been tested in 2T3 small, you can try the same in 2T3 small. Make sure that you are mentioning this that you are using the configuration as mentioned into the readme. MD file so that you can experience so that you have a good user 1:31:46 experience. Now let us connect the worker 1 2 and 3 with master route. How do we do it? Basically just run the command sudo. Let me first clear the screen so that it could be visible for you. So I will run sudo followed by the command that we copied that is of cubadm join. Now what actually it does basically it will join uh the worker node with the master one right and make sure that all the security groups are the same the common one and it falls into the same VPC right and at the end just write hyphen v equals to five right I will copy this entire command and we paste it into the remaining worker node so that it directly gets connected with the master node and here you can see it says that And here you can see it says certificate signing request was sent to API server and the response was received meaning it is connected to the master node. The cublet was informed of a new secure connection details. Now if I go to 1:32:46 worker two I will need to do the same. I will again oops my bad. I will need to go back again. So I will copy the same sudo command which we just executed over here and I will execute the same command into the worker node 2 and I will again run it into the worker node 3. Now what will happen? It will again connect to the API server uh request will be sent and it will say that the connection request is received. Now you can run cubectl get nodes and the machines will be connected. Now here the work for worker node one, worker node two and worker node 3 is done. Now let us verify whether we are able to see the machines into the master or not. Right? So cubectl get nodes and this time we should be able to see all the instances in in front of us. So it is cubectl cubectl get nodes and here you can see we have a control plane that is master 1:33:47 the current machine and here we have the worker nodes which are connected to it. Now how do you verify whether which machine is what? Basically worker hyphen is followed by an IP address. If I go with 1723112 - 211 it's basically the first worker node. Uh no it's basically the third worker node which got connected. Now if I go to the master and here if I check 172 315 63 it's basically nothing but the first worker node that is 172 315 63. And if I go with the third output that is 172 314161. It's nothing but the second worker node that is 172 314161. Now our work is done. And here it says that all the worker nodes are connected. Now you can close all the tabs. And here you can actually perform all sort of Kubernetes operations from the master node itself. And here it will give you the actual look and feel of production. Right? And that is how we actually completed the installation of Kubernetes with three methods that we saw that is 1:34:49 first is with kind, second is with mini cube and third is with cubed medium. I hope you enjoyed this video. You learned a lot where you can actually install Kubernetes with three different methods. And this is the only video that will guide you to install Kubernetes with all the three available methods. Right? I hope you learned a lot in this video. If you faced any issue, do let me know in the comments. paste the error so that I will able to help you out with it. Right? So yes, that was all and I will see you in the next one. Thank you very much. Hello everyone. So in the previous video we literally saw how we can install Kubernetes into the instances and I am sure that you have installed Kubernetes into the system. Now before even we actually start with the deployment let us take one step back and understand few terms in Kubernetes because understanding those terms will literally help you in understanding Kubernetes in a very better way. Right? In this video we are literally going to understand what actually deployment is, what is replica set, what is services, what is node. Once you have a idea of these 1:35:49 terms learning Kubernetes will definitely be very easy for you. Right? So this video is very important for you and don't worry if those terms don't make sense for you. Just understand what is the purpose of that specific service and why it is used for right so understand those terms and it will literally help you in understanding Kubernetes in a very efficient way. So yeah without further ado let's get started by understanding the terminologies of Kubernetes. So let's start with the Kubernetes terminology. So before even we move forward just wanted to give you an heads up that all the things that we are going to learn today or going forward will be documented in the same repository. So make sure that you are forking it and you are marking it as star so that you will have it in your own GitHub repository in your own GitHub account. So here whatever we are going to discuss today will be documented under second directory that is two - kubernetes terminology and I will make sure that everything is documented in a such a manner that it will act both as a revision material and uh as a point of 1:36:50 reference for you. So let's begin with it. So in order to begin with the terminologies I have actually added all the terms that you will be coming across in the coming video or you might have already heard about it. So I think like this will definitely add value to your learning because let's say in future I am whenever I'm talking about deployment then you should actually have a clarity what deployment actually is and that's the purpose of creating this video right. So to begin with let's start with one of the most important uh term that we have actually came across with and that is nothing but the cubernetes cluster. Now what actually is a cluster? A cubernetes cluster is the complete environment where our application runs. So now if I want to put it into a simpler term, think of it as the company's building. Now that building itself is nothing but the cluster and inside that building you have managers and the employees. Now the managers are called the control plane. Now why managers are called the control plane? Because these are the one who gives the instruction. Right? And here we have the employees who are known as the worker 1:37:50 nodes. Now what actually is a worker node? This is the actual place where the operation has been performed by the control plane. Right? So together they both manage and run our application. So whenever someone says that I have a Kubernetes cluster they're talking about nothing but uh this actual center this actual ecosystem right now let's move forward and here let's talk about node. Now inside inside that cluster we have nodes uh so a node is simply a machine uh it can be a physical server it can be a virtual machine. So there are two sort of nodes that we have in Kubernetes. So one is the brain of the Kubernetes which we call as the control plane and what it does basically decides where application should run and manages the entire cluster. Second is the worker node. So this is where our actual application and the container runs. So if Kubernetes was a restaurant then your control plane would be the manager and the worker node would be the chefs who are actually preparing the food. So I think this analogy will make sense for you whenever 1:38:52 you are dealing with Kubernetes. Now you will have a clear idea what actually is a control plane and what actually is a worker node. Right? Next let's move forward with the next term that is pod. Now let's talk about pod which is one of the fundamental unit in kubernetes. So a pod is the smallest deployable unit in kubernetes. So whenever someone ask what is the smallest deployable unit in kubernetes. So it is not container make sure it is not container it is pod right? So whenever you are telling someone then what's the smallest deployment unit in Kubernetes it is not container it is pod and containers run inside that pod right so a pod can contain one container and it can also contain multiple container but the standard configuration for the pod is nothing but it it should contain only one container. So think of pod just like a house where the containers are the people living inside that house and they share the same address uh like they can easily communicate with each other and whenever the kubernetes runs an 1:39:54 application it runs inside that pod. Now let's move forward with the term called namespace. Now what is a namespace? Now let's say as our cluster grows we need an organization. So that's where the nameace comes into the picture. So a namespace provide a logical separation inside a cluster. Now just imagine it just like having an large apartment building and each floor belongs to a specific team. So for each floor there is a dedicated name. One floor will be for developer, one floor will be for testing and one floor will be for the production. So even though everyone lives in the same building, they remain separated and that separation is done nothing but by the name space itself. So the commons name space that you will come across would be the cube system. It can be development name space. It can be a production name space. Right? Now let's move forward with the workload resources and these are very much essential for us to understand because uh like while when I was learning Kubernetes at that time it was uh like 1:40:55 kind of difficult because I was not even aware of the term and that's the reason I made sure that you won't face that same issue. So let's go with the first one that is nothing but deployment. What does a deployment do? A deployment tells Kubernetes what application to run and how many copies should exist. So for example, if I want three copies of my engineext application, I will define that thing into the deployment file. So if let's say due to some reason uh one of the pod crash down, so the cubernetes is automatically create one new part for me. Deployments are also used for supporting the roll back and the ruling updates. So it means that whenever you want to upgrade any sort of application without downtime, you can easily uh return it to the previous stable version if something goes wrong and if you want to roll up a new update version that can also be done with the help of deployment. Now let's move forward with the next one that is nothing but replica set. So behind every deployment there is one thing that is running at the back end is nothing but the replica set. So a replica set ensures that the desired number of pods are always running. you 1:41:57 want to run three pod every time whenever you are running that application. So due to some reason if any of the part fails so what replic uh what replica set will do it will immediately spin up a new uh port for you and it will actually create a replacement for you. So think of the replica set as the security guard that continues uh that continuously monitor your employees. If uh one of the employee leaves uh the guard will quickly bring another employee to maintain the required count number. So usually uh in the current updated version of Kubernetes we usually do not make use of replica set because uh deployment usually manages them automatically. So you don't have to worry about replica set. But since we are learning Kubernetes we should be aware of the terms and technologies and that's the reason we are making sure that we are adding all the terms over here. Let's move forward with the state pool set. So before we move forward with state pool set let us first understand let us first clear two terminologies. First is stateless and second is stateful. So what are stateless application? So those application which 1:42:58 doesn't require the previous context are known as stateless application. The application that requires the previous context the previous history for the working of the application are called stateful application. The good example for uh stateful application is nothing but the database. So database need a stable identity and persistent storage. So that's where stateful sets come into the picture. Right? So stateful sets are usually used for application and databases like MySQL, post grace, MongoDB, Cassandra and other sort of databases. So unlike deployments, each pod gets a unique identity. Even after restarting the pods, Kubernetes remembers their identity. Think of it as a um think of students in the classroom. So each students have a unique role number. So even if they leave the classroom and even if they come back again their role number will be constant every time. So that's exactly how state pool set works. Now let's move forward with demon set. Now the name itself says 1:44:01 demon. Demon is something in Linux context something running into the background. Right? So sometimes we need the part that uh that is needed to run every time into the back end. So for example it can be your monitoring agent it can be a logging agent or it can be your security scanner. So instead of manually creating the pod on every node, we make use of demon set. So your demon set is nothing but it is a pod that ensure that one copy of pod runs on all the nodes, right? So whenever a new node joins a cluster, Kubernetes will automatically create that pod and you don't even have to create that pod automatically every time because because that will be already defined into the demon set. So it is just like installing antivirus software on all the system uh in an organization right let's move forward into networking and access section where we are going to cover the first and most important thing that is nothing but service so we are already aware that pods are temporary uh the containers are temporary right so their IP changes every time whenever we are 1:45:03 spinning up right so how do the application communicate reliably right here we can make use of services so what service a service will provide a stable network and an endpoint through the group of pod. So instead of connecting that pod directly a application will connect to the services then the service will route the traffic to the correct pod. So think of it just like customer care, phone number. So here the employees can change but the customer will always call the same number. Right? Let's move forward with the cluster IP where we can make use of cluster IP. So cluster IP is used in those conditions where uh the other ports can communicate with it but the external users cannot communicate with it. Imagine the internal company phone extension. Just like that employees can call it but outsiders cannot call it. Now let's move forward with the next one that is nothing but node port. Let's break the term node and port. So a node port exposes the application on a specific port every node. Uh so users can access the application using the node IP plus 1:46:05 the port number. For example 192.168.10 col 30,8. So like that can be something that can be used for accessing that application. So this is useful for testing. It is useful for learning Kubernetes and that's the reason we have added it over here. So think of it just like opening a specific gate into your building for the visitors. Now let's move forward with load balancer. Here we are balancing the load in the pod. That's the reason load balancer. So in cloud environments we usually make use of load balancer services. So when we create load balancer services the cloud the cloud provider automatically creates the external load balancer. uh this load balancer can distribute the traffic amongst the multiple pod that we have created. If one pod becomes busy due to some reason the traffic is sent to other healthy pod. So think of it just like um demart where we have multiple billing counter. If one of the billing counter is occupied then the customers are sent to the other uh billing counter where the customers are not present. So 1:47:06 likewise the load balancer works. Let's talk about ingress. So what exactly is ingress? So imagine you have multiple application uh one for users, one for payments and one for products. So creating multiple load balancer will be an headache and it will be expensive. So here is where ingress comes into the picture and this is where it actually helps. So ingress acts as a smart traffic controller where it routes the incoming traffic to different uh services based on the routes based on the rules that we define. So for example, let's say you have a website called shop.com which is the product uh of uh which is your product where all the customer do the shopping. So what it will do whenever the uh customer goes into the payment section here we will define the route. So for example it will be like navigating to shop.com/payment. So it will be acting as a payment service. Shop.com/ user. So it will be listing all the user services. So ingress makes the application routing simple and efficient and that is one of the power that Kubernetes bring into the 1:48:08 plate. Now let's talk about configurations and secret which is the plus point whenever we are learning Kubernetes. So let's understand the first point that is nothing but config map. So applications of often require configuration. So things like application settings, the environment names or the feature flag. So instead of hard coding these values inside the container, we actually make use of config map. Right? Config map stores the nonsensitive data and the configuration where the pod can actually read those values as an environment variable or the file and think of config map nothing but like a setting file stored outside the application. Right now let's talk about secrets. Now we know how do we handle the environment variable. Now let's take about now let's talk about how do we handle the secrets. So uh secrets are nothing but the sensitive information. It can be your API, it can be your password, it can be your certificates or it can be your database credentials. So we should never store those credential uh directly inside our application code. So Kubernetes provides some one feature and nothing but the secrets. So secret 1:49:09 the sensitive information and it can be injected directly into the pods when needed. So think of secrets as the logged world where only authorized application can access that data. Now let's talk about security and metadata where we would be talking about the security of the application. And here the first thing that we would be covering is arbback. Arbback is nothing but role-based access control. So security is very important in extremely important in Kubernetes. So arbback stands for role based access control. Arbback defines who can do what inside who can do what inside the cluster. For example, developers can deploy the application. Admin can manage the entire cluster. Viewers can only see the resources. So it's similar uh just like assigning different permissions into a company based on the employees profile. Right? Now let's move forward with annotation. So what annotations are? So annotations are the key value pair that are attached to the Kubernetes object. So they store the additional metadatas. What are the metadatas here in this case? It can be the labels, it can be 1:50:10 annotation that are used for selecting or identifying the objects. So instead of providing extra information for example the building details the build details uh the deployment nodes the version information tool specific configuration think of annotations as this take note attached to the object right finally the additional concept that we have that is nothing but a load balancer so we already covered node balances then cluster IP what actually it does so yes that's it for all in this video where we literally covered multiple terms multiple keys that will literally help us in Kubernetes in the coming journey so we literally complet completed almost all the required terms that will make your Kubernetes journey very easy. I hope this video added value to your learning. Don't forget to check out the repository the sub uh repository number two two hyphen cubernetes terminology. Make sure that you are making a copy of it. Make sure that you start this repository so that you have a copy and you will be interact whenever I push any changes it will be present directly to you. So yes, in this video we literally covered all the 1:51:11 terminologies that are uh that will be helpful for you in learning the Kubernetes. So yes, that was all in this video. Let's get started with the Kubernetes journey in the coming video. So yeah, that was all for today and I will see you in the next one. Now you have successfully installed Kubernetes into your system with the help of kind QBDM and mini cube. The current scenario is your cluster is up but the problem is how will you do the communication? How will you see what exactly is running? How will you actually deploy the application? How will you do the troubleshooting? That can be done with the help of cubectl. Now, what exactly is cubectl? If I want to put it into simpler words, just imagine cubectl as a remote controller for cubernetes. Everything that happens in a cubernetes cluster is been done with the help of cubectl. In this video, we are going to literally cover 80 to 90 commands of kubernetes that you will be using as a devops engineer on a daily basis. So without further ado, let's get started with cubectl. Before even we move forward with running the commands, 1:52:12 let us first make sure that your cluster in spinup. Right now I'm making use of mini cube. So once your instance is ready and let's say if you have stopped it after your installation is completed, make sure you are running mini cube start so that your instance is ready and then you can follow along with this video. Now before even we start doing anything, let us make sure that cubectl can talk to our cluster. Now how do I verify that whether cubectl is actually running or not? So for that just run cube cluster - info. Now what exactly it will do? Basically it will uh show the cubernetes API. What this command will do? It will show you the cubernetes API endpoint. And if you're seeing this output then congratulations your cubectl is successfully connected to the cluster and you can actually work with cubectl. Now let me clear the screen. Now how do you verify your nodes? Now as we are already aware that nodes are nothing but the machines that we are talking about. Now we have nodes of type control plane. 1:53:13 We have nodes of type worker plane. Control plane basically uh defines what works needs to be done. And worker nodes is the place where the work has been actually completed and the work has been actually done. Right? So how do we verify? How do we get the list of the nodes? So for that just write cube ctl get nodes and here you can see all the nodes which are present. So here we have a control node and here we have the worker nodes which are currently present. Now if you are someone who is directly jumping to this video I would highly recommend you to go with the installation steps where you will actually find how we how did we created one control plane and two worker nodes for the same and this is actually help you to move forward with the tutorial. However, if you are continuing with the same then don't worry if even if you have a control pen right now uh it will work smoothly because here we are mostly focusing on qctail commands and these commands are 80% commands that you will be using very frequent in your day-to-day job right so uh once the qCl is done uh we know how we can get the 1:54:16 nodes what are nodes nodes are basically the machines on which the operations has been performed right now this actually tells us what nodes are actually available inside the cluster. All you have to do is just run cubectl get nodes and this will list you all the nodes which are available. So what exactly the status ready means? Ready means cubernetes can schedule workloads on these nodes and it can schedule the part so that we can actually see the container running on those specific worker nodes. Right now let me clear the screen and let us go with the very first command that we would be using. So whenever someone learns cubernetes the very first cubectl command that he or she runs is cubectl get let us run cubectl get command right. So cubectl get now this get command is used to fetch multiple information. Now let's say if I want to see uh the parts that are running on my current uh cluster how do I check? So here we are making use of pipsy till get and here I just need to 1:55:17 write the name of the service that I am looking for. So here I'm looking for the ports. When I press enter here it returned me with an output that no resources found in the default name space. Right now we don't have any application running. So that's the reason we are getting this output. So let us deploy a service. Now how do I deploy a service? So for that we need to write manifest. Now Shoubam what exactly is a manifest? So whenever we are working with Kubernetes, whenever we are dealing with Kubernetes, we would be dealing it with the AML files and all the ML files throughout the Kubernetes are known as manifest. Right now since we are yet to touch that topic, let us create a deployment from the commands itself. So that we will be able to experience the commands and we will actually know what does each command does. Right? So let us create a deployment. So how do you create a deployment in kubernetes with the help of command line. So it is very much simpler. So you just have to write q ctl 1:56:18 create followed by the service that you want to create and here we want to create deployment followed by the deployment name. So what is the deployment name? So let us take engineix for example. So here the deployment name is engineix and here I need to pass an image. So that deployment will actually run containers but that container in order to run will need an image right and that's the reason we are passing we are passing hyphen image flag and that will actually help the deployment to run with the image name engineix. Now here you can again specify the tags too. So let me just write engineix latest enter. Now what it says it says deployment.apps/endix apps/ antigenics created right now let us again make use of cubectl get command and here this time it will create ports for us so when I run qctl get pods here you can see we have the pod running the name of the pod is engineix along 1:57:19 with some hash then here it says ready 1/1 here the status is running and we are good to start with it right so what we did created we actually created one deployment ment and that deployment is created with the help of the image called image enginex col. Now that we see the engineext port running the cubectl get command is actually used to list the services right. So let us list the deployment that we have created. So how do we list it? So again we will make use of cubectl get deployment deployments enter and here it says cube command not found. Let me just correct it. So here it will go as cubectl get deployments. And here you can see the deployment that we created earlier. It was by the name engineix and that is the reason here we are getting the name as engineix. Here it says it is already up to date and it is available right and that is the sort of thing that we get that we are already aware of services and in the previous video in the 1:58:20 terminologies we know what actually services mean. Now let's say you want to list the service right you can again actually make use of cubectl get right so again for that you can write cube cl get service basically you can write services and here it will list the service there is another abbreviation that you can make use of that is uh it is a shortand you can even write svc and it will again list the services for you right so here uh c ubectl get is actually used to list all the services right now let's say if you want to list down the nodes you want to see how many nodes are present in my current cluster. How how you can actually list all those nodes? Again, you need to just write cubectl get nodes. Enter. And here it will list down all the nodes which are present in your cluster. Right? So what exactly cubectl uh get does whenever you want uh to list anything any service into your cubernetes cluster you can make use of cubectl get right. So whenever something goes wrong cubectl is usually the very first command that you usually run. Right? Let me clear the screen and now 1:59:22 let's talk about describe. Now let's get detail information about the pod. Now how do I get the detail information of the pod? So here we will make use of cubectl describe right like cubectl get it has a job for listing listing down all the services. Cubectl describe is just used for describing the pods and the services. Now let's get a detailed information of the port. But before that let me just list my part. So cube ctl get ports and here I have my port running. Let me just copy the name. Now let's say if I want a detailed uh information about this. How do I get it? So for that just write cubectl describe followed by what do you want to describe? I want to describe the pod and I need to pass the name of the pod. So cubectl describe pod and followed by pod name. It will actually tell you all the information about that pod. Let me just zoom out so that it would be easier for you. Now this is a very important command and this is actually used for troubleshooting whenever you face any 2:00:23 sort of issues. Now here you can get tons of information. For example, you can see through which image this pod is running. Right? Again here you can see all the events that are that actually happened when the uh pod was running. Even if you scroll down, you can actually get the name of the pod, the name space in which that pod is running. All sort of information are actually mentioned over here. Describe is actually used to get a detail information of that product, right? And the best and the important section whenever we are troubleshooting any sort of Kubernetes issue. The main highlight section over here is the events because eventually tells us what happened when the pod actually started to run. This is one of the most important section in troubleshooting. If parts fails to start cubernetes usually tells you exactly what happened over here right now think of cubectl get it is used to get a summary and cubectl describe it is used to get the full report right let me just 2:01:23 clear the screen and let me just run cubectl get pods once again so that we have the pod listed in front of us okay now let's talk about cubectl lock now we are now we are already aware of cubectl will get cube set described. Now let us move to the logging phases. Right now now let's see if we want to know what is happening inside that container. So here where cubectl logs comes into the picture. Now let me just run cubectl logs followed by the pod name and when I paste it here I will get all the log that is related to this container and these logs help us to understand what happens inside that container. Right? So it basically tells you what happened to the container. For example, it may tell you that the container started then it listens for that code. If anything goes wrong here with that logs, you can actually troubleshoot. When we actually make use of logs, so it is used in those places, it is used in those condition 2:02:24 where let's say an application got crashed, right? So logs are usually the very first place to go and do the investigation, right? So that's the main use of cubectl logs. Now let's move forward with an interesting command and that actually makes the life very much easier. Now if you remember when we were learning docker when we were learning docker at that time we made use of docker exact command. Now for what reason docker exact command is used for it is used to go inside the container and run the commands manually to check and troubleshoot the issues that are happening inside that container. Same thing can be done with the help of kubernetes too. And here we can again make use of cubectl exact right. So let me first list the pod once again. So cubectl get pods and here I have the pod name. Now let's say if I want to go inside this part how will I go? So again here the command is very much simpler straightforward. So cube ctl exact it for interactive terminal followed by the pod name and then I will need to 2:03:26 pass the shell through which I want to go inside it. So here I will pass hyphen space dash and here you can see I'm inside the port when I do ls here I can actually run all the commands that are present. If I run host name it will print the host name for me and this is exactly what we are looking for. Right. Let me just exit. So this command is extremely useful when we want to debug the production issues. Right now let me clear the screen and here let us talk about one of the scenario where we want to uh we are dealing with deployment and due to some reason uh your managers ask you to increase the number of pod right. So uh how do you do it with the command line itself? So it is very much easier when it comes to cubernetes because when you are dealing the same thing with docker you have to do multiple activities but when it comes to cubernetes things are very instant. Now how do we do it? Let's do the hands- on for the same. Now if you remember uh when I do cubectl get it will list all the services. Now here we are talking about deployment. So 2:04:27 let me just write deployment and here you can see there is one deployment which is up and running. Now here it says there is one container which is up and running. Now here your manager asks you to run five ports. How will you make sure to do that? So here is where cubectl edit comes into the picture that will help you to edit the running code and increase and scale up the right. How do you do it? So it is very much easier. So just write cube deployment edit deployment followed by the deployment. And here the deployment name is nothing but engine. When I press enter, there is a huge YAML that comes into the picture. And if you scroll down here, we are looking nothing but for spec section and within that spec section, you will just update this replica account from 1 to 5. Now, if you are wondering what exactly is pack and what exactly is this file, don't worry. We are going to write a YL file from 2:05:28 scratch and believe me by the end of this series, you will be very much confident to write the YML file. You can literally create any sort of Kubernetes services by your own. You don't need any sort of help. Right? And that's the beauty of learning everything from the scratch because you don't have to worry about each and everything. Right? For now here this video is just for demonstrating what is the power of cubectl because that is something that you would be using on a day-to-day basis. Right? Let me just press escape wq. And if you remember when we executed ubectl get deployment here it says ready 1/1. And when we executed cubectl get pods at that time only one pod was running right now what will happen if I just run cubectl get pods here this time you can see there are five pods which are running now let me just count it 1 2 3 4 5 and that is exactly what we were looking for and 2:06:28 what will happen if I run cubectl get deployment. So here let me run cube ctl get deployments and when I press enter here you can see all the five ports are up and running. Now what if shubam I want to just go back to the previous st and I don't need five ports to be running my work is already done. I just need two port to be up and running. Okay no worries at that time again we will make use of cubectl edit. However mostly in production this sort of action is avoided. We mostly do not use cubectl edit. We mostly make use of the deployment manifest. Now what exactly is manifest in cubernetes? Whatever files, whatever yl we are dealing with, it is nothing but the manifest. This edit command is just for our knowledge purpose that this can this can also be a second option. Now let me just remove the replicas. So instead of five. Now I just want two replicas to be up and running. So here you don't even have to worry about terminating all the remaining things. Kubernetes will take care of it by itself. Now when I do 2:07:29 cubectl get deployments here you can see two containers two pods are running and when I do cubectl get ports here you can see only two pods are running and here it here you can see there were five ports which were running how cool is that we don't have to worry about how what are the things which are happening at the back end everything has been taken care by cubectl itself so here it is immediate you don't have to worry about anything. This is one of the very fastest way to make the changes. Right now we learned about cubectl edit. We learned about cubectl describe. We learned about logs. Now let's go through the manifest. Now I already have one manifest prepared. Let me just run a cat over here. Cube cat deployment. ML. And this is the manifest that we would be referring to. Now what is API version? How do we write this? This is something that we are going to see in the coming videos. But for now just focus on what this uh manifest is capable of. So 2:08:31 basically it will create a deployment by the name my engineix. And here there will be two replicas it is supposed to create. And finally it will be adding a label. The label name would be app engineix. And finally here it will it is going to create a container namex by the image name engineext. Right? And here it would be using enginex latest image. So this is something that this manifest file is supposed to do. Now uh this is something that I was talking about whenever we are working on production we don't usually make use of edit we make use of manifest file and this is nothing but a manifest file right let me clear the screen and I am talking here about the deployment file right and this is nothing but a manifest file now let me just clear the screen so how life becomes very much easier because here you can actually manage each and everything now if you want to see it how can I apply it so basically you can just make use of cubectl L apply - f for the file followed by the file name enter. Now what exactly it will do? It will 2:09:32 apply all the changes which are mentioned in that manifest file. So all the operations which are mentioned into the deployment. ML what actually it does basically it will create a deployment with two ports replicas and the replica will be created with the help of image. When I press enter it will create the deployment by the name my engineix. If I do cube cl get deployments deployments. Uh let me just correct the spelling. Here you can see we have my engineext up and running. Now let me just now let's see if I want to list down all the pods. So I will just write q ctl get pods. And when I list down the pods, here are the two pods that my engineix deployment has actually created. Now let's say if I want to change number of items into this deployment, how would I do that? Just I will run vim into that deployment uh manifest. And then here I will just update into the specs. I will go into 2:10:33 insert mode. And here instead of that replica count as two here I will scale down it with one. SK WQ. Now see in edit whenever you run escape col wq the changes are reflected immediately but here the changes are actually done into the manifest file or if I want to implement those changes don't have to do anything just write cubectl apply - app followed by the file name and here the file name is nothing but deployment deployment.apps/myix apps / my engineix is configured. Now when I say cube ctl get deployment here you can see okay let me just correct the command so when I run cubectl get deployments here you can see the changes are updated we didn't have to do and we didn't have to worry about anything cubectl took care of it by itself right let me list down the parts when I run cube ctl get pods and here 2:11:34 you can There is only one part which is up and running and that's the power of the manifest file. You don't have to worry about it. You can even store this manifest file into GitHub repository so that you will have a track what sort of replica how many replicas are present what labels are been implemented and that is the power of using manifest file. So mostly in production in any sort of environment we usually avoid we usually avoid edit we mostly prefer manifest file. Right now here we learned about cubectl apply. Now let us move forward with the next item that is nothing but deletion. Let's say we have created this resource. Now I want to delete it. How do I delete it? So basically here we will make use of cubectl delete. And how do I perform the deletion? So basically let's say I want to delete the deployment engine. First of all let me just list down all the things. So cubectl get deployment and here I have two deployments. First is engineix and second is my engineix. 2:12:34 Now let's say if I want to delete this deployment, how would I do it? So it is very much simpler just write ql delete deployment followed by the deployment name and here the deployment name is nothing but engineix. Now when you delete a deployment it will delete the ports too. Now let me just verify the same. So cubectl get ports. When I run get ports here you can see the previous engine ports are removed. The only one which is running is the one that we actually created with the manifest file. Now how do I delete a deployment that is created from a manifest file. So that is again the power of using manifest file. Let's say if you want to delete a targeted resource which is created from a specific file that can be done with the help of manifest. How do you do it? Just write cubectl delete deployment delete hyphen f followed by the file name and 2:13:35 here you can provide the name of the resource the resource file through which that resource was created and here what it says here it says deployment.apps apps my -yphen engineix deleted from the default space right now when I do cube ctl get deployments you can see nothing is present over here okay now when I run cube ctl get pods you can see no resources found in the default name space why because deployment itself is deleted then no parts will be present right now what is the hierarchy of this thing is this also we are going to cover in the coming videos but for now just focus on the power of cubectl. These are the commands that we would be using on a day-to-day basis and believe me 80 to 90% of the things will be resolved with the help of cubectl and that's the reason we are dedicatedly focusing on this commands right so this command is basically used to remove the resources from the cluster right what happens into the real world life so let's say you're working as a devops engineer uh and what is the 2:14:37 day-to-day workflow with kubernetes cubectl right so you will first uh check the resources and how do you check the resources basically we will run cubectl get ports ubectl get ports. So this is something that will be used for listing down all the parts that are present. Now let's say if you want to get more details of those part. So how do you do it? Basically you will make use of cubectl describe ports. Right? So let me just create one more uh deployment for you so that it would be easier for me to explain you so that you can go through the day-to-day thing uh with cubectl right. So cube cpl apply - app followed by the manifest file and here the manifest file is deployment. So here let me just correct this spelling it is cubectl instead of cube clubectl. Okay enter and here my deployment is created. Yeah. So uh whenever you are dealing with kubernetes so these are the commands that you will be mostly using into day-to-day life. The first way is nothing but to check the resources. And 2:15:38 how do you check the resources? basically you will make is of get. So the first thing that you will be checking is the parts. So how do you get the list of parts? So just write cube ctl get pods enter and okay I again make the mistake. Let me just correct the spelling. Okay. And here you can see the pods are up and running. Here we can get the list of all the pods which are running in the default name space. Now if you want more details on this how do you get it? Basically you will make use of cubectl describe. So just write cube ctl describe followed by the service name. Now basically just like what do you want to describe? So just write cubectl describe followed by the pod. So here it's the pod and followed by the pod name and here it will give you the entire detail entire report of the pod. Here you will find events. Here you will find the image it is created. Here you will find the container where here you will find 2:16:38 here you will find the labels here it will find the node where it is actually running. So every detail regarding that part is actually listed with the help of describe right let me just run once again. So cubectl get pods to list the pod. Cubectl describe pods followed by the pod name to list down the detailed report. Then for uh then finally uh let's say you want to list down the logs. Now let's say you want to see the logs of the pods. How do you do it? Basically just write cubectl cubectl logs followed by the log name. uh the pod name and what's the pod name over here. I'll just copy it from here and here it will get me all the logs. So all the events that are happened inside that pod will be noted down into that logs. And let's say if you want to do a deep troubleshooting and you want to go inside that container, you will make use of exac. And how do you go inside a container? Just write cubectl 2:17:38 cubectl exact. So it is very similar to docker exec command where we make use of docker exact id followed by the container name and followed by /bin/bash. Here we are passing hyphen bash for the flag and that will actually define the shell through which we are going to login. Right? So here I will write docker cubectl exact id followed by the pod name and followed by the shell through which I want to go inside. And here the shell that I will be using is nothing but bash. And here you can see I'm inside the uh container. And now let me just go uh get out from it. Uh let me just get let me just do exit from it. Right now let's say if I want to uh deploy changes from a manifest file, you will use nothing but cubectl apply cubectl apply command. For that you will need the one one and only thing that is nothing but the deployment file. And how to create a deployment file? That is something that we are going to see in the coming video. But for now let's say if you want to apply any sort of service file any sort of resource file in Kubernetes you will make use of cubectl 2:18:40 apply utility right and if you want to remove any sort of resources how we will do how you will do it basically you will make use of cubit delete and if it is something that is coming through a manifest it is again a very lifesaver for us just run cubectl delete hyphen f followed by the resource file name and here the resource file is name is nothing but the deployment so here I will write d delete f deployment.ml. So I need to again correct the command. So cubectl instead of cube clubectl delete hyphen fav deployment.ml and here it deleted the resources from my default uh name space. Right? So that is something that we have been learning so far and these are the commands that alone covers 80% of your day-to-day task when it comes to cubernetes. So congratulations now you have the complete knowledge of cubectl that will literally help you in your day-to-day uh task with cubernetes we actually know what cube cubectl get is what describe does what log does what is the use of 2:19:41 exact what is use of edit why we are not considering edit why we are moving into manifest we know what how does cubectl apply work what is the use case of cubectl delete so that is something that we have been learning so far as a summary as a revision material I have documented everything into the readme.md file. All you have to do is just go to my repository and in the sub repository number three that is 3 - cubectl cubernetes you will file everything documented over here. So here it will tell you what exactly is cube cubectl that is something which we saw cubectl is nothing but a remote controller through which we can actually perform any sort of operation inside the cluster right and what sort of operations can be done with the help of cubectl here I have shown you what where does cubectl lies in a graphical manner then how you can verify the cubectl connectivity everything is documented over here all I want you to do is just go through this documentation this will literally help you to strengthen your knowledge pities and also So one more thing if you're worrying about the deployment file that 2:20:41 is also present over here if I scroll all the way to the bottom all you have to do is just create a deployment uh from all the operations which I have showed you. So it would be very much easier for you to perform. So once you perform you will get more clarity how things are actually working. Believe me learning Kubernetes can be easy if you learn it with a very sequential manner. Right? So yeah that was all about this video where we literally covered 80 to 90% of day-to-day task when it comes to cubernetes which we actually perform with the help of cubectl commands right so this is just the starting we are we literally started our journey with cubernetes and this is something a very big achievement for each and every one of us right so that was all in this video and I will see you in the next one thank you very much if you face any issue do let me know in the comments and I will definitely help you out with that right so yeah that was all and I will see you in the next Hey everyone, welcome back. So in the previous video we learned and have we have gone through the cube cutle commands. We now know what exactly is 2:21:42 cubernetes, how does it works, why it was created and how cubernetes architecture works. Right? Today we are going to learn one of the most important concept in Kubernetes and that is nothing but pods. Till now you might have been hearing this term from me a very long time. We were talking about pods. We were talking about containers and that's the reason I really wanted to create a video on pods. Right? So if you understand pods properly then uh believe me uh deployments, replica sets, stateful sets, services and everything will become very much easier for you to understand. Right? Because this is something that most of people uh most of the people ignore while they are learning. That's the reason here we are there to strengthen your foundation. Okay. So, yep, let's get started with a very simple question and that is is and that is what problems do p solve and why we are learning it. So, uh before 2:22:42 Kubernetes existed uh developers was simply deploying the containers. Now let's consider that uh I have 10 servers and on those uh server I am running hundreds or maybe thousands of containers. Now the question will start appearing which container is running on which machine which port is been used by which container and what happens if a container crashes and how will they communicate with each other and the last thing is how do I scale them when I am managing it manually and think of it like that your company expands and it generate huge businesses and due to which the infra infrastructure will grow. So in that case managing the individual container will become very much difficult right and that is exactly where Kubernetes introduced this topic called pod right 2:23:44 and exactly uh that is the reason why we are considering it today. So yeah what is this pod thing called? We are going to discuss it today. So think of pods as a way of managing the containers efficiently. Right? Now I know this statement is uh something that will not give you the idea. So let's first discuss what exactly is a pod. Okay. So when uh someone ask you in the interview that tell me what do you understand by a pod? Most of us literally most of us will say a pod is the simplest deployable unit in Kubernetes. And basically it is correct but it doesn't really help us to understand the parts. Okay. So you can definitely give this answer into the interview but for our understanding let us even break down the statement right because this has been said by hundreds of people but let's understand it a very better way and let's think about this right. A pod is nothing but it is a wrapper around 2:24:45 one or more container. Right? So uh you can just think of it like a pod just like a matchbox and the containers are like the sticks which are inside that pod right so Kubernetes does not deploy the container automatically okay Kubernetes doesn't deploy the containers directly instead the containers goes inside the pods and then Kubernetes deploy the pod if you can see this diagram so here in this pod we have this container inside it right so whenever you create any application in Kubernetes the Kubernetes will first create the pod and then it will place your container inside it and that is why pods are considered as the smallest deployable unit I hope now this statement will make sense to you right so uh all right you might have one question that okay we are learning about pod and pod is nothing 2:25:46 but a wrapper around the container. Why we are not directly deploying the containers? Right? So if containers already exist then why do we ever need pod? Right? So answer directly lies in the management right. So imagine Kubernetes has to manage thousands of container individually. So in that case uh there might be the challenges that may cause port conflicts between the container. It may uh create issue for the networking. It may create the issue with service discovery. It may create issue with the communication between the containers. Uh and finally it may create issue with the scaling of the application. Right? Due to this reason uh like it becomes very much difficult and that's the reason uh we do not consider uh containers directly. So instead of this uh Kubernetes group uh everything together inside something called pod and manages the pod as a single unit. And this makes the entire system much simpler and more scalable. 2:26:49 Right? So now I hope you got the answer why we are considering pods over container. And here we understood what exactly is pod. Now let us discuss about the architecture of pod. Okay. You can directly uh focus your area into this diagram so that it will give you the complete idea. Right. Now let's look at the architecture as shown on the screen. So here we have a pod pod A, pod B and pod C. In pod A we have engineix container. Pod B we have springboard application. P C we have a Python application. Right now you can think this entire node as a house and the pods are the rooms inside those house and each room contains an application engine python and springboard. So the important thing to remember is that pods are isolated from each other and every pod gets its own right and due to this reason uh due to this isolation uh like this is what makes cubernetes networking so powerful and that's the reason why we are considering pods in the very first. 2:27:52 Now that you understand the architecture of pods, now it might literally help you to visualize things why we are considering pods and why not we are managing individual containers. Right now here since we are talking about uh communication let's talk about the networking and here let's talk about the pod IP address. And don't worry if you are seeing this text so much. I deliberately have added it so that by the end of this video when you are revisiting the MD file it will definitely help you to understand it in a very different manner. Right? And that's the reason just watch this video post that go to my GitHub repository in sub repository number four. you will find this uh radiator MD just read it will be a perfect revision material and after this I don't think so you will ever need uh to understand pod because this is something that will finally stick into your mind right keeping those thing in mind will definitely help you out to understand pod and move forward with your journey with kubernetes okay so we were discussing about pod uh the 2:28:55 IP address so one of the most important concepts about pod is that every pod gets its own IP address, right? So, let's say we have uh three pods, pod A, pod B, and pod C, right? Each pod is running on on port number 8,000. Normally, this would create an conflict. But Kubernetes solve this problem. Why? Because each pod has a unique IP. So, pod A have the IP address 10.1.0.5. Pod B have the IP address 10.1.0.6. Pod C have the IP address of 10.10. 1 0 0.7 since every pod has different IP address all of them can safely run the application on the same port. So this is one of the biggest reason why pod exist right now let's talk about single container pod right now if you are aware uh in the beginning itself I told you that pod is a wrapper within which we can run a single container or we can run multiple container right so 2:29:56 let's talk about single container pod so mostly in real world production environment most pod are most part mostly contain one container for example example uh your pod can container enginex container it can be a NodeJS container it can be a spring boot container or it can be a python container right so all these uh inside their own pod so in fact if you're looking for most production uh in fact if you look at most of the kubernetes cluster that in production you will find majority of pods are running single container pods right most production application use a single container pod because each pod is responsible of running a single application of service. This follows the principle of keeping the workload isolated, easier to manage and independent to scale. Right? Now let's talk about multicontainer pod. Right? Now let's look into the another side uh and another scenario. Suppose you have a application container and you also need a logger right uh which will 2:30:58 be logging your application logs. So the log container continuously collects logs generated by your application. And since these are the two containers that are tightly coupled, Kubernetes allow us to place them inside the same pod. And this is nothing but called as multicontainer pod. Most containers share the same resources and can communicate very efficiently. As the name suggest multicontainer pod multi means many container and pod. So here in this pod we have multiple containers. That's the reason multicontainer pod. When it comes to single container port meaning in that part there will be only a single container. Right? Now let us come across with a very uh important term which maximum people don't even uh cover in the videos that is nothing but sidecar pattern. Right now what exactly is this side pattern? One of the most important multicluster design uh in kubernetes is sidecar pattern. So you can hear uh this term mostly into interviews or someone who is working into the production 2:31:59 environment. You might have heard about sidecard pattern. So what happens in this sidecard pattern right? So just put a focus on this diagram. Right? So here we have one main application container and there is another helper container. Uh the helper container performs the additional task. Let's take an example. Okay. Uh basically it can collect logs. It can send the metrics. It can perform security scans or it can monitor the application. So the helper container works alongside the main application container. It is just like a sidecar attached to a motorcycle. And that is where exactly this name sidecar comes from. Okay. A helper function, a helper container that helps the main application to function proper. Right? That's the reason we are moving forward. That's the reason we are learning about sidecar. Now let's talk about the communication that happens inside the pod. So this is something really interesting. So containers inside the same pod doesn't need complex 2:33:00 networking. They can simply communicate using local host. Yes, you heard correct. They can simply connect uh they can simply communicate using local host. Why? Because they share the same network name space. They share the same IP address. They share the same network stack. So if container uh if one of the container is exposed on port number 8080. Okay. If any port is exposed on port number AT80 another container in the same port can simply access local host at80. No service required no DNS required no external networking required and this makes the communication extremely far. Now let's talk about pod networking. Okay. So uh here we are talking about the network of inside the same pod uh we use uh local host but when pods need to talk to other pods they either use pod IP address which we just covered or they make use of kubernetes services. So 2:34:01 mostly in production environment we make use of services because pod ips get changed frequently. So we are going to learn about services uh later in the following videos. For now just remember if we want to communicate uh uh within the same pod we can make use of local host. If you want to do the communication from one pod to another we make use of service or pod IP right. So let's move forward and understand about something called pause container. Right? So uh this is one of the coolest concept in Kubernetes. uh something many of you haven't heard about it. So most of the people think containers most of the people only think a pod contains only the application container. But internally Kubernetes create another container first and that hidden container is nothing but the pause container. Now why does this pause container exist? The pause container has a very special job. It creates and 2:35:02 manage the pods network name space. uh you can think of it as the foundation for pods let's say your engineix uh container crashes okay and without a pause container the network name space would disappear the pod IP could be lost and the networking would break but because of this kubernetes can simply restart the application and while keeping the pod networking so pod container acts like uh an anchor that keeps the pod alive right and that's what here we have covered But what does the role of pause container display? So pause container acts like an anchor that keeps the pod alive. This is one of the most beautiful engineering decision which is made inside the cubernet. Now since we are talking about the post container. Let us first understand the life cycle of pod. And here you can actually see how does the pod life cycle looks like. So pods also have different states. The first state is pending. 2:36:02 Okay. It means the Kubernetes has received the pod definition but hasn't started yet. Next comes the running. Okay. So this means that pod is active and the containers are running. Then we have succeeded. So this means the pod uh the pod completed its work successfully. And parallelly we have something called failed status. So which means something went wrong. And finally here in the dot we have something called unknown which means Kubernetes is unable to determine uh what is the current pod state. So whenever you are troubleshooting Kubernetes parts you will check the status first and this is usually the very first thing that you will see and based on these status you will come to know what exactly is the problem. Right. So here we talked about the multiple states and everything is documented over here. Now let's directly jump into the body. Now let's look into this YAML. So everything in the Kubernetes is defined with the help of YAML. And here uh we specify the API version, 2:37:05 the kind, the metadata, the specification, right? So uh we are going to apply this file. So whenever uh Kubernetes reads the AML, it creates the accordingly. So think of YL as a blueprint for your infrastructure. Right now, how do I write this uh YAML file? What is the meaning of API version kind metadata? That is something that we are going to see in the next video. But for now, just imagine uh just understand that uh this YAML is actually a blueprint through which our pods and the remaining services are created in Kubernetes. Okay. Now, let us uh go through a quickly uh quick recap of the commands. So let's say if you want to create a pod so you can make use of cube uh cube cut apply hyphenf pod.mml and inside that pod.ml you have this eml file present right you can also try to do the hands-on in this video and uh you can also do the hands-on parallelly and it would work fine right now let's say if 2:38:06 you want to list down all the parts the commands that you would be using is cube cuttle get ports okay cool now let's say if you want to view detailed information out of it so basically here you will need to describe the pod and here you will be using cube cutter describe pod follow and let's say if you want to view the logs right basically you just need to run the command cube cutter logs followed by the name of the pod and finally if you want to delete a pod which command you will be using you will make use of delete command and that is cube cutter delete pod followed by the pod name and here is the cube reference which you can uh just go through these commands are already covered in the previous video so I think you already have the idea how does the things are working and now since you have a clear idea of how what is pod and what exactly is the meaning of pod. Uh this will actually make sense to you. So before we finish uh let's answer some uh interview questions right. So this is something that will be asked to you and you should actually uh know when you're learning with u pods in kubernetes. So uh the 2:39:08 first thing is uh what is the smallest deployment unit in kubernetes? So definitely pod. Now after this video you definitely have the answer. It's not container, it is pod, right? And next is uh can a pod contain multiple containers? Yes, we already understood about it. A pod can run single container and a pod can also run multiple containers. So yes, it is correct. Do containers inside a pod get separate IPs? No, we already learned about it. How do containers inside a pot communicate? They interact. They communicate with the help of local host. Why is pod container required? Post container is required to maintain the pod networking and name space. Right? So that was all and if you can answer these questions confidently, you are already ahead of many people. Right? So let's revise everything. Uh cubernetes does not deploy container stick directly. It deploys you with the help of pods. Every pod gets its own IP 2:40:12 address. Right? Containers inside the pod communicate using with the help of local host. And then we learned about a part can contain one or more container. And u every pod contains uh a hidden pause container to maintain the networking. Then we came to know about uh if you understand then we came uh around the life cycle of the pods. We came to know about these different states that is pending, running, succeeded, failed and unknown. And finally uh Kubernetes uses pods as this unit for scheduling, scaling, networking and recovery. So yes, if you understand bots properly, the next concept like replica set, demon set, services and stateful set will become very much easier for you. So yes, that was all in this video. I hope you liked the concept of pod and believe me uh like after this video you don't even have to touch anything right just one request from my end go to the readme.md file uh read 2:41:14 everything entirely believe me it will just take 5 to 10 minutes just go through the documentation understand what exactly it is trying to say once you are done with the documentation it will literally help you in clar in uh in the it will literally help you in understanding ports clearly after this video. I don't think so you uh you will have any sort of confusion when it comes with pod and you will be very much confident on the concepts of pod. So yes that was all in this video. Feel free to check out the readme.md and if you have any question please feel free to write down in the comments and discussion section. Yes, that was all and I will see you in the next one. Thank you very much. Hey everyone, if you just completed your journey with Docker and you are just starting your journey with Kubernetes, there is one absolute thing that you have to keep in mind before you start creating the pods, the services, the config map or basically any sort of resources in Kubernetes and that is nothing but YAML. In this video, we are going to learn YAML, not just a 2:42:16 language. We are going to map it with Kubernetes, right? So, if you go to Kubernetes documentation, you might see something like this. And believe me as a beginner it might feel very much intimidating. You might feel what exactly is API version, what is kind, what is metadata and what is the significance of specs. Right? That is something that we are going to see today. By the end of this video, you will be very much comfortable in writing your own YAML files. You will be able to read the ML files. You will be able to create pods with the help of YAML. You will be able to create name spaces with the help of YAML. So instead of copying pasting code blindly from the internet we would be writing our own YAML file. That is something that we are going to look today right. So yeah without further ado let's get started with YAML. So before even we start our journey with YAML let us first understand why Kubernetes prefer YAML in the very first sense. Right now let's say you want to create a pod. Now in order to create a pod what all details you will need. First is the name of the pod. Second is the name of the image through which that 2:43:17 pod will be created. The container that would be running inside that pod. Third is the name of label. Fourth is the volume if it is something that requires a volume usage. Now what exactly are these things called? These are nothing but the configuration. This configuration in Kubernetes needs a format and YAML is that format. Right? Now if you want to understand it a very layman term think of YAML like uh explaining infrastructure in a human readable format. So instead of creating uh things from UI you write YAML file then cubernetes will read those YAML file and create the resources for you and that's the reason we are learning YAML in the very first sense. So yeah I hope that gave you the clarity why we are learning YAML for Kubernetes. So now let's get started with understanding of YAML for Kubernetes. Okay. So let's start with YAML and whatever things that we are going to discuss today will be documented in sub repository number five that is five hyphen YML for Kubernetes. 2:44:18 Right. So here you can see uh before even when we start with YL let us first understand we already are aware that in order to create any sort of resources the recommended method is YAML. We will write that configuration inside that YL file and the resources will be created by Kubernetes for us. But again before even we move forward with that let us first understand how resources can be created in Kubernetes. Are there some another alternative method for creating resources in Kubernetes? Then yes basically we have three sort of methods. First is command method. Second is EML method and third is add that method. Now let's first go through the command method. Now let's say when you want to create uh any sort of small thing or like whenever you're given a very small task like creating a name spaces, you will usually go with command method. Let me just show you how it can be done. Uh I'm clearing my screen and here uh I'll just do a little bit of zoom uh so that it is visible for you. Now let's say if I want to create a new nameace, how will I create? With the help of uh command 2:45:18 method, it will be very much easier. I will write cubectl create namespace. Now I will write the name of the namespace. So here it will be dev. Enter. When I press enter, it will say namespace/dev is created. Meaning the name that we wanted to create is created within a single line itself. So here we don't have to worry about writing the entire Yammer file. Here the name space is taken care by the command method itself. If I want to list the name spaces which are available in my uh device. So I will write q ctl get namespace. You can either write name space also you can also write the small abbreviation that is ns. When you press enter you will get the dev namespace active and basically it's been just 28 seconds that through which it is active. Right now uh let's say if you want to uh run up engine export then how would you do it? Basically with the help of command method again it is a single line command that you would be making use of. So you will be just writing cubectl 2:46:18 run engineix. Now if you want to uh create a pod and if you want to run a p run a pod like run a container inside a pod you will need to give him some sort of image right. So I will write hyphen image equals to engineext. Now what it will do it will take the image from docker hub and it will create a pod for you. When I press enter, it says pod/engineix is created. Now let me clear the screen. And when I do cube, ctl get pods. Here you can see engineix is saying engineix container has been create creating is in under creating mode. And when I do create pods again, it says uh engineix container is running. Right? So that is something that we can do easily and quickly with the help of command method. Now let's go back and here uh let's go with the uh highlight part that is nothing but YAML method. So in real projects we mostly make use of YAML files. Now the question should be why why we are creating YAML itself. Why we are very much emphasizing on YAML. Why? 2:47:19 Because first is version control. Second is it is reusable. Third it is easy to modify. It is easy to share and it can be used in CI/CD pipeline. So this is one of the most important method that we are going to focus on today. That's the reason we are learning YAML today. Now how do we create YAML file that is something that I will tell you after some time but let us focused on the third method that is nothing but edit method. Now we can also modify an existing resource with the help of edit command. So what it will do? It will open the EML of the existing resource and will allow us to edit it in real time. Now let me show you an example. Now here we have a pod name engineext which is running and it is containing the image engineext which is pulled by uh docker up. Now let's say if I want to change some sort of details I will just run cube ctl edit pod followed by the pod name and what's the p name? It's engine x. Enter. Now here you can see 2:48:20 the entire yaml file is created for us. Now don't worry if you don't understand API version kind or metadata uh it's normal uh for beginner it might feel intimidating don't worry that is something that we are going to learning today right uh we are going to understand how these things are created but now just focus on what sort of methods are available to create the resources in kubernetes right now here let's say the containers are created with the help of the image called engineext now let's say I want to use a specific version of engineext right I'll go to docker hub and I will search for engineext dockerhub engineix docker image and here I'll just search for some another versions right so here uh let me go with 1.13 okay so here I am let me just go with the tags itself so it would be easier for me to explain and for you to understand too yeah so here these are the recent tags which are available so I'll just go with uh 1.13- pearl and here we have the docker pull command now here if I go back to my yl 2:49:22 file. Okay, I will go into insert mode and here I will just update that with the current image. If I just remove the previous one. Yep, here you can see I removed engineix and it replaced it with engineix 1.31 -4. Now I will do escape colon 1 second. Now I will just go out from insert mode. And how will I go outside from this? Basically I will press escape colon wq enter enter. Now the thing is whenever you are modifying any sort of resources it will uh uh open a yl file of the existing resources and it will allow us to edit in real time. Meaning whatever changes I did just now meaning whatever uh image changes I did it will be reflected immediately. Now let us verify the same cubectl get ports. It says it is running. Okay. Now let us describe the pod. So cubectl describe pod followed by the pod name. 2:50:24 And what's the name of the pod? The name of pod is engineext. Now here if I scroll down here it says container started. And here if you remember I renamed the image from engineext to engineext colon 1.31- pull. And that's the beauty of uh cubectl edit. But believe me in production in real life we usually avoid uh edit command because that is something uh that we should be cautious why whenever we are dealing with uh uh edit command because if you make any sort of changes by mistake it will be reflected immediately. That's the reason mostly edit command has been avoided. Then what exactly is the recommended thing that most people use and that is nothing but YAML which we are going to learn today. Now let's get started with YL itself. So what exactly is YAML? What is the full form of YAML? So YAML stands for yet another markup language. But on it honestly you don't need to remember that for cubernetes uh just think of YAML as a language to 2:51:24 write the configuration file. Now if you remember at the starting itself I told you that uh whenever you want to create any sort of resources. Now let's say pod all those things which are required for creating the pod are nothing but the configuration that configuration needs some sort of format and yl is the format right so I hope you remember that so let's get started with it let us understand the important concept in yl so the most important concept in yl is key value pair so if you remember if you're coming from Linux uh you usually uh you usually write the variables by key followed by a value so name is equals to shubam. This is something that you write in Linux. But if the same thing that you want to write in YAML, you will write it with the help of colon. You will have to give one space and then you will write your value. Remember YAML is very strict with the indentation. So whenever you are dealing with YAML, you have to follow the indentation. Right? So here the name is key and the value is shup. And let us take an example that will give you the 2:52:26 clarity how does things are working in YAML. I'll go back to Visual Studio Code. I will just minimize this. Okay. And I will create one new file. And here I will write that as first yiml. Now what exactly is yml? Yiml is the extension. Just like in an image we have jpg, we have png the extensions. Likewise in files we have yiml and that yiml indicates as yl value. You can also write yl that will also signifies the same. Now let us say you want to write the name uh you will make use of name colon. Make sure of your uh that you are following a space and you're writing the uh value. So here the name uh is the key and the value is shub. Okay, I'll just zoom it a little bit so that it is visible for you. Now let's say if I want to define my age, I will write age and here age is the key colon and the value is 25. Now what will happen if I just 2:53:27 try 25 directly over here. Now see the best part of IDE why we are considering IDE is in the very first place is because it will give you an error. So if you see this red line it shows that something is wrong. You mention that you're using by ML as the uh as the file which means you are dealing with YL file but again this goes against the rule. You will need to provide one space. when I provide the space that error is gone. Now again now let's let's define one more variable. I will write city. Now let's say uh the city is hydraad. Now since you are again using visual studio code it throw an error and see here in the suggestion itself which says instead of using city colabad there is one thing which is missing that is something that you need to do. I will click over here and here the changes are implemented. That is the reason why we are considering uh YAML why we are considering ID uh my visual studio code 2:54:28 right now if you have worked with Linux before earlier you have seen something very much similar to it. Now let me just write the equivalent for it. So let's say if you want to write something uh like the same in Linux how would you have written that? Basically you would have written name equals to Shubam. So this is how you write variables in Linux. But this is exactly the thing that you write in YAML. Right? Now let's say if you want to uh write age in Linux. So basically how will you write? Basically you will write age equals to 25. And this is how things are working in Linux. Right? The only difference is uh between the colon and the spaces. That's it. Rest everything is the same. I hope that is clear. Right? The most important thing over here is uh if you want to differentiate uh defining variables in Linux and variable in NAML is just a colon and a space. So if you want to uh compare Linux so here I will write for Linux in Linux 2:55:30 you'll write things as name equals to sham which will be very much fine for you. Okay, I'll just mark it as a comment. But again when you are dealing with YAML if you want to write the same thing you will just need to pass YAML colon this equals to has been replaced with a colon you will need to provide one space followed by your variable name and then your things are done. So that is the basic difference between Linux defining variables in Linux and defining variables in YAML. Right? Now let me go back again. Now in few of the files you might see these dashes uh and these are called as starting marker and these three dots are called as ending markers. Although these are not mandatory in most cubernetes file uh but yl provides the start and end markers. Right? So this three dash means the start of the document and this three dot means uh that it is the end of the document. But again it is not 2:56:33 mandatory to define those markers. It is just for your knowledge purpose that these things does exist because in older Kubernetes manifest file if you're working in production. So basically you might find this thing but basically that's the reason I kept this over here so that you will have a clarity you will get an idea why what is the significance and why these things are been used. Right now whenever you are dealing with c uh whenever you are dealing with YAML uh indentation will matter to you. This is where most of the beginners will make mistake because uh in Python indentation matters and the likewise in YAML indentation matters too. Let's take an example. Let me create another file and here I will write second do yiml. This time I will write yl so that you will also get an idea of like there is no difference between yiml and yl. Right? So now let's take an example and here uh what I will do I will just write a user enter. Now let's say uh the name of that user is Raju. Okay. And the age of that 2:57:36 user is age. Age of that user is uh let's say 25. Okay. Now here the name and age belongs to the uh key called user because they are intented. I will just comment it out. Now this thing can also be written in this way but this will be wrong. So I'm telling you what all mistakes we make usually whenever we are writing or whenever we are dealing with yaml for the very first time. So if I write username equals to shub although if I give you uh one thing that if I give one space over here and second is I will write age equals to 25. Okay. So here you can see uh the one thing that is YAML here thinks that user and name and age all are the separate keys. What it does basically it will just give one single uh instruction to YAML that these all fall under the same 2:58:36 lane. But this is not correct. This is wrong. Remove. So that's the reason. Let me delete it. What is the correct syntax of it? Let's say if you want to define a user, you will create a user key and inside that you will give one space. This space is important. This is something that you have to keep in mind. If you want to define a user specifically, you will just uh give one space and then you can just write it accordingly. Now, whatever falls under this user will be treated as these things are intended inside the user. Right? Now YAML thinks that user uh YAML thinks basically name and age belongs to the key named user. Right? Now let us take an example of list in YAML. Okay. Now if uh let's say there is one key which has multiple values. Let me take an example of colors. So this is color. Right? So color can be of multiple colors. So here what I will need to do I will just give one space 2:59:37 one hyphen space name of the color red. There can be multiple color. So I will give one more dash. I will write green. Then I will press enter. I will press one more dash space and I will write blue. This is how you represent a list in YAML. Here the dash means the list of item. So if you want to read it basically you will uh read it like colors contains uh red, green and blue right? Let me give you another example by the names itself. So here we have something called users. Now what all users do we have? We have someone called Raju. We have someone called game. We have someone called u Shubhham. Right? So these are the users. So this is nothing but a simple collection of values. Now let me go back over here. Here we have talked about key value pairs in YAML. Here we talked about list in YAML. This is something that we just saw right now. Now what is what about uh 3:00:39 nested objects? So uh this is something that makes YAML more powerful. Now here you can see we have user, we have name by Raju, age 25 and address as Nakur. So user is now an object. Okay. Inside that user we have name, age and address. Right? Now let us see a nested objects in action. So objects can contain other objects too and that is nothing but nested objects. So nested object inside the nested objects. So here we have something called user. That user contains address, age and name. Right? Now that address contains current address and residence address. Right? And this is something that we call as nesting. So here if you see in a hierarchal view uh user contains name, age, address and groups which falls under the same line and inside that we have address uh within 3:01:41 that address we have current address and address of residence that falls in another line. This is something that we call as uh nested object. Right? Now think of it like folders. I will give you an example. So here is the visualized folder. Right? Here we have one installed cubernetes. Right? So here we have one folder. Inside that folder you have another folder too. And this is something that we call nested. Here you can see user is a folder. Inside that folder we have name, age, address and group. But again in the folder named address you have again two more folders by the name current and residence. I hope that made sense to you. Right now let us talk about variables in lemon. Right? Sometimes you may see something like this. Believe me it looks very much weird when you start learning YAML for the very first time. But again this is something called syntax. This syntax is commonly used in automation tools like uh ensible, helm charts or ginger 3:02:41 templates. So what exactly it means? So when I say user name user.name, it means it fetches value dynamically from somewhere right. So uh let's take the example from here. I'll just uh uh copy it over here and let me just paste it over here so that it will give you the clear idea. Now let's say uh we have something called this and what if I want to refer the address of residence from this user. How will I do it? Basically you will define it like this. Here if I write uh basically this is something which we call as curly braces. Now here I want to access the residence address. How will I access this? You will need to first define the user. So inside user we have something called address and inside that address we have precedence. I hope this made sense. This is called as variables in YAML. So whenever you 3:03:43 want to fetch value from some sort of VML files, you will make use of this sort of syntax. So let us take another example. Now let's say if you want to know the group of that user, how will you do it? Basically, okay, you will write user dot group. Now, why this is correct? Because these all fall under the same lane. Why we entered one more level ahead inside address is because it was a nested condition, right? That's the reason we move forward with it. It was a nested object. That's the reason we wrote one more dot over here. I hope that this made sense. If I click over here, it will give you the idea. This is the user and inside that user we are referring to address and inside that address we are referring to residence. I hope that made sense. Believe me starting uh with YAML might feel difficult, might feel somewhat confusing in the initial itself. But if you practice it, you will definitely get a clear idea how does YAML actually works. By the end of this 3:04:43 video, I will write few comments and I will provide you these files too. So that it will give you the complete idea how things are working. Right. Okay. Now let's move forward. Here we talked about variables in YAML. Now uh let us go forward. Now since we have been working with YAML, you already have the complete idea of the indentation. Now as I mentioned earlier too, indentation is very extremely important in YAML. So parent must be uh written before it. So here the parent is user and the child's name and age. Right? Now let us understand YAML from Kubernetes point of view. Now that we understand YAML, Kubernetes will become very much easier. Now because Kubernetes simply follows YAML, uh there are few keywords that we need to keep in mind. Whenever you are dealing with YAML file, you will be dealing with these keywords for sure. Now understand API version, client, metadata and spec. These are something these four keywords are the heart of almost all Kubernetes YAML 3:05:44 file. This is something that you will find in all Kubernetes file no matter what sort of service it is creating. Right? Let us begin with API version first. Now what exactly is API version? If you see here we have API version v1. Here again another example is API app/vision uh app/v1. So what exactly is API version? API version tells which API version should be used for that specific resources. Now uh basically let's take an example when you want to submit a government form in a government office you need to follow a particular form version right similarly the cubernetes follows a version for creating a specific resources right let's move forward with kind now what exactly is kind actually tells kubernetes what resources you are creating now your kind can be a pod if you want to create a pod you will write the kind as pod if you want to create a deployment, your kind 3:06:45 will change to deployment. If you want to create a namespace, your kind will change to namespace. Right? So kind will tell the Kubernetes what resources that you want to create. You can create pods, you can create deployments, you can create name spaces, services, secrets and config map. So Kubernetes needs to know what objects you want to create and that is something which has been defined by kind itself. Let's move forward with metadata. Now what exactly is metadata? Metadata means data about the data. Now here we have metadata by the name of demo. Okay. So mostly we use metadata to give the identity. So here uh if you remember if you are someone who is coming from AWS, if you're coming from docker itself, we have a very huge advantage uh when you are labeling things. So here that label becomes your metadata. Right? So now you are already a buyer of labels. So let's take an example of labels. Now what exactly are labels? Labels are nothing but tags. So 3:07:47 for example in Instagram you have hashtags. Likewise in Kubernetes you have labels. Right? Now let's move forward with specs. So specs is one of the most important uh section in Kubernetes manifest file. Now uh whenever I am talking about manifest file, I'm talking about the YAML file, right? Okay. So spec means specifications. So this contains the actual configuration right. So for example here the specification says that we want three replicas right the specification can be what containers you are creating the specification can be what ports you will be using. So everything in Kubernetes should be described under the specs right now let us understand about name spaces. Now before we create pod let's understand namespaces. Now imagine uh your company has a development team, a testing team, a production team. So would you want all their resources to be mixed together? Well, definitely not. Right? So 3:08:48 namespaces solve this problem. So what exactly is namespaces? If someone asks you what is a namespace, you can tell them namespace is a logical pattern inside Kubernetes cluster which is used for isolation. It is used for organization. It is used for multi- team environments. Right? Now, how would you check the existing name spaces? So, I will just copy this command. And what this command is cubectl get NS. Now, what exactly NS? NS is this short abbreviation of namespace. So, let me go to Visual Studio Code. And here I will open my terminal. I'll clear my screen and here I will write cubectl get name space or ns. Enter and here you can see all the name spaces which are present over here. Now let us go through the entire name spaces which are given by by default. Let me delete the earlier name spaces which we created before the start of this uh session. So cubectl delete ns and the name of that ns is 3:09:50 dev. This is something that we created at the starting remember. Now let me just clear it so that we will just focus on few services few name services. So cubectl get ns and here you can see we have default we have cube node we have cube public we have cube system and lastly cubernetes dashboard which we can ignore for now. Now let us focus on these four. Okay. So let us focus on the first name space and that is nothing but cube system. Now what exactly is cube system? Cube system is a name space and all cubernetes internal components runs over here. Now if I just want to show you what all components are running over here, I will just run cubectl get pods in the name space cube system enter. So all the things all the internal components are actually mentioned over here. Now since I am 3:10:50 running this on mini cube here you can see ATCD for mini cube we have API server we have control manager we have cube proxy we have scheduleuler and we have core DNS we have storage provisioner so if you want to see the internal components in cubernetes you will mostly make use of cube system namespace right now there was one more thing that we saw in the name space that was nothing but default so what exactly is default namespace Default name space is basically whenever you want to create a resource and you don't want to specify a name space Kubernetes will put it uh in the default name space. So if something let's say if you run cubectl create engineext by the image engineext itself since you didn't mention the name space you didn't told him where to uh create the resource for it will create it into the default name space. I hope that is clear to you. Now let let us move forward with the next one and that is nothing but cube- public. Let me just 3:11:51 run cubectl get name space cubectl get ns. So here we understood about default we understood about cube system. Let us go with cube public. So what exactly cube public contains? Cube public contains uh accessible cluster information. Right now next is cube node lease. Now what is cube node list? It is used internally by Kubernetes for the node hardbeat and the management. Right now let me clear everything and let us go what all things we covered. We covered all the common name space which are present. We understood what is the significance of the same. We understood about this command cubectl get ns which will help us in listing all the name spaces. Right here we we have gone through the cube system name spaces and what it does basically it contains the internal components which we just saw by running the command cubectl get ports n cube system. If you want to decode this command basically we want cubectl to get us all the ports which falls under the 3:12:51 namespace cube system. That's it. It's that much simple. Now let us create the name space with the help of command. Now this is something that we already saw. If you want to create a name space with the help of uh command, you will write cubectl create namespace and followed by the name of that nameace. Right? And again there is another abbreviation for that. If you don't want to write namespace completely, you can also uh define ns and that will give you the idea uh that nameace pro is created. Right? Now let's say if you want to delete that namespace, you will run the command cubectl delete namespace dev. This is something that we have already saw. Now as I promised earlier in this video we are going to create and understand how things are created with the help of a YML manifest file. Start by creating the namespace. What I will do? I will just create a new file nameace do yl or yml. Now whenever you will be dealing with Kubernetes there are four keywords I mentioned earlier that you will see entirely in all the manifest 3:13:53 file and those are nothing but API version kind metadata and last is spec. Okay, we already know what is the significance of the same. uh and when I started my journey with Kubernetes at that time I was very much confused like what version should I use every time right should it be v1 or should it be app/v1 where do I get it from so basically there are two methods first is you go to browser and search for name space in kubernetes and here you will find uh one of the documentation from kubernetes itself if you go over here you will see uh you will get the entire details of the u name space And if I scroll down here uh you will find one YL file too. Okay. Creating a new name space. And here you will see the file is present. Here you will see API version, kind, metadata and name. Right. Spec is 3:14:53 not needed because here we are just creating the name space itself. But the main thing is how will I know which version to use? Here it says v1. But how will I get to know whether v1 to use? First is you can completely trust on document which is completely fine. Secondly is you can find it yourself by running a command cubectl API resources. Okay, let me just correct the typo. It's cubectl API resources. Now what all resources can be created in Kubernetes will be listed in front of you. And this is how you will find four more four important things that is name the short names the API version name space and the kind for us the main thing is name short names and the API version. If you remember at the starting I was telling you whenever I am creating a name space I was writing a short name I was using a small abbreviation and that was nothing but NS 3:15:53 right this is the place where I get the information from. So if you want to get the detail uh if you want to get the idea which uh basically uh version should I use basically you will run the command cubectl API resources. Let me clear the screen. Let me just redefine it once again. Here I'm specifically looking for something called namespace. I will just run grab ns. Here what things we are looking at? We are looking at name spaces. The short name is NS. The version is v1. And that is how you will come to know that which version should you use and as per this we will be making use of v1 that's the reason I wrote v1 over here. Now how do kubernetes know what sort of things what sort of uh service we are creating that's the reason we will be defining the same thing in name space in the client right so I will write namespace now metadata now what exactly is metadata metadata is nothing but data of 3:16:54 data now what would be the name of this name space that is something I will be defining in the metadata itself here after pressing one enter give space. Make sure you are not uh making use of tab. Please refrain using uh tabs because that will give you some issues. Mostly make use of spaces. Single space works fine for us. And even if you want to like give it a readable format, you can make use of double spaces too. Now what would be the name of this name space? I will make this name space as developer. So this would be the name space dedicated to the developer itself. If you want to add some sort of labels, you can add it over here. But for now, we just want to create a name space with the help of YAML file itself. Here specs is not required because we are just creating a name. There is no specification. There is no configuration needed for namespace. That's the reason we removed spec over here. Right now, let me explain you everything. So what exactly API version does? API version 3:17:54 basically tells a Kubernetes API version. What exactly it denotes? It tells Kubernetes that we are creating a service, a resource called namespace. Metadata basically it's the information about the namespace. And what information we need? Basically the name of the namespace and it is nothing but developer. Right now how do I create a namespace from a manifest file? Let me clear the screen and focus on my console. Now here let me just do uh let me just go inside this uh subdirectory. So I am inside the subdirectory 5 and here we have the file called 1 second and here inside that fifth directory uh I will move all the files which we just created and now we have everything under a single place. Yeah. Okay. So the name of the file which we just created is called as namespace.yamel. Right. I explained you everything and now it's finally the 3:18:56 time to see YAML in action. Now, how do I apply these changes from the manifest file? Basically, you have the command called cube cl apply -f. Now, what is hyphen f stands for? Basically, here we are telling cubernetes which file to take care of like so the configuration is written is name in namespace.yamel. That's the reason we root hyphen app followed by the name of file. When I press enter, it says namespace /developer is created. Now let me just verify the same. So cubectl get namespace enter. And here you can see the name space by the name developer is created. Right? And let's say further if I want to make some more changes. Let's say uh in the meta data I need some more changes like I want to get I want to add some labels over here. What I will do? I will just write label over here. Labels. Enter. And since uh we are 3:19:57 dealing with developer and what developer does? Developer does the coding, right? So we added a label called coding. That is something that we want to list. Now how do we list the labels from the created resources? We will just write cubectl get name space - labels. Enter. Now here you can see in the developer name space we are getting something called this. But the problem over here is earlier uh we didn't specified the labels but after that we specified the labels inside it. Why the changes is not reflected over here because whenever you make any sort of changes you need to apply those changes. Now once I apply the change it will be reflected over here. So I will again write cubectl apply - f namespace.yamel. Now here it says YAML configured right earlier it says namespace uh uh now it 3:21:00 says uh developer configured earlier it says developer created right now when I say cubectl get ns the name space will be listed as is there won't be any change but the change would be in when I run cubectl get namespace - show labels enter now here you can see name equals to coding and this is nothing but the label. Now for what labels are used it just for the identification purpose if I put it into a simpler words let's say if you go for shopping in H&M and you want to purchase any sort of jeans in that like inside that jeans you will find one tag that tag will give you the information about that specific jeans the quality of it the brand name right likewise we make use of labels inside the metadata because that will give us more information about it right now let's move forward word and I also told you if you want to understand if you want to find the API version how will you find it you will run cubectl API 3:22:02 resources enter and here you will get the entire list of every resource that you will be dealing with Kubernetes here you will get the name the short name the API version the name space the kind but the main focus for us would be the name short name and the API version this command tells us which resource exist and which API groups they belong to. Now let us go to the documentation and here we understood how a namespace can be created with the help of YAML. We understood what is the meaning of API version, what is kind, what is metadata, uh what is the meaning of labels, why to use it. We understood how we can apply the changes, how we can list the changes, how we can see the labels which has been applied. Right now, if you want to describe your namespace, how will you do it? Basically, you will need to fire a command cubectl describe namespace. And what's the name of the namespace that we created? It's nothing 3:23:03 but developer. So, I will just write the name developer and enter. Now here what you will get? You will get the detail information of that name space. Now here it shows you that the name of that name space is developer. The labels that we are using is name equals to coding name equals to developer and the status is active meaning that name space is now available for us to use. Right now there is one more thing that I wanted to point out that let's say if you want to delete this name space right so when I say long list and if I want to delete this name space with this manif uh manifest file itself how will I do it cubectl delete f namespace doyamel now what it will do it will delete the namespace from the manifest file through which that it was created now this will give us the complete control over the resources. So we won't be accidentally deleting uh the resources that has been created by the manifest file itself. And that's the reason why YAML configuration 3:24:04 is configured as is considered as the best for uh creating resources, managing resources in Kubernetes. Now let's say if you want to create a pod inside that name space, how will you do it? Now let us uh put everything into uh one place and this will give you the complete clarity how things are working. Now let me just create a new file so that it will give you a complete understanding how will you create it. So I will write pyamel and here again I will start it from the very much start from the very much basics and I will also tell you how what will be the approach that you will uh you should follow when you are creating the manifest file. First is API version. uh make sure that the V in API version is in caps. Enter. We will need a kind. Here we will tell what sort of resource we want to create. We will need a metadata. We will give more information and that is and last is the specification where we will tell uh what sort of image what sort of container that we are interested in. Now the first thing is API version. Now how how will I 3:25:06 know uh for uh what version I'm creating the product against? So first thing is we want to create a port that is clear to us. So that is something that we will be defining over here. But how will I get to know that which version to use? Now see since I'm using Visual Studio code, it is giving me the Mets. But if I want to know exactly what sort of uh API version I should use, I will make use of cubectl API resources. I will run a grab for pod. Enter. And here you can see we have v_ub1 and we have a shortand to. So instead of uh using pods, I can make use of po. And for version basically I will make use of v1. So I will give a space and we'll write p1 over here. Now when it comes to port uh what sort of metadata we can give? We can give the name of that part. So name is uh let's say my pod and 3:26:08 namespace. Now see the thing is uh we haven't created a name space so far. Uh we created a namespace named developer earlier. Now let's say we want to create another namespace through it. So that thing again can be defined in this manifest file itself. Here I will write nameace and this time the nameace would be testing. Now comes to the main part that is the specification. when you are creating a pod basically what you want to create you want to create a container so I will just write containers okay now what would be the name of that container and what would be the image that it would be using so here I will give one space I will write the name of that container and the name of that container is nothing but app okay this would be the name of my container but uh what image uh uh should what image should be used right that information where we will be getting it from. So that is something we need to define. So just below name I will define the name 3:27:11 of the image that we would be using. So engineix latest. Okay, this is the image that we would be using. Now in the specification itself if you want to define the ports so that is again possible. So for that container I want to run it under the port called 80. So I will write container port 80. Now here I can say completely that my manifest file is ready because it consists of API version kind metadata and spec. We also followed the indentation because now we know that uh YAML is very much uh strict with the indentation. We didn't made use of any sort of tabs. We were just making use of the spaces itself. Right? And this is one of the important section that we should uh make sure of. Now let us go with the file line by line. So the first thing that we have is the API version. Here we are using uh the core API version that is v1. Secondly is the kind. Here we are telling kubernetes that we are creating a resource and that 3:28:12 resource is nothing but the pod. Now in the metadata we are uh telling them uh the identity information and what sort of identity we are making use of we are making use of name. Uh the name of the pod is iPod and here we also defined the name space. Now what namespace we want to create the pod inside basically uh we want to create a namespace named testing and inside that testing nameace the pod will be created. Now let's move forward with the main specification uh the main keyword that is spec. Spec stands for specification. Here is the actual configuration of our YAML file which consists of containers. Now here we can define the list of containers that we want to create. But for now since we are beginning with YAML uh beginning with Kubernetes for the first time we are just creating the one container. So that container is nothing but the engineix container. Right now what is the name of that container? The name of that container will be app. Okay. And what is the image that it would be utilizing? It 3:29:12 will be utilizing engineix uh latest. So it will tell docker image to uh run and find the image called enginex latest. So if you know docker uh this image field should immediately uh make sense to you. Now next is container port. So basically here uh we we are already aware that engineix runs on port number 80 and that's the reason we define port number 80 over here. Now that our manifest file is ready. Let us see uh the things in action. Let me clear everything. If I run cube cdl get ns here you can see we have these default name spaces present in front of us. Now if I want to apply the changes, how will I do it? Basically I will run cubectl apply f followed by the manifest file that is nothing but p.tml. Now see here it says uh an error. Here it says error from server error while creating the pod. Here it says name spaces testing was not found. So for that you can create a namespace. Right? So I will write cubectl 3:30:14 create namespace and the name space uh would be testing. Now the namespace is created. Now when I run cubectl get ns you can see testing namespace is created. Now in that workground in that playground the pod will be created and inside that pod or engineext container will be running. Right now let me just rerun the command and I will write cubectl apply -f followed by the file name and the name is p.ml. Now here it says pod/myapod is created. First thing that I will be running over here is to list the ports. So cubectl get ports. Now if you see engineix is running but it's from 48 minutes but again we created the pod just right now. Here the catch is we actually created the pod inside the name space called testing. So here there is one more thing that you need to pass hyphen namespace equals to testing. 3:31:16 Now here you can see my pod is running over here and this is the pod where we were actually looking for. Right now there is another way for writing this command in short that is cubectl get pods - n for namespace and the name of the name space it is testing. So you will get the same result right now if you want to get more detail of this uh pod you can just write cubectl uh get pod -0 oite in the name space testing. So here you will get more information about it. Basically you will get the IP you will get the name of the node right so all this information can be uh you can get by the help of hyphenovite right now uh let's say if you want to delete this part then how will you do it so basically there are two method first is command method second is the method right so if you want to delete it with yl you can just write cubect ctl delete f followed by the file name that is 3:32:16 piaml which will directly delete the pod which are created by the file itself which we already are aware of. But second thing that I wanted to tell you uh if you want to delete the same thing with the help of command, you can also perform the same. So if I write cubectl delete pod followed by the name of pod, the name of pod is my pod. When I press enter, it will throw an error. Now remember why it throw this error. It says error from server not found. Pods my pod is not found. Now see again the technicality over here is whenever you are deleting anything whenever you are deleting or creating anything in Kubernetes it will go into default name space but since we created a testing name space over here it is actually uh it is actually it actually wants us to define the name space too right now since we created a nameace and we didn't define over here it didn't find the my pod over there that's the reason it it was not able to delete it when I clear the screen And this time 3:33:17 when I fire the command once again but this time if I uh provide the name space to that is testing here it will search for the name space and once it says yes testing is found then it will delete the pod itself when I press enter it will say pod my pod is deleted from the testing name space right so here the kubernetes reads the request and removes it uh removes the resource right so today we didn't just learn cubern etities uh with didn't just learn YAML we learned what exactly is YAML what are key value pairs what are list objects uh what are nested objects right all the things we have covered and don't worry if you didn't get it in first go you can go through the documentation everything is given in detail so that you can just have a complete idea what all things are present over here we understood about declarative and imperative approach what is imperative approach basically you can just uh run the command directly itself. 3:34:17 Uh what is declarative approach? Basically, you can uh make use of file itself, the manifest itself. Right? We understood about labels and selected. We learned about the main keywords of uh Kubernetes, the building blocks of any uh manifest file, API version, kind metadata and specs. And then finally uh we created the name spaces with the help of command. We created namespace with the help of the manifest file. We created pod inside the name spaces. And we understood how does the flow works like. Now uh since we are able to create these things, you can just follow the examples which are provided over here. This will give you the complete idea how does YAML works with Kubernetes. And if you want to get more examples for the YAML, you can definitely go to Kubernetes documentation and this is the exact place where you can find multiple examples from here. Right? And this will give you a complete idea. How does YAML works? What are the significance of name spaces? What are the meaning of u what 3:35:19 is the importance of API version? How do you find it? So basically the thing is you just need to do hands-on and then only you will get a complete idea how does YAML works, how you can write a complete YAML file, right? So if this video helped you to understand YAML, please share it with the people. So yep that was all in this lecture and I will see you in the next one. Until the next time keep learning and thank you very much. Hey everyone welcome back. So in the previous video we learned about YAML from Kubernetes point of view and by the end of that video we created few manifest file we created name spaces we created pod inside the name spaces. But the question is we could have created the pods directly into the Kubernetes cluster. Why there is a need for name spaces in Kubernetes? In this video we are going to discuss the same. We are not going to just discuss we are going to visualize it because when you have the visualization it will be very much easier for you to understand the concept 3:36:20 of name spaces. By the end of this video you will have the complete clarity on the topic namespace. Why it was created? Why we should consider namespace as a standard setting? why it is used in production, right? And what will happen if you delete namespace that is something that we are going to do today, right? So let's get started with namespaces. All right. So let's say you joined a company and in that company you have one Kubernetes cluster. So let me draw Kubernetes cluster for you. So this will be the cluster that we would be referring to. Okay. So let me just add a label for our reference. So here we mark it as Kubernetes cluster. Okay. So here is the Kubernetes cluster uh for the company for which we are working. Right. So in this Kubernetes cluster there are three teams who will be working. Okay. Let me just name them. So first would be the dev team. Okay. And parallelly there will be few more team who will be working on it. So apart 3:37:21 from dev team there will be a testing team who will be performing the testing on the application and finally there will be the production team who will be working on prod related works. But the scene over here is let's say if someone comes let's say your PM comes let's say someone else comes and say you to deploy an engine pod someone from the dev team wants to deploy an engine pod how will they do it so basically from this point of view they will create a pod let me create a pod. So this is the pod which they have created and let's say this is nothing but an enginex pod. Okay. So someone from the dev team created the enginex part. Now someone comes into the picture and says uh to the testing team to create an engine spot again with the same name through which the dev team have created. Now here the actual issue arise. The cubernetes cluster works in such a way that you cannot create a duplicate named pod. Why? Because it is a unique entity. And that's the reason when someone from testing team tries to 3:38:22 create a part they will get an error. Now I don't want you to show just a pictorial representation. I will show you actually how can be the issue looks like. So I will go to Visual Studio Code and I will just uh run my mini cube by uh typing mini cube start. Okay. And here my mini cube will be up and running within no time. Right. So here the thing is basically we are going to test whether when we are trying to create a multiple pod with the same name whether Kubernetes allows us or not right and here we are considering that we have three teams working together in the same cubernetes cluster that is dev team that is testing team and the production team right now once the cluster is up and running we are trying we are going to create a engine x pod right that is something that we are going to do today once mini cube is up and running then we'll start creating the pod in this Kubernetes cluster. Okay. So as you can see the cluster is up and running. Let me clear the screen. And now let's say I represent the 3:39:24 development team and now I want to create that engineext pod. How will I create that pod? So for that we will make use of cubectl and I want to create a pod. So I will write cubectl run pod followed by the name of the pod and this would be an engineix port. So ng g i nx engine x followed by the image through which that pod will be created and yes this image is nothing but the docker image that I'm talking about. So I will write ngx colon latest enter. I just uh wrote a wrong spelling over here. So like okay don't worry on that we'll just correct it. But again the main concern for us is we want to create a pod and as I represent dev team when I run cubectl get pods. So in the default name space you can see a pod is created right here. It says image pool back off because there is a spelling mistake. Let me correct that. So let me first delete this pod. So cubectl delete pod followed by the pod name and the name of that pod is engineext. 3:40:28 Okay. Uh all right. The name of the pod is actually pod. I'll need to correct that. Okay. So this is uh clear. So I will write cube ctl run engineext from the image engineext colon latest. Okay. So here I'm going to create a pod name engineext with the image engineext latest. So I'll just correct the spelling to it is cubectl not cube ltc. So when I press enter a new pod name engineix is created in the default name space. Now when I want to list this pod, I will run cubectl get pods. Now here you can see our engineix pod is up and running. Now let's say uh right now I was playing a role for someone who is representing the dev team. Now let's say I am someone who is representing the testing team. Now in this same Kubernetes cluster I am again going to try to create a same pod named engineext. Will Kubernetes allow me or 3:41:29 will it throw some sort of error? Let us demonstrate the same. So I will write cubectl run engineext by the name image engineext col. Okay, I am using the exact same image. When I press enter, it's th it throws an error and what it says that pod already exits and that's the reason we are not able to create it. What will happen if I change the tag? Let's say engine x v1 enter. It will again throw that error. No matter what image you use, the pod engine is already present in the default name space and that's the reason we were not able to create another resource in this kubernetes cluster. Now coming back to the visualization this was something that the teams were facing and what was the issue they were not able to create the same name pod. They were not getting that isolation that they wanted to do. The dev team do frequent changes and that's the reason they need a separate isolation from the testing team. Testing 3:42:31 team on contrary do continuously deployment and they do a testing on the develop version. Right? That's the reason they need a separate environment. How do kubernetes provide that isolation and the answer is nothing but namespaces and that's the reason kubernetes implemented and invented namespace concept. Now if you want to understand this in a very layman term, let me just explain this in a very layman term. Right? Now imagine that this pink block is nothing but your big apartment building. In this apartment there are few family who are living right. So right now the families which are residing in that apartment is uh deaf family, test family and the pro family. In that apartment building you have different different floors and in each floor you will have each apartment right. So let's say this apartment belongs to the deaf family this apartment belongs to the testing family and this apartment belongs to the production family. Now here the thing is 3:43:33 each apartment will have their own kitchen. Each apartment will have their own balcony. The main concern over here is they will have their individual independent space. That's the reason name spaces was created. Here I represent the pink block as the cubernetes cluster and the apartment that is marked as yellow is equals to the pod the name space that we are trying to create. Right? I hope this made the sense right. Each family will live in their own apartment. So even though each apartment have the same kitchen, same balcony, they have their independent space, right? And namespace exactly works the same way and that's the reason why namespaces were created. Right? Now let us take an another example. Now let's say you are working in Amazon and in Amazon there are thousands of projects which are working simultaneously. Now what will happen if you try to create all the resources in a same Kubernetes cluster. It will be an headache for us to manage all those 3:44:33 resources. Why? Because there is no isolation. That is the reason in each project whenever you are working in production uh you will get individual name spaces every time and that is why because it becomes very much easier to manage all the name spaces. So that's the reason that's the concept why namespaces came into the picture. Right now let us recreate this scenario but with the help of namespaces. Let me just go back and let me just clear the screen now. And here when I run cubectl get pods you can see there is one port which is running. Let me just delete this port. So I will run cubectl delete pod followed by the pod name and the pod name is nothing but enginex. Now it will delete the uh now it will delete the pod name engineext from the default name space. Now based on this picture what we understood is we need to create different isolation by the name of namespaces. So here what we are going to do we are going to create name spaces for dev team testing team and production 3:45:35 team so that they will have their complete isolation so that whenever the resources are there inside that specific name space the other team may not need to worry about the nomature they can work independently without even thinking about anything. So let me create a new spaces let me create a new name space. So how will I create namespace in cubernetes? So basically it is very much simpler. Now in the previous video we already learned about two methods basically one is the command method and secondly is the manifest method. So basically in that case you will have to create a manifest file and then through that manifest file you can implement the changes. Now let me create the namespace with command method. So what I will do I will run cubectl create namespace followed by the namespace name. So here I will write dev team. So this is the name of the name space that we have created. So this will belong to the development team. Now I will create similar name spaces for the testing team and the pro team. So I will run cubectl 3:46:38 create NS for test team. Enter. Now Shoubam, how do you know whether namespace is equivalent to NS? That's where API resource come into the picture. If you want to know short abbreviation what to use, you may just run cubectl API- resources. Enter. And here you can see all the short forms, all the API version, all the name spaces and all the kinds. This is very much helpful when it comes to create the manifest file. And believe me if you don't want to refer the cubernetes documentation, if you want to refer your console itself, API resource is your to go place is your to go command. Right? Let me clear the screen. Now we have created the name spaces for dev team and the testing team. Now let us create the name spaces for the pro team. So I will run cubectl. Create namespace for prod team. Now the name spaces are created. Now how do I list it? So I will run cubectl 3:47:40 get ns and here you can see name spaces for dev team, production team and testing team are created. Now here you can see the individual block is created. The apartment is created and there is nothing present in those apartment. Now as per the requirement what we want we want each in each name space we want an enginex board. How do we do it? So basically it is again simple cubectl run engineext which is the name of the pod followed by the image name. So image equals to engine x col. So hyphen - namespace and name space equals to dev team. Enter. Here it says pod created. Now let us do the same thing for testing team and the production team because earlier if you remember we were getting one error right now this time we are going to test whether we are going to get that error this time or not. When I press enter it again says the pod name 3:48:41 engineix is created. Now let me create the same pod for the production team. Enter. Here it says engineix pod is created and it is successfully created for all all three of them. Let me clear the screen and let me just list the pod. So cubectl get pods. When I enter this command, do you see it says no resources found in the default name space but if you remember we created three pod but where exactly it went? It went into the actual name spaces where it belonged to. Now what do I mean? Basically it should go into the name space into development into the testing or into the production team. Right now what will I do? I will just run the same command but here I will write in the name space dev - team when I press enter one second let me just correct the command name space equals to dev team. So here you can see engineix pod is up 3:49:43 and running. Now what will happen if I check for testing team enter. Here you can see again and pod name engineix is running in the test team name space. Now similarly if I run for prod name space uh namespace equals to prod team you can see engineix pod is again running in the name space of production team and that is what we wanted to achieve. This is something that we wanted to achieve because here we have created same resource name and there is no conflict right and that's the beauty of namespace. Now if I want to list all the pod at once with and also I want to see the list of name spaces together. How will I see it? Basically I will run cubectl get pods - a and here you will get entire detail about the pods which are running in your system. Now here you can see engineix pod is running in dev name spaces 3:50:44 engineix pod is running in prod name space and engineix pod is running in test name space. So this command is used to list down all the ports throughout the name spaces. Right. Let me clear the screen. Now since we are talking about name spaces let us uh I want to I wanted to show you few more name spaces which are very much important for us to understand. So for that let me list the name spaces. So cube ctl get an s for name spaces. So for now ignore dev team pro team and testing team focus now on the remaining one. So let us begin with the first one default name space. So what exactly it does? So in default name space basically it just like a main lobby or the general workspace. So this is an open floor where anyone can walk in the starting where anyone can walk and start working. If you tell the system to run an application but you don't specify the name space it will directly go into the default name space 3:51:46 and that is something which we demonstrated in the initial level itself. Right? So this is the default room for every projects. Now let us move forward for cube node list. Now what is cube node list? So let's say uh employees are punching it periodically to prove that they are still in the building. So this name space so this name space basically hold uh something called a heartbeat for your files for your server which constantly says that hey I am still alive healthy and working. So if a server stops sending the signal the system will know that it got crashed. So this is the significance of cube node list. Let's move forward with Q public. So what exactly is Q public? Cube public is a highly visible area to anyone even people from outside can see it without needing any sort of special security keys. It is typically used for basic nonsensitive information that the entire network needs to read and connect properly. Now lastly we have cube system. Cube system is the main 3:52:47 utility room the main maintenance closet. So what exactly it does? This room is strictly for the building operations team. In short, if you want to uh say what exactly is cube system, cube system in is exactly the internal brain of cubernetes because all the things required to run a cubernetes is present inside cube system. Right now let's move forward with the last one that is kubernetes dashboard. What exactly it is? It is a UI based dashboard that we can see in a visualized way. So it is a web- based control panel. So instead of typing commands, you can visually um see all the things. It gives you charts. It gives you button. It gives you visual maps. So it lets you to click around and see how many apps are running and you can check how many server are broken and you can even view your name spaces and that is basically used with the help of the standard browser that you may use. Now there is one thing I mentioned earlier that cube system is the brain of Kubernetes. It's the core through which 3:53:49 cubernetes run. What exactly is inside cube cube system? That is something that we need to check. So cube ctl get pods in the name space cube system. Enter. One second 3:54:17 name space enter. Here you can see all the components of Kubernetes are present. Here we have the core DNS. Here we have HCD. Here we have here we have API server the control manager cube proxy scheduuler and storage provisioner. So this is exactly the core which is required for kubernetes to run right. So that was the importance of name spaces in kubernetes. In this video we learn about uh what are the things what were the challenges before c before name spaces and how does namespaces helps us with the isolation why cube system is a very important component in cubernetes. Now let us go back to the learning and let us understand what all things are covered in namespaces right because when we are talking about namespaces we should be aware what exactly has been covered and what things can be isolated right. So for that you can go to my GitHub repository and in this repository you will need to find Kubernetes tutorial and in sub 3:55:18 repository number six you will find name spaces scoped resources. By the way whatever we are discussing today is already documented in this MD file. You may feel free to check it out. It will give you a complete uh revision so that you will have a complete clarity what we are learning today. So whenever you are dealing with namespaces there are few things that namespaces are covering right. So these are the scoped resources that name spaces cover. For example, pods, deployments, replica sets, services, config maps, secrets, jobs, chron jobs, ingress, PVCs. Now I know that these terms are very much new to you. Don't worry on that. We are going to cover each one of them in detail because these are the very important components in Kubernetes. These resource can only exist independently inside the name spaces and that's the reason I mentioned it over here. Right now since we know what are the things that name spaces cover but we should be aware of 3:56:18 what are the things that is not that does not belongs to namespaces. Right. So here we have nodes name spaces persistent volume storage classes cluster roles and cluster role bindings. So some resource exist for the entire cluster and these are those resources. Right now since these are the clusterwide resources they do not belong to a specific name space. So that's the reason these things doesn't fall into the name space right and these are not covered into name namespace. Now when I say these are not covered into the name space I mean to say that the uh the isolation will not be provided for these sort of resources. Now that we already know how name spaces work. Now let us go through one more method through which we can create namespaces. And yes you guessed it correct here we will be creating the name spaces with the help of manifest file. So what I will do I will create a new file nameace dot yml enter and here let us create a 3:57:19 new name space for us. Now here what I'm going to do I will create a new name space and I will tell you how manifest file I created. Now as I mentioned in the previous video in order to create any sort of resource in kubernetes there are four important keywords which we need to keep in mind. First is API version. Make sure you are entering V in caps. Okay. Second is kind. Third is metadata and fourth is spec. We are already aware of the specifications. We are already aware of what each term means. So now let us focus on how we can create a manifest file for namespace. Right? Now the first thing that comes into the mind is shamro I don't know where do I get the API version. Well again there are two methods. Right? First is go to Google and search for namespace manifest for Kubernetes. Here you will get the first link that you need to refer. And if you scroll all the way to the bottom 3:58:21 here you will find one of the manifest file. And here you see you have a new article for creating a new name space. And if you scroll down here you will find the API version. Right? How easy it was. Right? Here we need to write the API version. v1 but let's say I don't want to go outside from my terminal I want all the information in my terminal itself which utility from cubernetes should I use so yes you can go back you can just open your terminal let me clear the screen and here you will make use of cubectl API resources and when you press enter you will get all the information over here starting from the name short names API version name spaces and kind here we are looking for namespace right so what I will do I will just run a graph over here for namespace enter and here you can see the API version that we should use is v1 right 3:59:23 so instead of assuming things we are searching it and then we are actually entering it over here so API version is v1 now when it come to kind so what is the significance of kind so basically kind actually tells cube Kubernetes what sort of resources we are trying to create right so here we are trying to create name spaces right so I will write namespace now how will I know whether when to use capital N right again you can refer the documentation or you can go to the console search for API resources and here you will get the resource name right I entered the kind that is name space now Kubernetes know what sort of thing we are trying to create now come to to now comes The main now comes the main part that is nothing but the metadata. Now what exactly metadata consists? Metadata consists data of data. Right? So here we will mostly write the name spaces if we are creating the part. But now since we are creating the name space here we will write the name of the name space itself. So I will write name. Make sure of the 4:00:25 indentation. Now whenever we are dealing with Kubernetes we are dealing with we are dealing with YAML and YAML is very strict with the indentation. So here I will write the name of the name space and here I will write uh DevOps cube. This would be the name space and I will delete spec. Now Shubam why did you deleted spec. See since we are dealing with namespace there is no need for any sort of further specification. This data is sufficient itself and this will help you in creating the namespace. Right. Let me clear the screen. And when I go when I just list the files, you can see namespace.l is present. Now the manifest for namespace is created. Now let me apply this file. So for that I will run cubectl apply f to pass the file and the name of the file is nothing but namespace. Mml. When I do a zoom and press enter. Here you can see devi devops - cube is created. 4:01:26 Now let me just list down the name space. So cubectl get namespace and here you can see devops cube is present right. So that's the beauty of m making use of name spaces. Right? Now let us do one more thing. Let us create a pod inside the namespace. Now this time we are going to do this with the help of manifest file because through command line we have already seen this right. So what I will do I will again create a new file. I will tell you everything from scratch so that you don't need to worry and you don't need to refer the documentation from here and there. The only documentation that you should refer is nothing but the documentation which is provided by Kubernetes. Why? Because there are multiple benefits out of it. Let's say in future if you prefer for CK the only document that will be given to you for the reference is nothing but this Kubernetes documentation and also since it is the official documentation you will get the latest and trusted information over here. Now let us go back to the visual studio code and let 4:02:27 me just create the manifest for pod also. So here again I will start with API version. This will be the this will again be a standard template kind metadata and spec. Okay. So this is the standard uh template that we need to follow whenever we are creating any sort of resources in Kubernetes. Now again how will I know the API version when I'm creating the pod? I know the kind is pod because uh the resource that I'm creating is nothing but pod. Okay. But how will I know whether to use v1 app/v1 b/v1 what to use? So for that again I will refer to the documentation. I will go back to Google and I will search pod manifest file for kubernetes. And here the first documentation that I will get is nothing but from kubernetes.io. And if I scroll all the way to the bottom here, you can see the API version and the demo file is present over here. I will go back here. 4:03:29 I can make use of v1 directly. Right? Space v1. Or else I will make use of API resources. So cubectl API resources enter. And here I will search for pod. So grab pod. And here you can see the API version is v1. Right? And now the kind is pod with pcaps. Now let's go to the metadata. Now what should be the name of this pod? The name of this pod should be enginex. Engineix pod. Okay. And in which name space do you want to create it? I want to create this in DevOps cube nameace. The name space which we just created. So I will just type namespace DevOps cube. Right. So till now everything is fine. Now here comes the main part that is spec. Now what exactly spec? Spec is nothing but the specification. Right? When I press enter here I will define what thing I need to create. I want to create a container. So 4:04:30 here I will write containers. Okay. And what would be the name of that container. So here I will define the name of container and that is nothing but enginex container. What image should I use when I'm creating this container? So for that I will make use of engineix colon latest. Okay. Now where will this find the image from? It will go to docker hub and it will find the image from there. Right? So this is how we have created the manifest file for the pod which belongs to the name space devops cube. There is one thing that we need to highlight over here. Okay this single line this single line literally changes everything. Okay. Now I will just comment it out and let me just implement the change and let us see what actually happens. So cubectl apply - fp pod.ml enter. Here it says engineix- pod is created. Now let me clear the screen and when I run cubectl get pods. Here you can see since name spaces was commented out it created the 4:05:30 name space in the default name space which we didn't want it and this was again one more learning for our end that whenever we don't refine any sort of name space the pods and any sort of resource will get created in the default name spaces right now let me just undo it let me just uncomment this comment and now I want that pod to be created in the nameace name devops hyphen cube. So I will run cube ctl apply -f pod.ml enter. And here it says engineix pod created. But this time where here this time we are looking for in the name space devopsy cube. Enter. 4:06:24 And here you can see engineext - pod is up and running in the name space name devops - c q. Right? I hope that made I hope that made sense right now from this entire activity. Now you only answer me can two name spaces have same pod name. Let's say you have a development nameace and you have a testing namespace and you want to create a pod name engineext. Right? So can you do that? Well the answer is correct. You can actually create it when you have name spaces in picture. You can create the pod with same name and it will give you complete isolation. That's the reason of creating name spaces. Right now there is one more activity that I wanted to tell that is what will happen if we delete the nameace itself. What will happen to the resources inside it? Right now you can see inside this DevOps cube name space engineix pod is up and running. But what will happen if I delete the namespace 4:07:25 DevOps cube. Let us demonstrate the same. So cubectl delete nameace followed by the name of namespace. It is devops cube. It says devops - cube is deleted. But the question arises is what will happen to engine pod? Will it still be there or will it be running somewhere? Let me just run the command once again. Here it says no resources found in DevOps cube name space. Why? Because the nameace itself is deleted. Right? Let me clear the screen. And when I run cubectl get pods a here you can see the engineix pod which we created is just present in the default name space and it is not present in any of the name space because it was present earlier in devops hyphen cube but since the nameace itself is deleted everything is gone right so that's the reason uh you should be very much careful whenever you are dealing with 4:08:26 namespace and whenever you are deleting the namespace Right now let me tell you the best practices which you can follow in the projects. Never use the default name space in any sort of projects. Right? Keep separate name spaces for development. Keep separate name spaces for testing. Keep separate for staging. Keep separate for production. This makes your cluster much more easier to manage. Right? So that was all in this video. Let's take a quick summary of whatever we learned today. So today we learned about namespaces. namespace. What exactly it is? It is a logical partition inside a Kubernetes cluster. It provides isolation between application and teams and resources like pods, deployment services uh belong to namespaces. Some repo some resources like nodes persistent volume they do not belong to the name spaces and let's say if you do not specify any sort of name space while creating the resource it will go to the default namespace automatically right 4:09:28 and namespace allow different teams to use the same resources without conflict and in real world environments almost every production kubernetes cluster uses namespace extensively right so now that you have understood namespace This is visually and also practically you can you are now very much ready to organize Kubernetes application the same way it is managed in any of the environment right so I think that was all for this video I hope you liked it feel free to check out the documentation believe me if you have if you develop the habit of going through the Kubernetes documentation it will help you in long term right so here you can go with the definition itself for example what exactly is a pod well this is something that we are going to cover in detail in the coming videos and basically you can just go through the documentation and also I have documented everything in detail whatever commands I have used over here into the MD file. So you may have a look over here this will definitely help you in revision. So yes 4:10:29 that was all in this video and I hope you liked it. So I will see you in the next one. Till then keep learning and thank you very much. Hey everyone, welcome back. In the previous video, we learned about name spaces. In this video, we are going to talk about something that helps Kubernetes in organizing the resources. Yes, I am talking about labels and selector. And believe me, uh this is one of the most underexplained topic on internet because mostly people will ask you to refer the Kubernetes documentation. But yeah, it is correct. But it should be something like that. You should be able to understand why we are actually learning that concept. Right? In this video, we are not just going to visualize it. We are going to understand what is the importance that labels and selector bring us into the plate right and by the end of this video you will be doing the practical hands-on and don't worry I will literally tell you each and every line the significance of each and every line of that YML so that you are not left with any sort of doubts this is the only video that will 4:11:30 help you to clear all your doubts with labels and selector so yeah on that note let's get started so in order to understand labels and selector you will need to come to airport with me. Right? So now let us take an example where you are in airport and you are taking a flight to Bangalore. Right? So when you are taking a flight to Bangalore, you will carry your suitcase, right? That suitcase in Kubernetes terminology is nothing but your resource. That resource can be a pod, it can be a service, right? And there is additionally one more thing that has been attached to a suitcase and that is nothing but tag. That that tag can be from Air India, it can be from Indigo or it can be from any airline. Right? What is the significance of that tag? That tag will help people in the airport the air staff to identify where this bag is going to. Right? Since you are traveling from Maharashtra to Karnataka, it will give them the clarity from which source to destination it is going. Right? So it will be easier for the air staff to group the resources. 4:12:30 That is exactly been done by labels and selector. Right? I hope that example made sense. If not then let me throw one more example. Let's say you are in a school right? In school mostly on Fridays and Saturdays we wear house uniform. School where I come from basically we have four sort of houses. Red house, blue house, green house and yellow house. So this is how we used to group the students. Uh and that is how we used to do the categorization. That is exactly been done by labels and selector. Right? So I hope that gave you the idea what exactly labels and selectors are. Labels is something that we are giving name to a specific entity. Selectors helps us in identifying them in pulling them out. Right? So when I'm talking about red house, so we know all the people who are actually wearing the red shirt are from the red house. So that is how we are doing the selection. Right? So here label is not just a name. It is a metadata that helps us in identifying the resources. so that Kubernetes can connect it with the 4:13:31 objects. Right? I repeat label is not just name it is a metadata. Right? I will repeat this line again in the video because when we will be writing the YAML file at that time you will come to know that why I repeated this line. Right? So on that note let's get started with labels and selectors. Okay. So let's get started. So here you can see we are on folder subfolder subdirectory number seven labels and selector. You will find the documentation over here. So let's begin with labels first. What are label or what is a label? So label is a key value pair. A key value pair. Okay, which is attached to an object in Kubernetes. Labels are stored in metadata. Okay, I repeat again. Labels are stored in metadata. And it is used to organize, filter, and select the object. right now what do you mean by uh labels are used to organize 4:14:32 and why you are repeating metadata dot labels every time see there is a significance to it and from the starting itself I have been emphasizing on metadata word why because label is a metadata right so when I started my journey with Kubernetes for me it was very much difficult and I was just guessing like uh how do I know exactly which thing to put into which sort of section and that is how I learned right label is a metadata that's the reason it will go into metadata section I will directly go to visual studio code and I will just show you how things work over here before even that let me just open a new terminal and I will just start my mini cube so that we are ready with the setup so mini cube start enter all right so meantime it is getting ready let us create a new file and this file will be for creating a pod and in that pod we will be adding a label. So here I will write pod do yiml enter. Okay. So 4:15:34 whenever we are dealing with kubernetes file what are the four important keywords we should remember we should write. So basically it is nothing but API version kind meta data and spec. Okay. Now I'm sure that till now you have a clear understanding on what to write on kind, right? So what do we write on kind? So in kind basically we define what is the object type that we want to create and that is how cubernetes will know. So let us start with the first line itself without any confusion. Right? So here the first line is API version. But the thing is the first question is you should ask whenever you are creating any sort of manifest file. What do I mean by manifest file? So what sort of file that you are creating on Kubernetes for creating any sort of resource is known as a manifest file. Right? So going forward from now onwards whenever someone says uh like I'm looking for 4:16:36 that manifest file. He is talking about the YAML file in Kubernetes. Okay. So note down now here we are creating a manifest file per pod. Okay. Let me close it. So what's the first thing that we need to write? It's the API version. Okay, how do I know what is the API version for pod? So for that there are two methods again go to internet search for Kubernetes documentation there you can just do a copy paste or else you can just stay in terminal and you can just write cubectl API resources enter and here you can find the information so I will just do a grab on pod enter and here you can see the API version is v1 and that is how without even leaving my terminal I can directly write the API version and kind on my manifest file. Now kind is again part with PS caps. How do you know to put PS caps? Basically again API resources will give you the complete information. If I just scroll all the 4:17:37 way to the top, you can see the headers. Here we have name, short names, API version, name spaces and kind. And that is how I was able to know which letter to keep in upper case. Let's go. And now here comes the main part metadata. Now here the metadata will ask you about information the labels basically right but the first thing that he will be asking is now since we are creating the pod what should be the name of that pod let me just name that pod as front end okay now the next thing is we want to create a pod with some sort of labels now since we are talking about labels here we need to add labels right and if you remember from the starting itself I was very much emphasizing on metadata right label is not just a name it is a metadata and that's the reason here it will fall under metadata and here I will just define the labels labels colon enter along with the space okay make sure of the indentation yaml 4:18:39 is strict with indentation right okay now what sort of labels you can add basically you can add anything now here I will add two sort of labels it should be in key value pair what do I mean by key value pair basically you will have to write your key followed by a colon a space and the value right so here I will just mark it as application it will be a web app and the environment let's say uh for now since we are learning the for the very first time I will mark it as dev feel free to do the experiment because that is how you are going to understand how does this thing are working right because mostly I have seen people teaching about labels and selector mostly what they do they'll go to they will ask you to go to internet search for uh any sort of service services in Kubernetes services in Kubernetes and then uh you will be asked to go to services go through any of the manifest file and then this is how like you will copy and paste and learn but that's not the thing 4:19:40 right you will have to break the things down because when you are learning you have to go through each and every line because that is how things will make sense right let me go back and here we are under metadata. So basically I will explain you each and every line. Don't worry on that. Right now once labels are done then we'll start with the specification now since we are creating a pod what can be the configuration. What can be the specification? Basically we want to create a container. So I will write containers. Containers enter. And here I want to create engineext container. So I will write name engineext. enter and through which image it should be graded. So image colon engineext colon uh like let's say 1.14.2 to my manifest file is ready. Okay, let me now explain you line by line. Okay, now what exactly is API version? Okay, so what exactly this does? This tells this tells Kubernetes 4:20:43 what version of API to use, right? For a pod, the stable core API version is v1. Next comes the pod, right? What exactly it is? It defines it defines the object type object type and here in the in this case it is a pod right. If you write uh basically service the type of object will be a service here if you define the kind as deployment then the object type will be deployment. Next comes metadata. Now what exactly is metadata? Metadata simpler terms everything that comes under metadata describes the object as itself right it contains the metadata about the pod in this case then moving forward with the next line that is name colon front end so basically what exactly is this this is the pod's name uh it must be unique in the name space now let's move forward second is the labels now what exactly is this section 4:21:44 is where we add the labels to the pod Okay. So here I'm writing labels are the key value pairs that are attached to the object such as spot. Label can be used to organize and select the subset of objects. Okay. Next is app colon web. So here we have label with app as the key and web as the value. Right. So it means uh that this pod is a part of web application. Next is env. Now what exactly it signifies? Basically it is another label with key as env and value as dev. It tells us that this pod is in the development environment. Let's move to the spec section that is specification what exactly it is. So let me just write about it. So what is spec? Spec section describe the desired state of the pod right and inside that we have defined uh what sort of thing we are created. Now since we are creating a manifest for pod here we are listing uh 4:22:44 through which uh container that should be created. So here we will uh define the list of containers that should be running in this pod and the first container that we are creating is for engineext and that's the reason we have uh written the name of the container that will be executing that will be running inside that pod. Finally we have the image. Now since we want to create a container right we need a blueprint right we need an image. So basically here uh it is the image that through which that container will be created right now what is the main highlight in this entire manifest. So by adding labels like uh app col web and in env. Okay we can later select this pod with queries like app equals to web or app equals to or env equals to dev. So like I hope this made sense. Now let me show you the practical and I hope that each and everyone is now very much clear with the understanding how do we create a 4:23:44 manifest file. Right? If you want I will explain it to you multiple times. There are multiple hands-on that I have planned for this specific demonstration. And believe me after this video you won't face any sort of issues whenever you are creating any sort of manifest file because here we are breaking down things in a very smaller chunks. Okay. So let us create a pod and uh here the main part would be the main area of focus would be labels right because that is something that we are going to discuss today. Okay. So let me just move into the subdirectory number seven. Let me clear the screen. And when I do a long list here, we have pod.l. Okay, let me just create the resource by typing cubectl. Let me just do a zoom so that it would be visible for you. Clearing the screen. So cubectl apply-f uh and name of the file that is nothing but pod.l. Here it says pod/frontend is created. Okay, let me just list down the pod. So cubectl 4:24:45 get pods. Enter. And here you can see we have a pod by the name front end which is created up and running. Right now the main part is Shubhham we created the pod but how do we verify the labels are highlighted or not. Okay that can also be done. Let me just go into full screen mode. And here a part like after ports you need to add one flag show hyphen labels. How easy is that right? show hyphen labels and it will list down all the parts along with the labels. And if you remember when we were creating the manifest file, we define two labels that is app web and env. And here if I show you here we have the labels app equals to web and env. Let me just do a little bit of zoom out so that it will be visible for you. So here we are talking about front end pod which is running on the default name space and here we are dealing with the label named app equals to web and env equals to dev 4:25:47 which is exactly coming from this manifest file. Okay now let me explain you the command that we just used. Okay so we made use of cubectl get pods hyphen show labels. So what it will do it will list the pod and will print the labels attached to each pod. Right now what will uh now let's see if I want to get more information about it about this specific part how will I get it let me clear the screen and here we are going to make use of cubectl describe describe pod followed by the pod name and the pod name is nothing but front end here you can see chunks of information are present and here we will get lot more of information but the thing that we are interested is in labels, right? So, let us search for labels. And here you can see under the labels, we have two values that is app equals to web and env equals to dev, right? And this is again coming 4:26:48 from that manifest file. I hope the concept of label is clear. Now, now let us move to the next part that is selector. But the main thing is uh we defined labels and if you remember the example of school where we have multiple houses, right? We can literally choose the people who have wore the red shirt. We can literally choose the people who are from blue house, from green house or from the yellow house. Is there any way in Kubernetes where we can do that cherry picking? Yes. So that can be done with the selector queries, right? So selectors are the queries that actually matches the labels. So when you ask Kubernetes for objects, you can use selector to fill them to filter them. Okay, let me clear the screen and here let us make use of selectors. Okay, now let's say if I want to uh match all the objects where the label is app and it has the value name web. How will I do it? So I will make use of cubectl 4:27:48 get ports. Basically it will list the parts l I want to list down all the objects where the key is app and the value is web. Enter. And here you can see we have the pod up and running. And if you see here, it has actually showed the front end pod which is actually having this sort of configuration, this sort of metadata. And where it is coming from, it is again coming from the same file, the same manifest that we just created. What will happen if I just run cubectl get pods? Here you will get entire pods which are running on the default name space. But since we just wanted to do a cherry picking, we just wanted to point out to only that pod which has app equals to web value. So that is how you can actually cherrypick it out. Right now let's say if you want to pick out those pods where the environment is dev. Let me clear the screen. Let us repeat the same. So cubectl get pods. Basically what it will do, it 4:28:50 will list down all the pods. Now I want to list only those part where the environment is development. Enter. And here you can see again front end is listed and that is basically how things are working over here. And that's the power of selector and that's the thing that is bred by labels and selector. Let us visualize things. Now I will go to excal draw and yeah I hope you remember about name spaces. So after we are done by learning name spaces, labels and selectors for deployment and services don't worry we are going to club everything into a single one so that we will have a complete idea how does kubernetes work what sort of things kubernetes bring us into the plate. So let us take a scenario that will help us to understand labels and selector in the very next level. So let me create uh three pods. So here I have uh let me create it in blue. Okay. So here we have pod a and inside that pod uh we will 4:29:52 mark uh app equals to web as uh one of the key value and secondly we will define the uh you know the environment. So env equals to dev. So we have an application we have a web application where the environment is dev. Okay. So this is the first thing that we have. Now secondly we will create another pod and in that pod uh the app will be again um the app will be again web but this time the environment will be broad. Let us create one more pod and this time the application will be an API a backend application but the environment will be prod. Let me just add one labels for our reference. So this would be pod one. Okay. And uh I'll just Okay. I think this font should be okay. I'll just do a zoom so it is actually visible for you. Okay. So pod one is here and here I will add part two 4:30:52 and now I will just copy it and here we will have the part three. Okay. So let me just explain you once again what we are up to. Right. So basically here we have pod one which consists of uh two two key value pairs. First is app equals to web and secondly is env equals to dev. We have pod number two which consists of again two key value pairs app equals to web but here the environment is prod. Third is key value pair. Third part is again consisting of key value pairs where app equals to API and the environment is production. Right? Now the thing is let us say I want to only select those uh pods where the application is a web application. how we will do it. Let us create the manifest for the same and let us recreate this scenario and that is how we will be learning about labels and selectors. Let me go back to Visual Studio Code and here uh what I will do I'll just create one directory for us. So I will just write practice 4:31:55 uh for uh labels and lbl and selectors. Okay, I'll just rename it later but for now we are just focusing on the practice that we want to do. So the first thing I will be creating is pod 1 do yiml. Enter. And I will create two more pods. So pod 2 do yiml. Enter. And another pod that I want to create is pod 3 yiml. Okay. So we have three manifest file present with us. And let me just go inside that practice folder. And when I list I have all the three parts created. Okay. Again I will be starting everything from the scratch. No copy pasting nothing. Let's start with the pod number one. Okay. So how do I create a pod with manifest basically let's start from the basic. We will need an API version. Second is we will need kind. We will need a metadata and finally we will need a spec. Okay. So this is the building 4:32:55 block through which all the parts through which all the manifest file will be created. Right now how do I start with it? The first thing that I should be clear about is what exactly I'm creating. Right. Here I'm creating a pod. Right. So here in the kind I will write as pod. Okay. Now let us make silly mistakes. I will just mark it as small letter. Now since you are making use of visual studio code it will show it will throw some error. But if not don't worry we will make use of cross reference. We will make use of API resources. Now the thing is I amware aware of what resource I want to create. I want to create a pod. But what should be the API version? What should I use? For that I will make use of cubectl API resources. Enter. And here I will run a grab on enter. And here you can see we have v1 as API resource. So after colon give one space and write v1. And here if you 4:33:55 remember the type is pod right the kind is pod but here the up here it should be in upper case let's move forward with the first thing that is name of the pod now what should be the name of this pod yes we want to mark it as pod one okay so here I will write it as name colon pod one so basically I am just trying to replicate this same environment I'm going to name the pod as pod one, pod two and pod three. So that we are actually creating recreating this scenario. Okay, let me move forward. In this pod one, uh we want to create few labels, right? So here just below the name, I will define the labels. Labels colon enter. Now in the first diagram, what it says? We want app equals to web and env equals to dev. All right, let's do the same. App is equals to web and envals to dev. Shubam why you are not making use of equals to see this is not 4:34:56 Linux this is YAML in YAML whenever you want to define any key value pair you make use of key colon value but when you are dealing in Linux you will write it as key equals to value right that's the difference is a formatting that has been used by Kubernetes and this is one of the reasons okay now let's move forward with the specification now in the specification we want to create a container since we are creating a pod we will need a container that will be running inside Ed and for now let us run engineix over here with the image 1.14.2 two. I hope everyone are everyone is aligned. Let me explain you each and everything line by line. API version V1 what it does basically it tells Kubernetes which version of API to use. So for a pod the stable core API version is nothing but V1. Let's move forward with the next one that is kind. Here uh what it does it defines the object type and here we are creating the object name. Okay metadata. What is metadata? Metadata is basically it describe the 4:35:57 object itself. Now what sort of objects we are defining? First is the name. What is name over here? It's pod one. What is the significance of pod one? Basically whatever pod that will be created through this manifest, the name of that pod will be nothing but pod one. Right? So this is the pod's name and it must be unique in the name space. Let's move forward with the labels. Right? This is the section where we add labels to the pod. And here we have app colon web. And here we have a app. Uh here basically a label with key app is present and the value is web. What is the meaning of it? It means that the pod is the part of web application. And here again we have defined a label for env. What it signifies? Basically this belongs to the development environment. Now let's move forward with the spec. The spec section describes the desired state of pod. And here uh basically we are trying to create the container. So here it will have the list of container that should run in this pod. Here we are passing the 4:36:57 name of the container and again we are passing the name of the image through which that container will be created. Now again from where Kubernetes will pull the image. Now here the image will be pulled from dockerhub itself. Right. Okay. So I hope that made sense and we are done with the pod one. Let us create a pod two and here we will be directly writing it in a fast forward manner. Don't worry, I will be writing it once again. So that it is actually helping you to understand uh and follow the approach how you should write a manifest file. So here the difference in pod one and part two is instead of environment as dev, we are making use of broad. Okay, don't worry. I'll start it once again. So I'll go to part two. I will write API version kind metadata. I will be fast this time. So meta data and here we have spec. Okay. Now uh I'm going to create a pod. So here I will define the kind as pod API version from where will I get? Basically 4:37:58 I will run cubectl API resources grab pod and here we will get the API version. So it's v1. All right. So with a space I will write v1 over here. Now what's the metadata? So metadata here we are trying to create pod 2 and that would be the name of this pod. So I will just go to metadata. Enter. Give one space write the name of the pod. So it is pod two. Let me just recheck the name what I gave. Okay, pod one. So let me just add pod hyphen 1 that would be good in reading. So pod hyphen 2. All right. And now since we are dealing with labels and selector I will write labels. What are what all labels we are going to make use of. So here we want app equals to web and env equals to prod. That is something that we are going to do today. That is something that we are going to do now. So app is web and env is prod. Okay. And that is exactly the requirement in part two. Okay. Now once this is done, let us go to spec section where we will define the desired state, the specification, the configuration and 4:39:01 here we are defining the configuration for containers and here the same container has been utilized. So here we again recreated the same file but with different configuration but with different labels. The difference between pod one and pod two is nothing but of environment. Here the environment is dev and here the environment is production. Now let us recreate pod number three. This time we'll uh do it fast forward. Let me just copy entirely from port 2. ML we'll paste in port 3. ML. I will just rename part two with port 3. And here instead of app equals to web we need to update it with app equals to api. And the environment remains pro rest everything is same as is no changes required. Okay. Now let us apply all the changes. Let me just do a long list. Now let's say you have multiple files, multiple uh YAML files, manifest files which are present with you and you want to create 4:40:01 resources at once. How will you do it? Basically the first approach is you can just write cubectl apply followed by the file name. yl but again there is another one shortcut you can just write cube ctl apply -f star yiml what it does basically all the files that ends with yiml extension it will create the resource for the same when I press enter what it says unexpected argument apply hyphen h for help okay uh let me just check uh I think okay so basically it should be like cube ctl apply - f dot So basically whatever files whatever yamel files which are present in the current working directory it will create resources for us. Enter. And here you can see pod one port 2 part 3 is created in single shot in one go. Okay that's the beauty. Now let us list all the parts. So cubectl get pods enter. And here when I do a zoom here you can 4:41:02 see all the pods are created. Now let us see all the labels for all the pods. Right. So cubectl get pods hyphen a enter. Here we can see all the pods are running in default name space. And now if I want to see the labels of that pods, how do I see it? Basically let me clear the screen. I will type cubectl get pods showy-en labels. Enter. And here you can see if I just zoom out here you can see all the information. So here you need to just focus on the last three parts. So let us verify the same in pod one here we have app equals to web and env equals to dev. Uh so here app equals to web and env equals to dev. For part two it is web app equals to web and env is prod. So for part two here you can see app is equals to web and env is equals to prod. For part three we have app equals to api and environment is production. Here in part three app is equals to API and env equals to production. Okay. So we are 4:42:04 good with this scenario. We actually created this scenario. Now let us test how does let us see what what of what sort of power we have with labels and selectors. Right? We have literally generated the scenario. Now let's say I want to filter out only the parts where the application is a web application. All right, fair enough. Let me clear the screen. And here there is another uh front end part that we created. So let me just delete it first. So cubectl delete pod followed by the pod name and the pod name is nothing but front end. Okay and it has been deleted. Let me just show you the result once again. So here we have okay these are the three pods where we are focusing on. Okay now let's see if I want to list uh the pods where the application type is web right how do I do it? So basically cubectl get pods hyphen add list down all the pods where app is equals to web enter and 4:43:06 here you can see pod one and pod 2 is listed over here why because here the application type is web right now let's move forward and let's say if I want to see uh the application where uh uh let's say I want to see the parts where application is of type web but the environment is prod right in In that case it will show us the result of port two. Let us do the same. So here I will write app is equals to web and env is equals to prod. Enter. And here you can see port two the result is present over here. Now let's say another example we want where the where the application is web but the environment is dev. Enter. And this time what result are we expecting? So app is equals to web and env equals to dab. We have pod one and we are expecting pod one over here and that is exactly what we got over here. Right? So that is the power of selectors. They let you choose exactly the subset of the resource that 4:44:07 you want. I hope that made sense. Right? Let me go uh let me go back to the documentation and whatever we learn will be present to you. Don't worry about that. And I will literally push the files that we are uh working over here into the repository after this tutorial so that you will have every file. Just play along with it and I will recommend you to uh create your own files. Later you reference it then only you will be able to get more out of it. Right now here we learned about labels. We understood why labels matter. We created few manifest file. We understood uh how things are working. We learned about selectors, right? And we made use of selectors too, right? But why selectors matters? Selectors are used by many Kubernetes uh controllers and resources, right? Now there are few terms that will be very new to you. Don't worry on that right now. Just focus on the concept that we are learning right now because 4:45:07 at the end we are going to club everything together and by that time it will be very much clearer to you. Right now I'm focusing on strengthening your foundation. Once your foundation is strong then only your building will be good. Right? Okay. So why selectors matters? So selectors are used in Kubernetes resources. So what sort of resources basically it can be services, it can be replica set, it can be deployment, demon set, stateful set, it can be anything. So what it does basically it uses selectors to know which pods it should manage when we are dealing with replica set. When we deal with service it uses selectors to know which pods they should receive the traffic in. Right? So if labels and selectors do not match the controller will can the controller cannot connect to the right pods. Right? So if you want to see an example with service uh with the selector I can show you that too as well. So let me go back to Visual Studio Code and here I will create one more 4:46:09 file over here and here that file will be for service service. Mamel and if you are work and if you are wondering what exactly service so basically service is uh that sort of resource in Kubernetes that routes traffic to the pod that have uh the right label based on the information that we provide. Okay, let us create a service manifest. So API version what it is I don't know kind uh it is service but again I'm not sure which which letter should I mark it as capital but mostly it will be the first letter that will be capital whenever we are dealing with kind so metadata again next we have spec okay now how do I find what's the API version for service go to internet open browser go to kubernetes this documentation. Search for it or open your terminal and search for cubectl API- resources. 4:47:12 Enter. And here we need to do a graph on services. Enter. Here we have V1. Okay, got it. Let me scroll down. Here API version will be V1. Okay, now metadata. What would be the name of this service? So, let me just give this service a name. So name of the service will be let's say front end service for now. Okay. And in the like specification uh we want to create a selector. So selector selector colon enter. And here we want to create a selector where uh we are targeting to only those pods where the application will have the value for web and the env should be of production. Okay. Now let's say it can be development too. So let's take uh we only want to target those parts where it is of type web and the environment is development. And here uh we will define the ports. So I will just make sure the indentation is proper. So just below at 4:48:14 the level of selector I will define the ports ports colon enter. And this will run on port number 80. And the target port target port is 82. Okay, don't worry what exactly it is. I won't emphasize on this right now. But still we are creating a service. I will tell you line by line each and everything. So what exactly is this thing? API version. So it's basically the API version for the service for the stable core API. Secondly kind colon service it is the object of service type metadata service metadata section then name of the service that we would be creating specification so the desired state of the service selectors so the labels that service will use to find a pod and here we have two sort of labels app web and env so here it will match the pods with 4:49:15 a label app equals to web and envals to dev Then finally we have defined ports. So the ports on which the services exposed. And then finally here we have defined the service port that has been used by the clients. And here we have defined the client ports inside uh client ports inside the port. Okay. Uh so here what exactly it is the container port where it received the traffic. So for this service, Kubernetes will send traffic only to those parts that have both app equals to web and env equals to dev labels present. Right? So that was about service. I don't want you to uh like right now don't focus on much about services because that will that is something that we are going to cover up in the later video. For now just focus on labels and selector. Right? That was the main purpose for telling and taking this uh specific section. Okay. Now let's move forward to the next topic that is in selectors we do have type. 4:50:16 Cubernetes supports two selector types. One is equality based selectors and secondly set based selectors. Till now whatever we were running it was a equality based selector. Right? So what is a equality based selector? So basically it select the pods with app is equals to web named and secondly uh we can also search for another pattern where the app is not equals to web. So basically equality based selector is basically where equals to sign is involved. Let me show you the live demo by that you will be getting complete idea. Clearing the screen cube cl get pods pods odds hyphen show hyphen labels enter and let's say uh if I want to list down the pods so cubectl get pods and uh I want to list all the pods where the env type is not equals to pro enter. So this is what 4:51:18 exactly is this? This is equality based selector. And if I want to list all the parts which are of environment equals to prod here you can see part two and part 3 is listed. Right? So what it exactly it is it is a type of selector and the one that I demonstrated right now it is equality based selectors. Now let us move forward with the next one that is set selector. Now what are set selectors? So it will select the pods where uh like we can just run a sort of query. If you're coming from MySQL background, it will be very much easier for you to understand this. If not, I will show you how does it works. Right now let's say if I want to list down all the pods, let me first list it first with the labels. Okay. Now let's say if I want to list down the pods where the env is de or QA, how I can do it? So I will just run cubectl get pods. Okay. and list the ports where the environment 4:52:21 okay is indev comma qa enter and here you can see the result is listed what is exactly it is it is a set bait selector right it will select the parts where the environment is dev or qa so if you see env over here is dev and that's the reason it listed the pod pod one here. Right? So that is uh the beauty of selector the type of selector that we run right now. Now second is uh let's say if you want to select the pod where it has uh any value except uh like the mentioned one right so let me just check uh other labels too. Now let's say we want to uh find the pods where the env is has any value except dev. How do we do it? So let me clear the screen and let me just 4:53:22 uh list down all the parts. So cubectl get pods hyphen show labels and okay let me just correct the spelling. So it is cubectl cubectl get ports hyphen show labels. Now let's say let me take you another example where I want to show you one more method. So let's say if I want to make use of not. So I just want to list down all the pods where the value is not equals to div. So I will make use of cubectl get pods l where the env is not in. I don't want uh the pods where the env value is dev or it is test. Okay. Now after this I will press enter. And here you can see it only printed those pods where the environment value is not de or test. Right. This is nothing but set base selector. So set based selectors are useful when you want 4:54:23 to target a group of values not just a single one. Right? Now let us uh do one more thing. Let us go to the documentation and here you can see we have covered selectors to type of selector right. So now let us see labels and selector together how do they work. So let's define two pods uh and one service and see how labels and selectors collect them. Right. So I will go back to Visual Studio Code and here I will create another folder over here. So this would be for label labels and uh selectors demo. Okay. And here what we will do we will create two pods. So pod one do yiml enter again pod 2 do yiml and there will be one service file. So service do yiml enter. And now what I will do, I 4:55:24 will just open the ones which are of use. So I'll just close all the other tabs. So close all. And here I will just open the manifest file which we will be using pod 2. And third is service.ml. All right. So let us create pod one. So here let's let's be quick this time. So here API version meta data and spec. Now here we are going to create a pod. So the API version for pod is v1. How do I know it? Basically I made use of API resources. Now since I have been doing it from very long I understand what should be the value. Then pod will be the kind for it. Metadata again I will define the name of this pod. So let me give this uh name as front end. Front end dev will be the name of this pod. Along with that I will utilizing the power of labels. So labels labels 4:56:27 colon enter. And here I will define app is equals to web and the env will be development. Okay. And in the specification I will define the containers. And here uh the container that I will be using is uh the name would be enginex engineext. And the image that I will be using is image engineext. One second engine x colon latest. This time we will make use of latest. All right. So this is the pod that we were we are actually creating and uh the name of the pod is uh name of the container will be enginex and the image that we would be using is engineix col. All right hope that made sense. Let me just verify the file whether it is created correctly or not. I will go inside the folder clear cube ctl apply apply f pod 1L and yeah it is correct. I will copy the entire pod one and I'll 4:57:29 paste it into the pod two. The only change here I will be making is instead of dev this will be for prod and here I will change the environment to prod and the image let's keep it same as it is. Now let us create service. So how do we start with again API version kind meta data and spec okay now the thing that I'm creating is a service so here oops okay spec all right so the client will be again service and here I will be uh getting the information for API So cubectl API - resources resources and I will run a grap on service. So service enter and here the API version for service is v1. So apart from that I 4:58:32 will give one space. Here I will define the metadata for that service. So I will define the name. So it will be a front end service. I will write it as I will give it a custom name. The front end dev service where the specification uh of that service would be we are going to create a selector right labels are defined in the pod manifest and selectors are defined in the services. So selector and here we would be selecting those parts where the application will be uh given the value as web and the NV should be of dev and it should target only those application where uh sorry and this service will be running on port number port 80 and the target port is target port is again 80. Right? So here 4:59:32 is what happens. So front end dev has labels app web and env equals to dev. In pod 2 we have front end prod which has the labels app web and env. Right now what exactly service.myamel does? So what it does basically uh 5:00:12 yeah I think there is a typo that's the reason it is throwing a red line. I need to just correct the indentation. Here it goes and now it is correct. Okay. Now what it does basically here we have front end dev service and it select the pods with the label app equals to web and uh env equals to dev. Right. So this is a simple but powerful pattern for separating the environments. Right? Now here uh we have metadata dot labels. Now when I say metadata dot labels I'm talking about the labels over here. Okay. So this is where the labels live. Labels are not unique identifiers. They are the descriptive tags. Now whenever I'm dealing with spec dot selector, whenever you get something like spec dot selector, spec dot selector, we are talking about this. So this is how controllers and services discover matching object. So a selector only matches when all the required label conditions are satisfied. So now imagine you have hundreds of pods 5:01:14 running inside the Kubernetes and some are front- end service, some are backend service and some are the database services. Kubernetes needs a way to identify them and it doesn't use the pod names. Why? Because the name can change. If you delete a pod, it will respin again but again the signature will be changed. So basically the ideal thing is to make use of labels. Now we already saw uh we have two sort of labels which we have added into manifest file in pod one and pod two app web and env. And here we have appdev and env right. So a label is nothing but a key value pair attached to a cubernetes object that we know right now. So let us do the hands-on. Let us apply the changes from these manifest file. Clear. And here we have pod one pod 2 yimml. So I will write cubectl apply - f pod 1 dot yl and pod 2.yamel. Enter. Okay. So I think it 5:02:17 will just take uh one at a time. So I will just write pod 1.l. Okay. Front end is created. And here when I press pod 2.l it says uh pod 2 is created. Here it says uh front end dev unchange meaning that pod might be present already. Let me delete the pod first. So cubectl delete pod followed by front end dev. Let me just remove it from here. Okay. So it is deleted from the default name space. And now I will create part one. Okay. Now the next thing is let us see the label. So cubectl get pods hyphen - show hyphen labels we'll get a detailed view of the pods that we have created and here just focus on front end dev and front end pod where the uh labels that we have is app is web and environment is from development and prod right so this is the output that we 5:03:17 get so notice that kubernetes is storing labels uh along with every part right so kubernetes is actually storing uh the labels along with every port right so this is how we saw the labels so these labels are nothing but the metadata I am again repeating it labels are nothing but metadata so they don't change uh even though how the pod is working they simply describe the pod right now let's say if I do if I want to do the filtering so I will just make use of cubectl get pods and list the pod where the environment is equals to dev enter. And here you can see we have front end dev pod and we have pod one where the label stands for pod one equals to dev where the environment is dev. And again we have front end development uh pod where again the environment is dev right. So again let us do one more hands-on. So let's say I want to see all the pods where the environment is production. So I will run 5:04:18 cubectl get pods and list down all the pods where the environment is nothing but the production environment. Enter. Here you can see all the pods where the environment is production is listed over here. So here you can just revalidate it. So port three contains of environment pro. Pod two contains of environment pro. Again front end prod contains the label as env equals to pod. Right here you can see all the pods appear and here we did a filter on pod with the help of labels. Right? Now let us go to services. We created a service manifest file and right now I am aware uh I'm sure that you all are aware of the service file and what exactly is it does what it will does. Now I have one open question for you all. Uh can you tell me which part do you think that this service will try to connect to? Now based on this label do you think which part it will connect? It will connect to pod number one where the app is equals to web and the 5:05:19 environment step. Right. So uh let's get started. So what I will do? I will just apply the service manifest file. And how will I do it? Let me first mark it as full screen. Clearing the screen. And now let me just apply the service file. So cubectl apply - f services.ml. And here it says the services created. Let me just list the service. So cubectl get svc or service. You will get the services listed over here. And here you can see front end dev service. The service that we created is listed over here. And where it is getting the name from? It is getting the name from the manifest that we just created. Okay. Now let's move forward. Now let me just describe the service. And that is how we will know which pod it is targeting to. So cubectl describe service or svc followed by the service name. And when I press enter here you can see here it has the selector where the application name is web and the 5:06:19 environment is dev where it is getting the data from. It is getting the data from again from the manifest that we just created. Right. And here we can see the endpoints too. Here we have the endpoint and it is targeting to those uh pods where the values where these keys and values are present. So service will automatically find the correct pod. Right? Then the question is why didn't it took odd two? The reason is here the label is not matching because env is equals to prod right. But in the service we defined only to target those manifest only to target those parts where the environment is development right where the environment is uh development right. So that was all in this video. I hope uh you got to learn about labels and selector in depth. So without changing the pod names and without restarting anything Kubernetes can automatically start and routing the traffic to another 5:07:20 top another pod. Why this can be done? This can be done with the help of labels and selector right. So think of labels like tags on people at a conference. So one tag says department uh where the department can be HR and uh another says department as engineering. So if someone uh call for if someone call for engineering and I don't I won't be calling them by the name I will simply look for their tag. So Kubernetes will just uh do the same way here. Uh here basically service deployments replica sets and other objects won't uh identify them with the pod name. They will identify them with the labels and the selectors that they are using. Right? So yes, let us take a recap and here I will wrap up then uh I'll go to the repository that we have created. So what we have learned so far. So basically uh labels are the key value 5:08:20 pairs attached to Kubernetes object. Selectors are those labels uh where selectors uh use those label to find uh the group of resources. services and replica sets basically are dependent on selectors to connect to the right pods and good labeling makes your cluster easier to manage and basically that's the reason that you should have right uh and another what's the best practice with the labels and selector so it should be meaningful and it should be consistent for example application for example env for example ro or it can be version uh keep the label stable and avoid changing the labels labels frequently on the running resources. Uh use the labels for grouping not for identifying a single unit or a single object. Separate the application identity from the running information. Uh for example, app equals to web or env equals to prod. So these are better than 5:09:20 app equals to web hy-en. Right? And last but not the least very important very underrated that is document your label scheme for the team so that if a new guys join to your team it won't be any issue for him you will have everything documented and that's the reason uh labels and selectors does the job right so yes that was all in this video where we learned about labels and selector we not only just did the hands-on we visualized it we lived labels and selector and I hope that made sense to you so yes that was all in this video and I will see you in the next one. Until the next time, keep learning. Thank you very much. Hey everyone, welcome back. In the previous video, we learned about labels and selector and I'm pretty much sure that you have done your hands on with both the method that is the command line method and the manifest method. Right? In this video, we are going to discuss one of the important question and that is nothing but if you already had Paul then why do we need deployments in Kubernetes? Now in order to understand 5:10:20 deployments in kubernetes we need to first visualize the problem statement what was the problem that we were facing right so now imagine that you have an engine f which is perfect right now due to some reason your pod crashes down now what will you do you will take ssh into the cluster and you will spin up a new pod but will you do this every time second is now what if I ask you to create five pod because of the traffic increases will you again do this manually? Now the third and the most important is if I ask you to update the bot right without the downtime how will you do it. So basically these were the issues that we were facing with pods and deployment have that solution. Now basically we are already aware of the nature of pods. Pod is ephemeral in nature. uh when I say ephemereral ephemeral meaning if you delete that pod the IP will change and the object associated to that pod is gone right and also pod is not capable of self-filling 5:11:22 scaling and upgradation that's is something that has been provided by deployments in kubernetes right so that is something that we were facing with ps and the answer is provided by deployment itself now let's do the hands-on because that will give you the complete clarity now you imagine now you have already visualized the problem statement and now we are going to proceed forward with the solution. So on that note let's get started with deployments in Kubernetes. All right. So let's get started. So before we proceed forward so everything that we are going to discuss today is already been documented in sub repository number eight that is deployments in Kubernetes. So feel free to check out that and let's move forward with the problem statement itself because we already have covered the theory part of it. So for that I will be using the terminal that I have because till now we have been making use of visual studio code because uh and that's actually a good practice when you're starting learning you will get some help and I why I'm specifically moving to terminal is because maximum time you 5:12:23 will be interacting with this command line so you should know how does things look and feel like. All right on that note let us uh replicate the problem statement. Now what was the problem statement? It was like the pods are ephemeral in nature. So whenever they are deleted we will lose the IP and we will lose the object associated to it. So let us create. So cubectl run uh name of the pod that is demo pod demo pod followed by image and image is nothing but engineext latest and this will run on port number 80. So port equals to 80 and when I press enter here it says demo pod is created. So cubectl get ports and here you can see demo port is up and running. Now what will happen if I delete this part. So cubectl delete port followed by the port name that is demo port. Now when I run cubectl get pod my pod is deleted and what it says no resource found in the default name space right which shows 5:13:24 that it is gone forever unless and until we create it manually that was the issue that we faced with pods. So the thing is now let us imagine that uh you are working in a company and there are there is a new intern who joined and accidentally he deleted it right how will you get that back so that was the issue right so that is something that has been solved by deployment now what exactly is deployment we understood that deployment is a higher level Kubernetes object that describes the state of the desired state of that application let me take you through the documentation what is a deployment deployment is nothing but a higher level of Kubernetes object that describes type the desired state of the application. Now what does it declares? It will basically tell which image to run. It can be engineix. How many replicas do you want to create? So basically for this we have something called replica set within deployment that takes care of the number of desired count. Let's say if I want to run five uh pods, right? So we will just tell replicas to replica set to create the five pods and it will actually make sure 5:14:24 that that five pods are up and running. Third is the update strategy. So it will tell like what sort of update strategy do you want to follow? Do you want to follow rolling update or anything and last not but not in the least labels and selectors. So basically here uh we have a complete control on which part we are targeting to right. Kubernetes continuously works on keeping the actual state by matching the desired state. Now what exactly are we declaring over here? Basically we are declaring that which image we want to run how many replicas we want, what is the publish strategy and last is labels and selector. Right? Now in reality in simpler words what exactly deployment tells to Kubernetes? Deployment tells Kubernetes to run that specific app keep the three copies and if one fails create another and update them gradually. So these were the answer that is been provided by deployments and this is something this was the challenge that we were facing. If the product crashes who will take care if the traffic in uh increases who will make 5:15:26 sure that replicas is created if you want to update the application who will uh take care of the downtime that has been taken care by deployment itself and now I hope that the picture is clear to you and here let's move with the deployment architecture that will give you the complete idea how does deployment works. So what exactly deployment does? Deployment will manage your replica set and replica set will make sure that your pods are running right. So here deployment will manage your replica set and your replica set will ensure that the correct number of pod exist and pod will run the actual container. Right? Now in order to understand this relationship let us take an example that you are in an restaurant. Right? In that restaurant uh customer are nothing but the request. Chefs are nothing but the parts. Restaurant manager is nothing but the deployment. Now if due to some reason the chef leaves, the manager will hire another chef. Right? If the restaurant is busy, what will the manager do? He 5:16:28 will add more chefs. And what if a new menu is introduced, right? Then in that case, manager will update the chef one by one instead of closing the restaurant. that is exactly been done by deployment itself. Right? So let's get started. Let us start with the actual practice. Right? So on that note, let's go to the command line and let us explore deployments. Right? Now let's say if you want to create a deployment uh in command line how will you do it? Basically you will run the command cubectl create deployment. Create deployment. Right? And the name of the deployment. So here I will write engineix deployment. Now for in order to create that deployment we will need one image right so I will pass the image name so hyphen image equals to engineix colon latest right and now since we are dealing with deployments we need to pass the replicas right and that will be something that will be taken care by the replica set so replicas and how many replica do you want so for now I just want only two replica when I press enter here what it 5:17:30 says deployment app engineix deployment is created all right that's cool so let me just list the deployment right so here I will write cubectl get deployment or you can even write deploy here you can see we have engineix - deployment present in front of us now if I want more information about it I will just pass hyphen o wide and here it will give me more information now what more information I will get the name of the container I will get the name of the image I will get the selector information right so that sort of thing we get over here now since we are dealing with deploy deployment I mentioned that we will be dealing with replica set. Now what replica set does basically it will it will make sure that the desired number of application are actually been up and running right. So in order to list the replica set I will run cubectl get rs for replica set and here you can see replica set is present. There is one observation over here right and that is nothing but in the name of replica set. Here you can see the 5:18:31 replica set is the combination of the deployment name plus one hash. Right? Now what will happen when when I run cubectl get ports. Here you observe one more thing ports is also a combination. Right? Here it is a combination of your deployment name. Basically it is a combination of your replica set and n hash right. So what it does basically it proves the ownership change. Now what is the ownership and the ownership is nothing but deployment manages replica set. Replica set manages pod and pods make sure that the actual containers are up and running. Right now let me show you the actual skeleton of deployment. Now if you remember I have been telling you from demon itself whenever you want to create any sort of manifest in Kubernetes the four important blocks are nothing but API version kind metadata inspect right this is something that we will be dealing with every time but since we are dealing with deployment we will need to add more characteristics so 5:19:31 that is nothing but replicas selector templates and container right now what exactly API version it actually tells uh the API version for the deployment resource. What exactly kind does it will tell Kubernetes what sort of object we are trying to create. Metadata basically it will consist of the name of your deployment the labels specification it will contain all the template the replicas your containers the image everything will be present over here. Now since we are talking about spec we will need to pass replicas and since we will be dealing with labels we need to define what sort of pods we are targeting to. That's the reason we are defining selector over here and here we are defining the template for which uh the replicas will create the multiple copies and that is how the deployment in cubernetes looks like. So let us replicate and let us create deployment in command line. Let me clear the screen and here let me just create one file. So vim deploy or let me just write 5:20:33 engineext - deploy. This will be the name of the manifest file. Now the first thing is let us start with the very basics. So whenever we are creating any sort of YAML in Kubernetes the first four building block the skeletal that we need to write is nothing but API version API version kind metadata and spec right so right now think that you don't know nothing right and I'm not sure uh what sort of API version I will be using. So escape colq I will make use of API resources. So cubectl API resources and when I do a grap on deploy here you can see the API version here is app/v1 till now what sort of resources we were creating the API version was nothing but v1 but here it changed it changed to app/v1. All right let me update the same over here. So API version I give one 5:21:33 space and I will just paste the API version that is nothing but app/v1. What is the kind here we are trying to create the deployment. So here I will define uh the object that we are creating and that is something that will be notified to kubernetes. So deployment. Next comes the metadata. Now here I will define the name of the deployment uh within the name space. So I will just write name and what would be the name of this deployment? The name of this deployment will be let's say engineix- deployment deployment. Okay. Now the next thing uh since we are dealing with deployment we want to target a specific words right for that we need labels and selectors. So I will define labels over here. Labels enter. Now what are those labels right? Uh what basically this label will do? Label will attach to label will get attached to this deployment object for organizing and filter right and here I will write app space engineix. Now what it will do 5:22:37 basically this is a key value label which will be identifying the deployment as engineext. Right now we are done with API version kind metadata. Now let's move forward with spec. Now let's say if you wanted to create any sort of pod right in Kubernetes uh till now we have been updating the spec section where we were creating the containers. Let us do the same because this will give us a complete idea. Here I will write container and here I will pass the image name. So container and here is goes the im name of the container. So what's the name of that container? uh the name of the container will be enginex - container and here I will pass the image and image will be nothing but enginex col right these are the thing that we have been passing and last is what port it will work on so ports and here I will define the container port container 5:23:39 container port and the container port is nothing but 80 so this port will be inside the container And that is nothing but enginex default port. And what this port expresses basically this port uh is something that will be exposed by the container. Right? Now since we are dealing with deployment, this things are not sufficient enough. Right? We need to pass more details. Now if you remember the commands that we executed earlier, we passed the replica account where we defined it over the manifest that will go into the specification section. So here I will give one space and here I will define the replica count. So replicas replicas and I want let's say I want five replicas right I want five copies of it but on what basis you are targeting it so that's the reason where we will be making use of labels and selector here I will write selector selector right and in the selector I will ask him to match the label so match labels now 5:24:40 basically it will match the part based on this label now what are those label it is nothing but apps colon engine x right this is something that we have been using from the starting itself. So app colon engine x right so now we have the replicas we have the selector and we have also mentioned the match labels that will take care of matching the uh labels with match these are the selector basically it will make sure that the labels has been matched right now since we have created entire thing we need one more thing now see this container this pod will be created for a single pod we will need a template for creating the replicas too right and that's the reason we will define and the templates too. So here I will write template template and inside that template we will pass one metadata. So meta data and this metadata will be for the ports and here in this uh basically we will mention that target only those pods where the labels are matching as 5:25:42 engineext. So here I will define the labels to labels labels and the label would be app colon engine x right now inside this label what we are going to do is we are going to pass this specification for the container right and here on this place we will define the spec and here inside the spec we will pass the container information. So here here it goes like this and I hope this will make sense to you. Now don't worry we are going to break down each and everything. So everything will go inside your head and you won't be getting confused right. So till now this is the biggest manifest we have written so far and I believe it might be confusing but don't worry I am going to explain you each and everything but before even that let us first apply the manifest file cubectl apply fenix engine deploy and here we see a big error right and now this is something that we need to troubleshoot right so 5:26:43 let us first do the troubleshooting part and then I'll explain you the entire in a correct manner so the issue is with nothing but with the indentation. Right? And that's the reason why we chose uh Vim editor because this is something that we would be facing frequently. Right? Here the issue is here it says unknown field spec.spec. Right? So there is an issue with the indentation. Now let me just first let me just show you on Vim editor. Okay. This is the deployment file that we have created. And the issue over here is with this spec, right? And here it says the indentation it falls inside metadata. Right? Specification is configuration. It will never fall inside metadata. It is at same level as that of your metadata. When I go back, I will just clear the screen. And this time what I will do, I will just apply the cubernetes manifest file. Cubectl apply - f engineext deployment. ML and here you can see engineix deployment is created 5:27:46 and it is up and running. Right now let me just explain you each and every line. For that let me just go to the VM editor and engineX deployment. Okay. So let me explain you each and every line in detail. What exactly is API version? Here API version will define the deployment resource type. Right. Second is the kind that is deployment. It will tell the cubernetes that what sort of object we are creating. Third is metadata. So it is the metadata about the deployment of the about object itself not about the pod. Secondly here we defined the name of the deployment. It is the unique name for this deployment within this name space and that is nothing but uh default. Then labels basically it will uh attach a label to the deployment object for organizing and for filtering. And here we define the actual label that we were targeting to. Then third and then the fourth one is spec. It will define the desired state of the deployment. Then 5:28:47 the replicas. Here we mentioned we want five replicas. It will uh define the number of pod copies that Kubernetes should keep up and running all the times. Then here we have nothing but selector important component. It tells the deployment which pod it owns or manage. Then we have match labels. It will match the pods based on this level. And here we define the labels that we are targeting to. Now let's move to template. So it is the blueprint which is used to create every replica for that specific deployment. Now here we have again one more metadata. Now what this metadata does, this metadata is applied to each pod and it is created from this template. The template that we just created, right? And in that template we are mentioning that we have labels app colon engineext that you have to make sure that you are adding when you are creating and the specification. Now this is the actual pod specification same as the standalone pod that I created earlier. And here we have specification for the container which consist of your name, image and port number. And that is 5:29:48 how we created the deployment manifest file. Right. Let me go out from the screen. And here uh we have created the deployment right now how do I list the deployment. So basically for that you will just run cube ctl get deployment enter and here you can see engineix deployment is up and running and here there is one more thing that is running at the back end that is nothing but replica set. Now what replica set does it make sure that the replication count is been matched that is the current state and the desired state is matching. So for that cubectl get RS for replica set and here you can see five pods are up and running and when I do cubectl get pods here you can see five engineix deployment pods are up and running right now issue with pod was if I will delete any pod from here it will be gone forever but here it's not the case with deployment even if you delete either one of the pod it will spin up another part 5:30:48 if you don't believe me let me just delete one part so cube TL delete pod followed by the pod name and here it says the engineix deployment pod is deleted from the default name space and here you can see there is five pod 1 2 3 4 5 right now it should be four after deletion of this pod right so when I do cubes it will get pods here you can see again a new pod has been spinned up and that is nothing but this new one and that's the beauty of deployment right there is one more thing one more observation which I wanted to tell you and that is nothing but the chain between all of them. So here you can see the name of deployment is nothing but engineix deployment and here when it comes to replica set here you can see the name of deployment plus one hash and when it comes to pod you can notice one more thing we have the replica set name over here along with hash. Now what it denotes basically it denotes the chain the relationship between the deployment 5:31:49 replica set and port. So deployment basically manages your replica set. Replica set manages your pod. And pod is basically where your containers get executed. Let me clear the screen. And now let us understand one of the important concept in deployment. And that is nothing but describing the deployment. Right? So let me first list it. So cubectl get deploy and here we have the deployment. Now let me just describe it. So cubectl describe deployment followed by the deployment name. Now see this is one of the most important thing and you have to pay attention because this is something that no one will teach you right and this is something that contains maximum number of information right and since we are talking about deployment itself I wanted to cover this in this same video so that you can get maximum out of this video right so the command that we made use of is describe now for what describe is used 5:32:51 for describe is basically used to get additional information about that board or any sort of resources, right? So let's start and decode each and every line. So let's start with the first line name. So what exactly it says? It is the name of the deployment object. What is the name of the deployment? It is nothing but engineer deployment which we actually created. Now second we have name space. Now since we def since we didn't define any name space, it took it into the default name space. Right now, creation time spre time. It will tell you the exact time and date when the deployment was created. Now, here it says witness day 22 July 2026 and this is the time and here if I go here I can show you exactly it's July 2022. Right? Now next it comes to labels and here you can see uh it will tell uh labels attached to the deployment object itself which is used for organizing and filtering which I told you earlier also annotation. Now what exactly is annotation here? It says 5:33:52 deployment.cubernetes.io/revision 1. So basically Kubernetes automatically adds this to keep the track of revision number. It is uh basically use uh used internally for rollout history. That is something that we are going to see later. But for now just uh keep in mind that it tracks the revision number which is used internally for rollout history and roll out and roll backs. Right now let's move forward with selector. So what exactly selector does? So it is the label uh the deployment uses to find and manage the pod. It must match the pod template labels. Right? And that's the reason selector is created. So next move forward with replicas. So here it says desired five updated five five total five a uh five available and zero unavailable. So here uh desired meaning it says what you asked for and that is nothing but we asked for five pods. Then second is updated how many uh are 5:34:52 running to the latest version that is something that it says uh five total that is all pods that exist right now. Then available basically it denotes that pods that are handy and ready to serve the traffic and last is unavailable. So it is it says the part that are missing and are not ready right when it says zero uh basically everything is good right let's move forward with the strategy type here it says rolling update right so it confirms that pods are uh replaced gradually during the updates not at once so this will avoid the downtime so that's the beauty of using deployment and rolling update if you are thinking what exactly is rolling update so just like instead of deleting all the pod at once. It will spin up a new pod and like you will be actually reducing the downtime. Right? Uh basically we are going to discuss rolling update in detail later. For now just understand that it's a kind of method through which we uh do the 5:35:53 updation. Right? Next is minimum ready second. Right here it says how long a new pod must stay healthy before it's considered as ready. And here zero means it's mark ready immediately once the status check passed. Right? Now list is rolling update strategy. Here it says 25% max unavailable and 25% max. What is the meaning of this? So uh when we say 25% max available the meaning is during an update at most 25% of pod can be down at once. Now when I say 25% max search, what it says? At most 25% extra port can be created above the desired count during an update. Right? That's the meaning of it. Now let's move forward with the port template. This is something that we defined in the manifest itself. So below is the exact blueprint that we use to create every pod. So here we have the very first thing that is nothing but the labels. So labels that get attached to every pod uh which are created through this template. 5:36:53 Second is the container and inside the container we defined the name of the container that is nothing but enginex - container and for that container what image we used basically we made use of engineix latest what port it runs on it runs on port number 80 and let next is host port basically uh the actual actual physical node uh where zero means it is mapped to nothing normally it is used in deployments and host networking setup Next is environment. So it says none. So basically no environment variable was set for this container uh for this part. Next is mounts. So basically no mounts were present over here. That's the reason we are getting none. Same goes for volume node selector tolerations. Right? Now what exactly is toleration there? So basically here what it says basically no special permission was needed to run on this tinted nodes. Right. Let's move forward with the condition. So what exactly does this denote? So it uh Kubernetes internal 5:37:54 health checks for this deployment that is something that has been defined though what exactly is the meaning of available right? So here it says available is true what's the meaning of it so it means that enough pods are healthy and serving the traffic. Now let's move forward progressing so when uh it says progressing it true basically it means that uh the deployment successfully rolled out the new replica set without giving the stuck. Third is old replica set which is again set to none. So it signifies that there is no leftover replica set pre present from the previous update. It is a fresh deployment. Next is new replica set. Uh so basically it's the current active replica set name and confirmation for all the five desired pod that were actually created. Now event basically it's the time lock for the deployment controller that whatever things are happened actually happens in the environment section. Right now here you can see again we have something called normal scaling replica set the age. Right. So what it says? So how do we 5:38:55 read the event? So basically just like uh 5 minutes 16 seconds ago deployment controller scale the replica set name u engineext deployment and it scaled it to five. So this is how we read kubernetes and that is how kubernetes work automatically. Right. So I hope in this video you learned about how you can create manifest file. How do you learn about describe? That is something that we learned today, right? So far, now let me go back to the screen and this is something that we have learned so far. You can feel free to go and go through all the documentation because that will give you a complete idea. Now let's say uh during one upgrade someone asks you to update the port. How will you do it? Basically, it's simple. You can just go to the manifest file and update the replica count to maybe from 5 to three. Now let's say if you want to scale the deployment directly without even going to the manifest file. How will you do it? Basically you will what you will do 5:39:55 first of all you will list the deployment. So cubectl get deploy and right now 1 second it is deploy. And right now you can see it is uh five parts in total. And now I need to scale it down to two. How will I do? So basically I will write cubectl scale followed by the deployment name deployment followed by engineix deployment and here I want hyphen replicas equals to two enter and here it says replica here it says deployment is killed. Now when I run cubectl get pods and here you can see only two pods are up and running. So this reduced the replicas and that's the basic explanation of everything right. So with deployment it becomes very much easier to manage the pod because why uh because a replication set comes into the picture 5:40:56 that helps us in managing all those part right. So let us take few interview questions because that is something that will give us the idea. So the first is why not to use pod directly right. So let me just explain you here. I have provided a single liner but I want to explain you in detail. So just listen to me. Why not to use pod directly? So if you create a pod by itself and it crashes so it is gone. Nobody can bring it back. Right? You have to notice it uh why it is down and recreate it manually. Right? So you also cannot uh easily create five copies or you can update the application without downtime. A part alone is just like a single worker with no manager watching over him. Right? So that that's the first thing. Secondly is deployment versus replica set. So in order to understand that so think of it as two layers replica set the job is only to uh make sure the headcount is present. It makes that the right number of pods are running nothing more. and 5:41:58 deployment sits above it and add smart features like rolling updates basically changing the app version without downtime and roll back undoing the bad update. So in short replica sets uh counts the pod and deployment manages the whole life cycle. What uh what sort of rolling updates do we have? What exactly is replica set? We are going to cover in the coming videos. For now that's the difference between deployment and replica set. In order to uh understand this go through this visualization. This will give you the clarity. Deployment manages the replica set. Replica set manages the pods and pods actually runs the actual container. Let's go with the third question that is what happens when a pod crashes. So the replica set is always watching. It knows I am supposed to have three pods. The moment a pod dies that number will drop to two. It immediately will create a new one to bring it back to three. So this happens automatically within second and there is no human intervention required in between right. So what is the meaning 5:42:59 of desired state? So it's simply that you wrote in your RAM file as I mentioned earlier I want five replicas of engineix latest that's the desired state. So Kubernetes will keep checking the real uh the current situation in the cluster and it will keep nudging uh to make sure that whatever you ask for it is able to deliver it. If uh the reality drifts like if a part dies or someone deletes something, Kubernetes will fix it automatically. This constant checking and uh fixing loop is nothing but reconciliation and that's the reason it makes sure that the desired state has been matched. Now let's uh move forward with the last question that is nothing but how does the rolling update work. So uh this is something that we can cover in the coming video. For now just remember that uh uh when a new replica set is created uh the pods are replaced gradually based on the max search and max available while old replica set scales down. So 5:44:00 basically when you update the image version Kubernetes doesn't kill the old pod at once uh that would cause the downtime. Instead what it will do it will create a brand new replica set for the new version and slowly it will shift the traffic over to it. So what it will do it will spin up new ports and that has been controlled by max search. It will wait for them to be ready and then it will remove few older pod that has been controlled by max unavailable. Right? So it repeats the cycle until all the pods are running to the new version and user never notice a gap in the service. So let us take a recap what exactly we learned today. So pods run container replica set maintains the replica account deployment manages replica set and it provides scaling self-healing rolling updates and rollbacks. So at the end what conclusion we came with is deployment are one of the most important Kubernetes resources for running the application reliably into the real one environment. So yes 5:45:00 that was all in this video. I hope you got maximum out of this video and uh don't worry whatever files we created I think we just created only this single file I will directly push into the GitHub itself. So I'll just put push it right now. So get addit commit-m enginx deployment example get push. All right. So I have already pushed this file into GitHub repository and you can directly go and have a look inside it. So yes that was all in this video and I will see you in the next one. Until the next time thank you very much and keep learning. If your pod crashes right now in a Kubernetes cluster, how will you bring it back? Now, most of us will say that Kubernetes will automatically bring it back. Well, that answer is wrong. A pod cannot bring itself back by its own, right? Hi, my name is Shubam and in this video we are going to discuss about replica sets and deployment, the 5:46:01 differences between them and how they both work together. Also, we are going to see how rolling updates are being performed, how do we perform holdbacks. This will be a complete hands-on uh demonstration. I would request every one of you to go through the video once and do the hands-on. I will emphasize on it again and again. Please perform the hands- on because by just watching the video, you won't get maximum out of it. Right? So, it's my personal recommendation. After watching the video, try to do it by your own self. If you face issue, let me know in the comments. I will be very much happy to help you out with all of your issues. Right? So yes on that note let's get started and understand why we consider deployments in production and why we not consider replica set and what's the importance of replica set and deployments. So yes let's get started. All right so before we move forward just a quick note that whatever things we are going to learn today is documented on subreository number nine. So feel free to check out the same where you will find in depth detail about replica set 5:47:02 versus deployment. So instead of going directly and directly jumping into replica set versus deployment, let us first understand why there was a concept, why there was a need for replica set and why we are using deployment in the very first place, right? Uh so for the same uh let us go to excal and let's imagine that you are running an online website and your app is running inside that pod. So here you can mention like this is the user who is uh basically using your website. Okay. And let me draw another box. And this is the pod that has been used by that user. Okay. And here I'll just point it that here it is been accessed by that specific user. Okay. So the thing is uh let's imagine that you're running uh an online shop. It can be anything. And your app is running inside this pod, right? And what runs inside the pod? Yes, you are correct. It's nothing but a container. So so far so good. Everything is working fine. Now imagine that due to some 5:48:04 reason this node get crash. Okay, this this this is uh no more yet right or someone actually accidentally deletes it. Now what the pod is gone now one simple question is who will create it again right? Answer is nobody. Right? A standalone pod cannot create itself. Right? I repeat a standalone pod cannot recreate itself once it is deleted. The nature of pod is ephemeral meaning they are temporarily they are disposable resources by design. So basically that is not a bug that is how cubernetes was built right. So let me just show you how things actually work like I am already pretty much sure that you have already gone through it. So let me just show you how things work over here. So right now I have splitted the terminal into two section just to show you a demonstration that you'll get in some time. But let me show you first thing that how do how do how do we come to a conclusion that pods are ephemeral in nature right. So let us 5:49:05 create one pod. So cubectl run uh name of the pod. So engineix - pod and followed by the image. So image equals to engineix engineext col. And here uh the pod name engine pod is created. All right let me run couptle get pods. And here you can see engine pod is up and running. Right? Now the thing is as I mentioned pods are ephemeral in nature meaning once you delete that uh we cannot recover it back. The only way to recover it basically is just to create it once again. Right? And the second thing is if we delete the pod uh who will recreate that pod right now in the current setup no one will create it uh because it's it's by design itself right that job is been done by someone else and who is that someone else we are going to discuss in the same video. So let me delete this part and let us see the observation what actually happens. So couputle delete pod followed by the pod name that is engineix hyphen pod. And here what it 5:50:06 says engineix pod is deleted from the default name space. And now let me run couptle get pods. And here you can see no resources found in the default name space. Now if I again run this command, it will again show that no resource found in the default name space. When I again run this command, I'm getting the same result. Meaning we came to a conclusion that pods are ephemeral in nature. Once the pod is gone, no one will create it. Right? A standalone pod cannot recreate itself recreate itself. Pods are temporary. They are disposable resources which comes by design and this is not a bug. That's how Kubernetes was built. Right? Now think about why this matters. Right? Now let's take an example of uh let's say Amazon or maybe Netflix. Yeah, Netflix will be a best example. So if their application goes down every time, right? Uh if their application goes down every time one pot 5:51:06 dies, then there will be hundreds and millions of angry user who will be like uh unsubscribing from their platform, right? And the result would be there will be a loss of revenue, right? So we need something that can constantly watch our pods and fix the things automatically. That's exactly been solved by the things that we are going to learn today and that is nothing but replica set and deployment. Right? So let me go back to my excelling that pods are ephemeral in nature. Right? Let's cover replica set first. So in order to understand replica set, imagine that you are in a classroom and the students are nothing but your pods. If the teacher isn't watching then student quietly can leave the uh class and nobody notices it right we all have done it so we can uh really much uh relate with it okay so uh let's say due to that the class teacher appoints 5:52:06 monitor and the moment someone try to skip from the class someone tries to bunk the class the monitor notices it and calls them back that exactly has been done by replica set Right. So uh if someone ask you what exactly is a replica set? So replica set is a cubernetes controller. I repeat replica set is a cubernetes controller. Uh so basically what's it job? It job is to make the make sure that the desired number of identical ports are always running. It constantly basically it will constantly ask two question how many ports should exist and how many ports are actually existing. Right? So if those number doesn't match it will fix it immediately and it will be automatically without any human intervention. So let us take the same example let us recreated with the help of replica set right. So what will happen if replica set comes into the picture. So let's say here is the user who is trying to access the application but just before it let's say these are the three pods these are the desired 5:53:07 state that we want okay and here I have pod one pod two and pod three but just above this layer there is one thing which we call as replica set which will fall over here okay let me just move it over here so this will be nothing but replica set okay now what is the functionality of this replica set basically it will constantly keep a count that basically it will just check uh whether the desired number which is three is actually present or not. If the number is two just like you saw right now the pod is deleted it will make sure that another pod will get spin up which was not possible in the setup. Why? Because pod is ephemeral in nature and that is something been taken care by replica. Replica said uh definitely added a lot more advantage uh when it comes to uh self-filling and yes uh this concept is nothing but self-filling right uh one more important point replica set does not run your application your application is again uh 5:54:08 executed by your pod itself right so it is managed by your pods and like if you delete pod two right now the replica set will notice so let's say if I delete pod number two right what will happen replica set will notice that okay there is uh some change in the behavior and then it will try to create the pot once again and this behavior is nothing nothing but self-filling so keep that word in your hand we'll come to that later in this video okay so that is something that has been done by replica set now the theory is done let's try to build an actual replica set replica set is a very important concept so let's get started with it but before we move forward. There is one more thing that I wanted to tell you that whenever you are dealing with replica set uh you will have to make sure that you are making use of labels and selector. Why? Because replica set completely depends on them. So when you go to uh the documentation here you will find uh YAML for a pod right and here you can 5:55:10 see here we have added the labels and what labels are we are already aware that labels are nothing but the metadata that gives additional information to the pod or any sort of resources that helps us in identifying and if you remember from the labels and selector video basically these are used for identifying and locating a specific pod right so in this pod.l AML you can find we have made use of engineix uh we have made use of label where the key is app and the value is engineix and likewise in replica set you will defined the labels and basically here the main thing that you will be mentioning is the selector. So the main part here is uh this is how replica set will know which pod to target. So if this labels does not match the replica set will simply not manage that pod. This is a single most important mistake that usually happens. So you have to keep in mind that whenever you are dealing with any sort of resources in Kubernetes specifically with replica sets or deployment, you have to make sure that you are making 5:56:10 use of labels and selectors. Okay. So on that note, let us create an YAML file. And don't worry uh the YML file is already present. Okay. I don't want to explain you the YAML which are already created uh because I just want to tell you how to think when you are creating any sort of manifest file. So on that note we are going to create everything from scratch. Okay. So uh okay let me just clear the screen and here I will try to create the uh manifest file for replica set. So how do we start with it? So let me just open a vim editor or we can do the same on IDE as well. So I'll just go over here and here you can see I have one blank file by replicas set.yamel name. Okay. And here we'll start with the actual thing. All right. So let's start with the first and foremost one important thing that is uh the building blocks of any sort of manifest file in Kubernetes. So uh what are the four building blocks of any manifest file? Yes, you are correct. It 5:57:11 is API version, client, metadata and spec. Right? So we are good with this thing. We are already aware what exactly these are. Okay. And let me just do a little bit of zoom. One second. I think it would be better if I switch to terminal itself. That would be better. Okay. I'll just do a vim on replica set. Replica set. Enter. Okay. So we have API version kind method data inspect. Right. Now the next thing is uh I'll just Yep. So that's the beauty of using terminal. So this is how I like it. Basically I can just use two terminal parallelly and that will be helping me out. Okay. So the first thing is we are trying to create a replica set right. But the first thing is we know uh since we are trying to create replica set the kind will be replica set. But what will be the API version? Will it be v1? Will it be app/v1? Will it be a batch? What exactly it would be? So yeah, you are 5:58:13 already you are already aware that we will make use of cube control API resources. And here we will run a grab for replica. Okay. And replica or okay here I need to run a grab on replica. Enter. And here you can see we have replica set. The API version is nothing but app/v1 which is exactly what I'm going to update over here. So I'll go into insert mode and here I have added app/ vision app/ v1. Now the kind basically we are trying to create replica set. So replica set it's replica not replica. Okay. Now comes the metadata. So here basically this metadata will be for the replica set itself. So here I will write engine x - rs for replica set. A short abbreviation that I'm using. Now comes the main part that is specification. All right, let's go with the specs first. So whenever we are dealing with replica set, the first thing that we should define is how much replicas do you want to create. Now if I go back to the 5:59:13 example that we were referring to here, we were trying to create three replica pod, right? So let's do the same. Let us create three replica pods over here. So I will define the keyword replicas and here I want three replicas. Right? But uh on what basis you will be doing the selection, right? For that you will have to define selector. So I will write selectors right and here we need to select all those parts where it matches the label right so for that we again have one label called matched label labels okay and what is that label it is app colon engine x okay and now when I go back now see the thing is we have replicas we have selector we also told him that what sort of labels that we have to match matching but again there is one more thing uh which is missing what exactly it is the thing is we didn't specify the specification for ports and before even that uh there is one more keyword for 6:00:14 replica set and that is nothing but template let me define the template over here template now why we are using this template see uh since uh replica set makes sure that uh it should create a replica whenever something is getting deleted right how will he know like uh where and what should be the configuration of the things right so for that he need a template right and that is how he will be just creating the pod right based on that template he will be creating that specific pod so here we are actually defining the template right and here I'll just write within this template I will define the metadata metadata okay and yeah within this metadata here this is the important segment please uh pay attention here I will define the label labels and the label will be app colon engine which is exactly what we defined in the selector itself. Right? And now here comes the important part and that is nothing but the 6:01:14 specification and make sure that this specification falls under the template which is in alignment with the metadata. So here goes the spec and now here we will write the specification for pod itself. So containers containers enter and here uh since we are defining containers this is basically telling kubernetes this is telling replica set basically what sort of container we want to create. So first thing that we need to provide is the name of that container. So the name of that container will be nothing but engineext. Second is what would be the image. So I will pass the image over here and the image is nothing but engineext colon latest. Enter. Now if you want to specify ports you can. Okay. But okay, we can I'll just help you in writing the ports too. So even if you are done till here, your replica set will be created. But if you want to define the ports, uh it's a good practice you can define it over here. And then within that ports, you can define the container port container port 6:02:15 and this is the port 80. Escape colon wq and the manifest file is ready. Now let me just explain you everything line by line. Okay, let me just zoom a zoom so it is visible to you and I hope and I wish it is visible to you. So let's go line by line and I will explain you everything. Now pay attention to this. Let's go with the first thing that is API version. What exactly is API version? The API version says it's using something called app/v1. What exactly it is? So this tells Kubernetes which API groups handle the replica set. Right? Secondly, let's move to line number two. We have kind which says replica set. So this is the type of resources resource that we are creating. That is metadata. Right? Here if you want to read it in Kubernetes terminology we read this as metadata. Right? So what exactly this basically this is the name of a replica 6:03:18 set. And what's the name of replica set? It is nothing but engine RS. RS stands for replica set. Right? Next is spec do.trepplica. Spec is what? Spec is specification for that replica set. Right? And when I say specre replica set here we get the count three. What exactly it is? So here we say that we want exactly three parts running always. Right? Now let's move forward. We have selector. Right? And in selector we have match label. So this is how a replica set identifies which ports belong to it. And just after that we have defined what sort of uh label we are targeting to and then we define the template. Now what exactly is this template? This template is nothing but it is nothing but a blueprint which is used whenever a new pod needs to be created. Next we have uh template dot metadata dot labels. What exactly it is? Basically uh every pod created from this template should get this label. And what 6:04:18 exactly is that label? It is app engineext right and then finally we have specification for the containers where we defined uh the name of container image of the container and the port of the container right I hope uh you get a complete idea about this replica set yl file it's just a 19 line yl file and I tried my best to explain you uh each and every line right let me go back to the terminal and here is the replicas settl file I'll clear the screen at boot And and now let us do let us see the magic of replicas set. Right now let me just clear the screen and let us try to apply this manifest file. Now how do you apply a manifest file in cubernetes? Well it is very easy. You just need to type cube cuttle apply. You can say cubectl or cube cut. It depends upon you. Uh so cubectl apply f followed by the name of the file which we just created and press enter. Now here what it says a resource mapping not found for the name engine x 6:05:20 - rs name space from yl okay and then it says no matches for kind replica set in version app/v1 ensure CRDs are installed first okay so let me just verify what exactly it is trying to say uh so whim replica set enter here we have replica set app/v1 which we actually confirm from from cube cuttle API resources. So let me just reverify it. Uh cube cuttle API resources and uh I'll just run a grap over here. Grab enter. So okay we have replica sets and here the API version is nothing but app/v1 which is correct and then here we have defined replica set. Yes, I got the issue what exactly it is. Now if you see properly uh I have just written replica set over here but the catch over here is 6:06:22 my s was not in upper case and that's the reason we got that issue right and now what I will do I'll just cut this s I'll go to insert mode and I'll just correct it based on the documentation which is provided in API resources now see one thing is I didn't even open chrome till now right because I was just reverifying what mistake could happen I started it from line by line manner and that is how you troubleshoot the things once you are once you yourself is satisfied then you can uh like then you can mitigate maximum issues right and that's exactly what we did right now escape col wq and now let me rerun the same command again right and when I run cube uh cube cuttle apply - replica set enter here again it says error when creating replica set replica set in version v1 cannot be handled as replica set strict decoding error unknown field spec dot selector dot match labels. Okay, let us see what exactly is the 6:07:23 issue now. So the issue is with match labels. So the issue is maximum mostly with here. So we'll just see uh how do we solve it. Okay. So here we have match labels spec dot selector what it says spec dot selector dot match labels. So here it is specifically talking to this one spec dot selector dot match label. So this is what it is talking about. So let us see what can be the issue. So here we defined app coline x and I think mostly it will be indentation error only. So when creating replica set version v1 cannot be handled as a replica set. Strict decoding error unknown field spec selector match label. It says this is an unknown field and that is the exact issue. So let us go to the browser now. Okay. Now since we are not able to decode it. So I will just write cubectl uh replica set replica set. 6:08:24 Enter. And the first thing that we'll get over here is the documentation. I'll just scroll over here and I'll just recheck what mistake I could have done. So I'll just reverify. So API version I'm making use of app/v1 kind is replica set with s capital then we made use of metadata here uh we didn't made use of any sort of name space because we want everything on the default name space so that's good and secondly we have okay so here the labels are defined in the metadata section itself okay uh second thing is uh so mostly the issue is I think with this match labels and selector thing because they have mentioned the same thing into the uh metadata itself. So that's one thing to note. Secondly, uh they have mentioned the selector. Oh, so they are using the selector here too. So selector mash labels. Then here they have defined the mash label too. Then we have template and that exactly we did right. So let us 6:09:24 check what can be the issue. Now I'll just copy the entire file and I'll just go and here in the AI mode I'll just go and check with the Google what exactly is you what exactly is the issue. So one second. Yep. So check the issue with this YAML and um apart from that something went wrong. The content wasn't generated. Okay. I'll just paste it once again. It looks like you pasted the raw manifest string. Again to clarify, you paste this directly into a tool or single file. And here is the exact file and that we can use. Okay. So here it says uh the issue is with match labels. Okay. Oh, I got it. See the issue was with the spelling itself. So here if I go to match labels, it is L A B L E S. But actually it should be LA labels L A B E 6:10:28 L S. Okay, this was a very silly mistake. But yes, we learn from this silly mistake itself. So again cubectl apply - f replica set.ml and here you can see replica set is created right see this is how we learn actually right it was a very silly mistake that I made right it was just a spelling mistake right here instead of labels I made use of something else I made use of labels right so it's just a single word that actually can throw you a multiple errors right but somehow we were able to identify that the issue is mostly with this part of section only. Uh next time whenever we are decoding anything. So there is another check for me that uh apart from checking the indentation and everything check the in uh check the spelling mistakes too. Right? Okay. So let us go back to the terminal. I hope everything is clear now. Right. So let's verify the resources that we created. So I will run cubectl get replica set or 6:11:30 you can just write rs. So here we have enginex RS which we created. Where did it get the name from? It get the name from the metadata which is enginex RS which we defined in the ML file. Okay. Now as per the theory that we have learned we understood that replica sets manage pod. Let us see the pods. So cubectl get pods. Here you can see we have three pods available because that is something that we defined in the template itself. We want three uh three pods right and this is what we can see. And there is one more thing that you should identif uh you should see that is uh the pod is again containing the name of the replica set followed by few hash and that explain the chain hierarchy right. So yes look at these three ports which are created automatically and no human manually running the cube run command three times. I just applied the manifest file once and it is actually doing the job right. So now uh the self-healing 6:12:32 demo let's uh do the same thing because that's why we were learning replica set in the very first place. So let me delete one pod and just to help you understand things. I will be making use of this terminal so that you can see live what exactly is happened. I will run cubectl get ports - w. So when you write hyphen w it will run a live u pod watch. So it is some sort of uh like you can say a watch monitor into pods. So whatever activity we would be doing with this pod it will be reflected immediately over here. So what I'm going to do is I'll delete this pod name enginex rs um this one kh2 w right. So I'll delete this part. So I'm deleting I'm trying to delete this part. So keep an eye over here. Right. So I will run cube ctl delete followed by delete pod pod name. Enter. And here you can see it was running. Okay. KH2W. 6:13:36 And here it was getting terminated. Okay. Done. And then it was deleted. Now there is another pod which is in picture. Let us see what's that pod. So cube ctl get pods. Enter. And here you can see we have HMX CL and ZKT7 which is already present. But since we deleted 9K H2W a new pod is created and we didn't even do anything. That's the power of replica set and this is what we call self-healing right so a replacement pod appeared automatically. Right? If I delete all the pod at once what will happen? So let us demonstrate the same. So cubectl delete pod followed by the new pod that we created it. It got deleted that I'll delete this part too. Okay. The second one enter. And I'll delete the third one too. What will happen right on the right 6:14:37 hand side you can see what exactly is happening. It is deleting the pod. It is getting terminated. It is getting completed. And at the same time new pods are getting created too. So let me run cube ctl get pods. Here you can see again three pods are up and running. Right? So replica set what it did it noticed that only uh two pods were running earlier then one pod was running earlier. Then he instantly created new pods to bring the count back to three. Right? And that's the power of replicas set now let us do one more activity. Let me just stop this watch and let me clear the screen. We'll run it once again. Cube cutle get pods w once again. Okay. Now uh I'll just zoom it out a little bit for yep for visibility. Clearing the screen again and I'll run the cube cutw once again. Now the thing is uh let's say there is a requirement a traffic is uh we are getting high traffic into our 6:15:37 website and due to that reason we want to scale the replica instead of three we want to do it five right how we can do it. So basically it's very easy. You can directly go to the manifest file and apply it or you can do it on the fly. How you can do it? Just write cubectl scale replica set RS and followed by the name of replica set. What's the name of replica set? It is engine x - rs and then as - replicas. How many replica you want? So right now I have only three replica if you can see on the right hand side and instead of three I want five replicas. Enter. What is happening over here? It will create two more replica on top of the three which were already created. And here you can see those two are also in running state. Now now when I see when I run cubectl apply uh sorry cubectl get pods here you can see five pods are up and running. 1 2 3 4 5. How cool is that? Right now we 6:16:42 have five ports. Now this is this concept what we did right now is called as scaling up. Now if we have scaling up there should be something called scaling down right because now let's say the traffic went to normal and we don't want the pods which we scaled up the two new pods we don't want it right. So we want uh the previous state that is nothing but the uh three pods right or let's say I just want instead of the standard one I don't want that much of pods let's say it is weekend and I just want two pots to be running because that can do the job how can I do it it will be again the same I will just write cube ctl scale replica set followed by the name of replica set it is engine x - rs followed by hyphen replica class and the replica will be two. Okay. Uh there is a spelling mistake. Okay. I need to correct the spelling for scale. S C A L E. Okay. Enter. And here you can see the 6:17:46 replica set is scaled. Now when I run cubectl get pods. Now you only tell me how many pods will be listed over here. Okay. You can see the log. It was visible to you completely right on that node. Tell me how many pods will be listed after scaling it down to two. Enter. Yes, you were correct. We will only get two replica sets, two pods, right? So you right see you just now saw how extra pods were removed to match the desired count and that desired state uh model is in action, right? So the core uh so the core idea behind almost everything is this only right I hope this made sense right now you understood uh replica set in a very good manner now it's time to move with uh deployments so one second let me go to the documentation and so what we covered we 6:18:46 covered how to create a replica set what exactly is the meaning of replica set right we understood uh the hierarchy right So basically the thing is what exactly things are happening over here is replica set manages part but who manages replica set okay so there is something called deployment which will fall over here okay I'll just mark it over here so this is nothing but deployment okay I'll just choose a good color okay so we have someone called deployment what exactly is this so before we move to deployment. Uh there are four mistakes that we usually do with replica set. So uh I just wanted to highlight the same. So before even we move forward with deployment, let us understand what can be the common mistakes that we can do with uh replica set. Right? Now since we are just talking about replica set, so let us focus on the same. So the issues uh so the uh uh mistakes that can be done would be like labels and 6:19:47 selectors. So basically in this file if you change the labels and the selector okay the value of those labels right uh the replica set will silently ignore those port. Second is a wrong indentation. So Kubernetes is very picky. We need to make sure that YAML the indentation is followed properly. If we don't follow the indentation we might face issues. Right? So I believe after the YAML video things will be very much clear to you about the indentation at at least right and yeah there will be a few challenges that you might face but don't worry see uh the main thing is refer the documents there are tons of documents that you have and even if you don't understand from documentation itself it's completely fine don't panic about that see you have chat GPT even I made use of Google right so like resources are there we just need to know how do we use it. Right? So that's the thing that's that's how we do the learning. Right? In learning phase everything is everything is accepted like there is 6:20:47 nothing big or nothing small. Right? Third is uh since we are talking about the mistakes that we can do let us uh discuss the third one too. So uh we can edit ports directly. Right? So uh do not edit the ports directly instead of editing into the replica set because once you do the editing in that pod it will be wiped out. Right? And the last one can be forgetting the check using cube cuttle describe command when something isn't working. So let's say if something goes wrong what we usually do we panic but instead of panicking instead of uh like panicking or like reaching out to someone the first thing that you could do is just run a describe command because describe command will give you a complete clarity complete visibility what exactly is happen try to record it from yourself. If things are not under your hand then reach out to people right. So that's that's all I did right now itself right I was not able to get the issue what exactly it was I went to Kubernetes document I tried to match the things but then I went to Google and 6:21:47 then I finally found the issue right so that is how we learn the things right so we were talking about describing uh the replica set so in order to describe the cube cutter uh in order to describe the replica set you write you can write cube ctl describe replica set followed by the name of replica set. What's the name of replica set? It is nothing but engine- rs. Enter. And here you can see we have all the description. Yeah, description of that replica set that which we created. And here you can see all the events that happened over here. Right. So let us take a quick recap of whatever we have covered so far. Ports can create ports cannot create themselves. So that's the reason replica set came into the picture. So what replica set does replica sets watch parts continuously and maintain the desired count and gives us the self-filling. Now that's the thing uh we learned uh replica set and I think uh 6:22:48 now you understand why we were saying replica set is nothing but the monitor of your class because he makes sure that everyone stays in the class the count remains the same but here is the twist. What are the limitations of replica set and why do we need deployment in the very first set right? So see the thing is replica set are very excellent for doing one thing that is keeping the desired number of pods alive right but here is a real scenario that your app is running on version 1.0 zero. Okay, I'll go to Excel draw. Now let's say this is the application that you are using. Let me just take an copy of it. So the app which has been consumed by the user, this runs on version v1. Okay, I'll mark it as green for now. Okay, so let's say this application or pod whatever it is, it runs on version v1, right? Across all the pods. Now the thing is your developers releases 6:23:49 version two of it. One second. Now what your developer does, they release version two of it with new additional enhancement, new functionality, fixing the existing bugs, solving the latency issues, everything has been solved, right? The question is with replica set, how will you update this version? How would you update every single pod to that new version? These are all the pods which are running. Now imagine this uh instead of three pod, imagine that these are 300 pods. How will you make sure that every single pod gets updated to a newer version without the downtime? So if you try it with the plain replica set, you'll realize that uh there is no easy built-in rollout strategy. You'd have to manually delete and recreate the ports, right? which is very risky and it can create huge down time that can affect the SLA right. So if you want to 6:24:50 understand this, let us take an example. So uh let's say uh let's say that uh you are in an restaurant. Okay. The chefs are nothing but your pod. So I'll just uh write it over here. So these chefs, this pod is nothing but a chef. So this is the chef. We are in a restaurant. Okay. I'll just make a copy over here. This will give you a clarity. So we have we are in a restaurant and we have these chefs. Okay. And we have a restaurant manager who is nothing but our replica set. So he is a restaurant manager. Okay. Okay. So we have a restaurant uh and we have the chefs who are preparing the dish. We have a restaurant manager which is nothing but the replica set which makes sure that enough chefs are always working. And then we have the restaurant 6:25:52 owner which is nothing but the deployment. Okay, I'll just rename it this. I'll just mark a label here too. So this is restaurant owner. Okay. 6:26:12 Okay. So here we have the restaurant owner which is nothing but a deployment which decide when to hire new chefs, when to replace old ones and uh how to undo a very bad decision, right? So the thing is the owner doesn't care about cooking, right? He doesn't cook. The owner manages the manager because he is completely in touch with the manager. He will get the updates whether this guy is not doing work properly, this guy's work is not doing properly. So basically the thing is these things are already been taken care by the restaurant manager itself, right? But the restaurant owner whenever he want to contact he will the only point of contact for the restaurant owner will be nothing but the restaurant manager. Right? So the owner manages the manager and the manager manages the chef. Right? So that exactly what a deployment does. It manages the deployment manages replica set and the replica set manages part where the containers are running. Right? So deployment give us uh the things a 6:27:12 replica set doesn't offer conveniently that is nothing but rolling updates roll backs easy easy image updates and full declarative management along with the revision history. So that has been provided by deployment was not even provided in replica set. Replica said what indeed a good invention but due to this single thing uh we are using make we are making use of deployment and I hope you understand the difference why usually we consider deployments into the production instead of replica set right so let us uh build one uh deployment file uh which looks very much similar to the replica set and yep let's do one thing let's make use of the same file that we made use of right now I'll just copy it I won't change anything. See, uh that's the thing that I wanted to tell. I'll just paste everything exactly as it is. Okay? There won't be any change. Let's go line by line. I'll explain you everything. Okay? And I will tell you what exactly is the difference between the uh manifest file of a deployment. 6:28:15 Okay? I'll keep it over here and what's the difference between a replica set file. Okay? Both are side by side. Right? Now, everything is identical. Nothing is changed. The only thing that will be changing over here is the kind deployment. And now if I say that uh you just learn how to create a manifest of deployment will you agree on that? No. Right? But exactly that's the thing. If you learn replica set then uh the manifest for deployment is exactly same. Only the thing that get changed over here is nothing but the kind. Okay. Let me just make few cosmetic changes. So instead of uh metadata keeping as replica set, we'll mark it as deployment. So deployment. Okay. And here I'll keep the uh replicas as three as it was earlier. And we'll keep the same labels. I'll just add few spaces so that it will be easier for you to read. So here we have the kind. Here we have the metadata. Metadata done. Then we have the specification where we mentioned three 6:29:15 replicas. Okay, this is also done. Then we have defined the selector where we have defined the uh labels that we want to target to. Then here we have defined the template which is exactly what is what was defi uh was what were defined in the replica set. Then again we have the containers and here in the containers everything exact same nothing is changed. Uh I'll just change one more thing since we are learning deployment. Uh let us make use of engineext image. Let's take any random enginex image. I'll just type engineext engineext docker hub. Okay. So we'll take any random image tag from here. So I'll I'll just go with uh I'll just search. Okay. 1 13 it is. So let me just take uh let me just make use of this image. I'll just copy this and I'll go back over here. And this is the image that I will be making use of. I'll just correct it. I'll just remove the docker pool. Okay, so things are ready. Now you understood the only change that 6:30:15 we made in this file was nothing but the deployment. Okay, the kind of deployment and we just changed the image name. I'll just close over here and I'll just show you everything from starting. So it is same structure just like replica said we just change kind to deployment which we just saw which we saw just right now and let's apply it and watch what exactly happens under the hood. And there is one more thing which we changed that is the tag of that image that is enginex 1.30 alpine and it's a p image. Okay. So yeah just uh just think of it as like we change we just changed the image. Right now let us apply the changes and see what exactly happens. Let me clear the screen. Let me stop this watch. Clear. Let me check whether is there any pod currently up and running or not. Cube ctl get pods. And here there are two pods which are running. I'll just delete the replica set and the parts will be deleted automatically. So cubectl and that is another observation. So I'll just show you what happens when I delete 6:31:15 the replica set. So so cubectl get pods in watch mode. And here you can see two pods are running. cubectl get rs for replica set. And here what I'll do I'll just delete this replica set. So cubectl delete replica set followed by the name of the replica set that is engine replica set. And here you can see the pods which were running got terminated and the status is completed. Now when I run cubectl get pods nothing is found in the default name space. I'll just close it and yep let's get started. And here we are talking about the deployment file. So let us apply this manifest file now. So cubectl apply f followed by the name of the file and that is nothing but deployment. ML and here what it says deployment.apps/engineixen deployment is created. All right, let us verify the changes. So cubectl get deployment get deployment or you can also write get 6:32:17 deploy and here you can see uh we have the deployment ready and here there is one more thing that you can see ready 2/3 out of that up to date is three and available is three. Let me just run deploy once again. And here all the desired states and the actual state is 3x3 meaning everything is running. Now there is one more thing as per this diagram whatever we learned so far that deployment manages replica set. But right now we didn't create any sort of replica set. Will there be any replica set created? Yes. Let me run cubectl get rs. Enter. And here you can see our replica set is created by default right and in the name if you observe the name of deployment is been copied exactly along with the hash in replica set that is the chain of events like that's the basically chain between deployment and replica set and now when I run cube cl get parts here you can see we have the 6:33:18 ports too right and if you notice one more thing here in replica set we had the name of the deployment And in the parts we have the name of the replica set itself along with the hash. What does it say? So basically it's a chain. It's the hierarchy that it signifies right. So deployment manages replica set. Replica set manages the ports. Right? So what happened? So basically uh just look at this chain right first the deployment gets created. Second the deployments automatically creates a replica set for us. Third the replica set creates three ports for us which we didn't created. Right? replica set create all self and the deployment did on behalf of us right and that's exactly what uh I wanted to convey that um that's the relationship between replica set and deployment right now let us inspect this relationship directly let me just clear the screen and let us describe the deployment so 6:34:19 cubectl describe deployment or you can also write deploy followed by the name of the deployment. It is engineext - deployment. Enter. And here it says engineext deployment not found. Okay, let me just check the name of deployment. It is engineext - deployment. One second. I'll just copy it from the metadata itself better. So cubectl describe deployment followed by engineext deployment. And here you can see we have the complete description of that engineext deployment. But the only thing that you have to keep in mind that you have to notice over here is it is scaling the replica set right. And now let me just describe the replica set first. Let me just list it. Cubectl get RS and cube CL describe the replica set followed by the name of replica set. I need to pass a space over here. 6:35:19 Enter. And here what you can see here basically replica set controller what it does it creates the pod right. And now final thing is let us describe the pod. So cubectl get pods and let me just describe any of one of the pod. So cubectl describe pod followed by the name of the pod. And what is the name of that pod right? This is the name of the pod and here you can see the application is running and the container has started. Right? So this is the reference that I wanted to draw and this is the actual parent child link uh Kubernetes uses internally uh where the pod is owned by the replica set and the replica set is owned by the deployment. Right? Now let us see this visually. Pod is owned by replica set and replica set is owned by deployment. Right? Now let's come to scaling. Uh so same idea as before. Uh but this time we'll do the same with the deployment. Right? So let me just go back and here let me clear the screen and here I'll 6:36:20 just drag it over here. Clearing the screen and running a cube cuttle get pods w with watch. Okay. Now the thing is what I will do I will just uh scale up this to five. Right now there are three pods which are up and running. So what I will do I will run the command cube clale deployment followed by the deployment name. It is engineext - deployment followed by uh the replica and how many replicas do we want? So replicas equals to 5. Enter. And here you can see there are two containers which got added over here and it says running right. The deployment updated the replica set and the replica set immediately created two ports for us and that's exactly what happened over here. Let me run cube cl get pods. And here you can see five pods are up and running which is managed by the replica set. So let me just list the replica set and let us run the describe 6:37:22 and let us see what exactly happened inside it. So cubectl uh get rs and cube ctl describe replica set and the name of the replica set enter. And here you can see based on the instruction whatever it received it created two ports immediately right that is Q 28 JP and 22 GXF right and if I go over here and this is the exact two parts which are created right so yeah that was all let me clear the screen now this was the example for scaling up and now let me just show you how the scale down happens over here so again the command will be same cubectl L scale scale deployment followed by the deployment name. So engine x - deployment and hyphen replicas equals to two this time. Okay. Now what will happen? Tell me. 6:38:25 The deployment will update the replica set and the replica set will delete uh or uh the replica set will make the count of pod as two. This will something uh this is something that we call as scaling down right and one more important thing let us delete a port directory and let us see what exactly happens. So cube ctl get ports and what I'll do I'll just delete this part. So cube ctl delete pod followed by the pod name enter. Okay so this pod is deleted now. Ideally there should be only one pod right but since deployment is there since replica set is there I don't think so there will be only one pod there will be two pod because we just mentioned what exactly is our requirement right so when I run cubes it will get pods here you can see two pods are again up and running a new pod appears but pay attention to who actually uh is the uh but pay attention who actually did that 6:39:28 it was not deployment It was the replica set right? Deployment itself will never touch the ports directly. This is the favorite interview question. So always remember that that deployment will manage the replica set and replica set will manage the ports. That is something that I have been saying I think uh more than 20 times but yeah that's exactly the fact deployment manages replica set and replica set manages the pod. Right now since uh we are talking about deployment we understood that what was the challenges that we were facing with uh replica set and what was the offering which was given by deployment. The offering that was given by deployments was rolling updates and rollbacks right and this is where deployments truly shines. So here is the real reason deployments exist in production. So now imagine that all your pods are running in let's take a live uh scenario by the way. So what I'll do uh I'll just clear the screen and here uh let us delete 6:40:28 that deployment first and see the act things uh what are happening over here. So cube ctl uh get deploy and here what I'll do I'll just delete this deployment. So cube ctl delete deployment for deployment name. Okay followed by the deployment name. Enter. Here uh we have deleted the deployment right. So what will happen to the replica set in the pods. So cube cl get rs replica set is gone. If the replica set is gone what will happen to the pod? The pod is also gone. So if you delete the deployment the replica set will get deleted automatically. And since the replica set is not present the pods will also get deleted. Right now since we were talking about a scenario in production, let us take a live scenario that u in production uh that imagine the pod is running on engineix version 1.27. Let's take this is the image that we are using in prod and 6:41:29 there is a new version that is uh 1.28 which has been released. So if you delete all the pod first and create the new one the user will experience the downtime which is unexpectable in production right and user will basically unsubscribe from your platform and you will face revenue loss right and that's the reason uh deployment performs a rolling update and what exactly it does it uh replace it it's it gradually let me show you how it does the replacement right so what I'll do I'll just show you how the picture looks like for uh deployment. I'll just copy this one. It will be helpful. So one okay one second. Ctrl + V. So let's say we have these three pods which were running in version one. Okay. I'll need one more. Okay. And okay this is so this is before uh we made the changes. This is something that is 6:42:30 running currently right now. What happens when we perform a rolling update? The exact same thing. Let me copy over here. This is something that happens in progress but the change is only one port get change. Okay. And I'll mark this one as yellow. And then finally what happens is let me copy this once again. And I think visually this will give you the clarity how those things are working right. Finally and here what happens is this is what exactly happens. I hope you understand. So what exactly happens? So user will keep accessing the application entire time. There will be no moment where everything is down. Okay. So what exactly happens when the application were running on v1 right? Everything was working fine. Then we decided to upgrade it to the latest version v2. Then out of those three, one port will get updated. Then once 6:43:30 everything is running fine, it will uh update the remaining ports too. And the final state that we get is like this. Right? So yep, let's see deployment uh rolling update in action. Right? So yeah, let's actually trigger this and see how does things are working. Right? So let me just go back and here let me just clear the screen and I will just apply the manifest that I just created. So cubectl apply - f deployment dot deployment and the deployment is created. And when I do cubectl cube ctl uh get deploy here we can see the deployment. Okay let me just see the replica set. Okay replica set is present. Desired and current count is three which is good. And when I do cubectl get pods and here you can see three pods are up and running. Okay. And here what I'll do I'll just kill the watch currently and I'll just clear the screen. I will rerun the watch command once again so that we can see the live changes how things are working. Right. 6:44:31 There is one more thing that I wanted to tell you is before even we do the rolling update. First thing is let us first describe and check what exactly is the image of engineix uh in the current deployment. So in order to uh in order to do that just run cube ctl describe describe deployment or deploy deploy deployment or deploy and followed by the deployment nametrl cnv and here we have the complete information and if I scroll to the top here you will find the uh and here we will get the information which image has been use. So yeah uh okay mostly it won't be here basically it will be at pod okay so cubectl get pods and I will describe either one of the pod to get to get an understanding which image has been utilized right so cubectl describe pod 6:45:33 followed by the pod name enter and here if I scroll up under the containers we have engine x and here we are making use of 1.27 image right now my requirement is I want to update this to 1.28 to 8. How will I do it? Let me just update this. And how do I perform this rolling update? So for that I will run cube cdtl set image. Okay. And what's uh where are we setting this image? Basically we're setting this image in the deployment. So uh we will write engineext - ngi and enginex - deployment. Okay. And basically which image we want to update? We want to update the image of EngineX. So, engineext equals to uh right now the image tag is 1.27. So, I will just write this as engineext colon 1.28. Enter. Here it says uh it doesn't have the resource type. Oh, I didn't mention the resource type. That is something uh 6:46:35 that's the reason I'm getting this issue. So, I'll just add a deploy over here. So, okay. So, this is how the commands looks like. So cube cuttle set the image into the deployment and the name of the deployment and there we want to update the image uh which is engineext and we want to update it to version 1.28 enter. Now see what exactly happens over here. Cube Ctl get ports. Cube CDL describe pod. This describe pod. Let's take this one. Enter. And here you can see the image is updated to version 1.28. But again there is one more thing that we we need to see that is the rollout status. So let me just run q ctl roll out status for the deployment 6:47:38 engineext - deployment enter what's the status so it says engineext deployment is rolled out successfully and now here you can see the complete watch what exactly is happening so what's happening behind the scene is the deployment creates a brand new replica set for version 1.28 into it and it gradually shifts the pod from the old replica set to the new one until the old replica set has zero pod left. So this it's not editing the existing part it's actually creating new ones and retiring the old one gradually right let us list the replica set now so clearing the screen and cubectl get replica set enter and here as I mentioned here it won't delete or edit the pod here it will create a new replica set right let me just describe this one right so here from the age itself you can get to know that this is the new replica set which was created And this was the earlier one where it was running the pods, right? 6:48:38 So now let's move forward. Now what if this new version that is version 1.2 head has a bug. So this is where deployment will save you. Right? Since we just performed an rolling update, we have a concept of rollout. What it will do? It will undo the changes, right? And how do we do it? Basically, let me just show you. So cube ctl ctl roll roll roll roll roll roll roll roll roll roll roll roll roll roll roll roll roll roll roll roll roll out undo. Okay. Followed by the deploy which is nothing but deployment name of the deployment that is enginex deployment. Enter. And here uh what it says warning resource deployment was previously managed with cube cut apply. Okay. Ignore this. Rolling back will not update the cube cuttle last applied configuration annotation which may cause unexpected behavior on future. Right. consider using cubectl apply with your previous configuration file instead. Okay. Now let me just show you the 6:49:39 rollout history. So here instead of undo I will just replace it with the history so that we can get the history of rollouts. Enter. And here we have the revisions present. Right. What is exactly happening over here? The deployment will instantly switch back to the previous replica set. Okay. And if I just run cube ctl get rs, you can see it again switched back to the previous replica set. If I go above. Okay, I'm not able to go over but remember earlier when I showed you when you just go back to this video, you can just make a note that earlier it was running on this new replica set. But then when we rolled out it again switched back to the previous replica set, right? So the deployment instantly switch back to the previous replica set and basically that's the only thing that is holding your stable ports. So this is a roll back and it's something uh a print replica set cannot simply do on 6:50:40 its own. Right? So let's lock all of this into a single comparison. I have one documentation for the same. uh I'll just go to the bottom and here I have created this table which will help you in understanding what all things what are the offerings of replica set and where a deployment shines right so the first thing is u self-healing right self-healing is provided in basically both replica set and deployment which we checked scaling again it is provided by both we checked rolling updates it's provided in deployments not in replica set roll back not provided in deploy rot not provided in replica set but is present in deployment. We have revision history in deployment which we just saw but it it is not present in replica set and that is the reason we recommend deployment over replica set into the production right and in order to understand in order to keep this concept in mind remember the chefs are the pod the 6:51:41 restaurant manager is nothing but the replica set the restaurant owner is nothing but the deployment and the owner the deployment doesn't cook they manage the manager and the manager will give enough chefs to keep working the parts right so again I'm saying this once again deployments use once again I'll just go over here so yep deployments make use of replica sets internally and you are almost never going to create a raw replica set in real production environment you'll always uh reach out for a deployment right so what can be the best practices when we are uh learning deployments or when we are working with deployment. See, prefer deployments for stateless application and uh always make use of meaningful labels that will give the clarity what you're dealing with. Tag your container images with a specific version. Never rely on later version because if you give a specific number, it will be very 6:52:42 much helpful for you to understand. Now see in this example itself, we were making use of 1.27 earlier and now we are making use of version 1.28. Now since we got to know that there was an issue with version 1.28, we rolled back to the previous stable version which was nothing but version 1.27. Right? I hope you understand. Then next is always uh monitor your rollout status before assuming that the update is a success. Okay. And test every update in lower environment before touching the production. I repeat, test every update in lower environment first before you push it into the production. So yes that was all and I have uh prepared ample amount of questions for you. These are the top eight questions that you should go through before uh you are attending any interview because this will definitely give you the idea about replica set and deployments and uh I believe in this video you learned a lot. you will get an idea what exactly we are 6:53:44 dealing with why we are considering deployment why we are not considering replica set right so uh pause this video and go through this question and try to answer yourself okay now I'll help you in answering each one of them I'll just explain you what exactly is what so the first thing is why pods are not directly used in production now you have the idea right so basically a bare pod has no controller supervising it. It's uh like a nonself filling and if the node fails the pods will get deleted or if someone delete it accidentally nothing uh there will be nothing there will be no one who will be recreating the pod but who does the recreation of that pod it is nothing but replica set right and one more thing that you can say is uh there is no built-in way to uh scale it up or roll the updates roll back the standard parts so in production We always run ports through higher level of 6:54:46 controller. Typically, it is a deployment. Make sure you are saying deployment not replica set over here. Right? So mention that uh there is always an upper level controller that has been managing these pods and that is nothing but a deployment. So Kubernetes can actively maintain the availability of of the pod instead of uh fire and forget scenario. Now the next question is what is a replica set? So replica set is a cubernetes controller who is uh whose sole responsibility is to ensure that the specific number of pods are up and running like and it will be an identical pod which will be running all the time. So it continuously reconciles uh between the actual versus the desired state using the selector and that's the reason I told you that whenever you are dealing with replica set make sure you are making use of labels and selector right so with the help of uh labels and selector it makes that the identical pods are running and for that it requires a template to know what uh a 6:55:48 new part should look like if it needs to create one right let's move to the third one what problem Does replica set solve? Okay, it solve the problem of uh self-filling and scaling problem for stateless workload. So without it if a pod dies nothing will bring it back and scaling means manually creating and deleting the pod one by one. So the replica set controller loop constantly and compares how many pods should exist and it will check uh how many actual pods are present currently. Right? So it reconciles the differences automatically and it replace the dead pods with uh with adjusting it with the newer one to scale it uh to the desired number. Right? Let's move forward with the next one that is why deployments are preferred over replica sets because a replica set alone cannot support declarative rolling updates or roll backs. So you would manually have to create the replica set and uh you have to migrate the ports yourself. So 6:56:50 what it will do it will risk the downtime and it will be an errorprone. So uh a deployment sit one level above the replica set and it manages a deployment sits one level above the replica set and it manages the replica set. Uh the whole rollout strategy has been performed by deployment and replica set actually executes it. It creates a new replica set per version. Gradually shifts the traffic from older to newer replica set uh which we just saw and it lets you to undo the uh changes if something goes wrong into the previous state in second. So almost basically in practice you almost never create a new replica set manually in production. It is something that has been managed by deployment itself which we just saw right we didn't even graded a new replica set of the older one. it was managed by deployments by itself. Next is explain the uh architecture of deployment, replicas and and the pod. 6:57:52 Again we'll refer the same diagram. Okay. So uh it's a three layer ownership change a deployment replica set and pod right. So deployment it is at the top where it is a userfacing object. It defines the desired specification such as images, replica count and update strategy and its own u more than one or more replica set. Now coming to replica set what it does it creates u it is created and controlled by the deployment which sits on top of it. Right. And uh the deployment then scales uh it to a new up when the older one is down. And then we have pod. What pod actually does it is created and controlled by the replica set which is managed by deployment right. So what it does it is controlled by replica set and based on the uh template which is provided into the manifest file. So the linkage is forced via the owner references and it's based on the metadata for each object. So you can see it without uh you can see it with uh cube cut describe. So uh 6:58:53 whenever you run the command uh rolling update uh the old and the new replica set uh coexist together and with the deployment orchestration you can transition uh between each one of them. Right. So yep let's move forward with the next one that is can a deployment create pods directly? No. The answer is no. A deployment can never create or delete the pod itself. He will need someone. And who is that someone? it will only create it through replica set. The replica set is the only one that actually creates the pod. This is why if you delete a pod manually, it is automatically reconciled by a replica set and then it will notice it and replace it. Right? It is not deployment who will directly manage the pod. It will need replica set. Right? So though the end user uh effect looks the same but the thing is uh deployment is doesn't manages the pod. It is something that has been taken care by replica set. 6:59:53 Let's move forward with the next one that is rolling update which we just saw a practical of. So basically what is a rolling update? So rolling update is basically it's a strategy for zero downtime updates. Instead of terminating all the pod at once and starting the new ones at once, the deployments creates a new replica set and it incrementally scales it up while scaling the old replica set down. So if you remember this diagram this will give you the idea. So this is how you can explain the rolling update. So whenever there is an update that we are performing that uh at that time it will instead of deleting all the part at once it will try to replace one container at a time and then finally we will get the achieved desired result. Right? So here the traffic keeps serve true uh because there is always a sufficient number of pods which are running behind the service. Let's move forward with the last question that how do you roll back a deployment. So basically uh you just saw basically uh you run cube cut roll out undo command. 7:00:54 This works because the deployment retains a revision history and each revision is tied to a replica set which is controlled by revision history limits. So on roll back it simply scales the previous set back to the current one current one down and same rolling mechanism as forward update uh this is applied in reverse. So uh you can inspect available revision with the cube cuttle rollout history deployment right. So yes next thing is uh again you can also say that pods run your container uh run your container and replica set keep the desired number of pods alive and deployments manages your replica set and give you the production ready roll out and roll back capability. So that's the complete life cycle from port to replica set to deployment and yes that was all. I hope you got to learn a lot from this video. Right? In this video, we literally covered tons of thing. We understood about deployments. We understood about replica set. We understood what are the differences between them. We even saw like what is 7:01:55 the hierarchy of uh replica set deployment and the ports. What will happen if we don't have replica set? Will uh deployment directly be able to manage the port? Right? These sort of answers we are now able to answer. Right? I hope this video added tons of value in your learning. Don't worry all the manifest file which I created. I will just push it into your GitHub repository. I'll push it up right now right away so that you have everything handy. So get add dot get commit fm and I am adding the files for deployment manifest addit. So I'm doing a push and now all these changes will be reflected into the GitHub repository which we are looking right now. I'll just need to do a refresh. And here you can see the deployment.l file is present and alongside we have a replica set file. Uh I think this is a spare file which I 7:02:57 just shared. So I'll just delete it and I'll push it again. So yeah, you have everything uh under your hood, right? Everything is present documented over here. Please feel free to check out the same. Feel free to do the experimentation. Feel free to make mistakes because the more mistake you make the better learnings you'll get. And believe me, Kubernetes is not something that you learn by just watching. This is something that you have to do manually. If you are not doing u command, if you're not executing command, if you're not making mistake, then believe me, watching video will not help you out. Okay? You will be just able to retain the concept for some time, but then afterwards you will forget it. My personal recommendation whenever you are learning Kubernetes you have to do it manually. Watch this video once, watch this video twice, watch it th watch this video thrice but at the fourth time try to do it yourself. If you're facing the issue do alongside with me but try to do the hands-on that is very important right. So yes on that note uh that was all and I will see you 7:03:57 in the next one. Until the next time keep learning and thank you very much. Hey everyone, welcome back. So in the previous video we learned about how does deployments and replica set work together to make our application scale. Right? Deployment directly doesn't manage pod. It it is basically replica set who takes care of everything. Right? Replica set make sure that the desired number is matched. So even if you delete the pod a new pod will be created with the same configuration. Right? And now how does deployment helps us? Basically it helps us with selfhealing. Right? So those are the things that were the offering by deployments and replica set but now let me take you to the production and what if I ask your application is live right and the thing is uh you want to upgrade it to the newer version you want the users to test the new feature which you have created and you want to roll it out to the people how will you do it so yes in this session we are going to discuss about the same here we are going to talk about ro rolling updates and bugs right what will happen if you want to update it to 7:04:59 a newer What happens if it goes down? If it is not working as per the expectation, how will you roll it back to the previous version? That is something that we are going to discuss today. So grab your terminal, grab your coffee notebook, make the notes and let's get started with this and solve. So before even we do a deep dive, let us first understand the problem statement. Okay. Now imagine that uh you have a deployment and that deployment is supposed to run three pods. Okay. Let me just draw three pods over here. So this is pod number one and here uh I'll mark it as pod one. Okay. Likewise you have two more pods. This will be your pod number two. And this will be your pod number three. Okay. I'll just place it one below the other. Okay. Let me just correct the labels. So this is pod number two and this is part number three. And you have deployment who is managing it. And just below deployment 7:05:59 there is someone who is taking care of all the pods right and if you're coming from the previous video you are already aware that replica set is someone who's taking care of all the pods right and deployment directly connects with replica set so that they are working together right now the main point over here is let me just replace it deployment okay got it here let me mark it with blue and let me change the color to let's say green okay so this is the deployment and here you can see we have pod number one pod number two and pod number three. Each each pod runs on a specific version. Okay. Now let's say the version over here is v1. Okay. This is version one which is currently up and running and things are going really very fine and this is exactly uh you can consider that this is into production and people are accessing your website. Okay. Everything looks good right now. Uh since you're running a product, okay, uh your developers 7:07:00 developed something and they came up with a new idea, right? And they wanted to update this with a new version, a new release and that is nothing but the version number two, right? So the most obvious and the worst idea would be to delete each of these pods which are running and then create three new ones with the newer version. It sounds really simple, right? But see, think about it. What happens during those few seconds when there is no words available? So, what happens usually is here, let's say this is the guy and he is nothing but user. What happens is whenever uh some sort of changes happens over here, right? If these pods if these pods are not even present there then basically you will lose that customer. You will face revenue loss. So every time user visits your website he will get few sort 7:08:00 of errors. It may be anything. You will get 500 error. It will be a very bad experience for the user right your APIs will stop responding and the customer won't be able to log into your system. The order will fail. The payments will fail. And what exactly this term is called? This is exactly what we call as downtime. And in production downtime is really very expensive. Sometimes literally it is so much expensive that it may go into a revenue loss and sometimes the customer loses the trust into the product. Right? Now if you want to understand this in a very better way, I have an analogy that will help you to understand rolling updates. Okay? Now let us imagine let me just copy this entirely then it will make sense for you right? So here let me paste it. So now let's imagine that uh you have an hospital and in that hospital you have three doctors. So this is the hospital 7:09:01 and here you have doctor one. Okay let me remove the version from here. Now delete. This will be our doctor number two. Hello doc. And this will be your doctor number three. Okay. And now what we'll do I'll just carry this user for now. Please come here. Okay. And what happens is you have the patients over here. So this is your patient. 7:09:39 So this gentleman is the patient. Okay. Now let me explain you what exactly I'm do. So you have an hospital and you have three doctors treating the patients. Now suppose the hospital wants to train all the three doctors into a new medical procedure. So what will happen? Will they send all these three doctor who are operating the patient? Right? At the same time, of course not the patient would have no one to treat them. Right? Now just imagine if this patient count increases to let's say from 2 to three, from 3 to 4, right? And from four to five, from 5 to 6. Now these are the patients and only three doctors are present. Right? Now if the hospital want to train all these three doctor to a new medical procedure will it be possible to send all the three doctors to home and ask them to get themsel updated with that procedure? Well definitely not because patient will have no one who can treat them right. So instead what hospital will do okay they will ask one 7:10:41 doctor to go and attend the training. So doctor one goes and attend the training. Okay. While the other two take charge and they continue to treat the patients. Okay. Now once the doctor one comes back they again have their helping hand back and then since things are working fine as it is supposed to be. Then the next time what happens? Second doctor goes for the training and the work is been done by Dr. 1 and doctor 3. And then again after the training is completed, Dr. 2 comes back and then it's time for doctor 3 to get updated. He goes for the training and then he will come back. Right? So at every point the patients are still been treated and there is no service interruption and that is exactly what has been followed by Kubernetes when it comes to rolling updates. So instead of replacing every pod together, it replaces them one by one. 7:11:43 And that is exactly what we call as rolling update. I hope this made sense to you. Right? So now what exactly is rolling update? A rolling update means Kubernetes will gradually replace your older parts with the newer ones and instead of stopping your application, your app will still be available to the users for the entire time. So if you want to visualize it, let me just help you to visualize it. Okay. Now we'll just keep this as it so that it will be easier for you to understand and I'll just move it on the left hand side. Let me just Yeah, this would be good. Okay. Yes. So this is the thing that we are learning. And here we go. I'll pull it over here. So let us visualize rolling update. What exactly happens? I'll just pull it down over here. Yeah. So initially what happens? We have pod number 1 2 3 running in version one and the user is 7:12:43 accessing the application. Then what's next? The next thing that happens is you get a new version and the developer says hey we have something uh that might be useful to you and it is a new feature that we are releasing. So here it goes to step number one and in step number one what happens one of the part let's say part number one will change the version from version one to two this exactly happens and once it gets success okay there will be step number two involved now this time what will happen another doctor will come and here this pod number two will get changed to version two right okay let me just pull back Okay, I'm just packing it down a little bit. One second. We'll just release it once this is done. Okay, now let's come back. Okay, let me just copy this entirely once 7:13:43 again. And this will be step number three. This is our step number two. This is step number three. Okay, so ignore the above one. Okay, I'll just move it to the side so that it would be easier for you to understand. One second. 7:14:11 Okay, cool. Now this looks good. Okay, now what happens? In step number one, only one of the part is uh getting updated. In step number two, two of the ports is getting updated with the new version. And in step number three, all the three pods are getting updated with the newer version. Did you notice something important? At every time and every stage, users still will have someone who will be serving the request, right? The pods will be still available to serve the request. There is no moment where the count of the pods drops back to zero. And that's the entire point of rolling update. And now I am 100% sure that this would have made sense to you, right? And this with this uh that's the actually that and that's the entire point of using rolling update. So what exactly rolling update promises it? It promises us zero or near to zero downtime. That's exactly we make use of uh rolling updates right now what happens behind the scenes and what actually Kubernetes does. Okay, let me 7:15:14 tell you. So here uh let me just copy deployment over here. Okay, I'll paste it over. So what exactly happens? So whenever you perform rolling update, okay, deployment will create two replicas. Now why two replicas? Let me just clear it. Replicas. This is replica V1. That would be the original one. And this will be replica V2. Let me mark this with some other color for visibility. Okay. So what happens when you perform rolling updates? What deployment does it will create two replica set and then the pods will get updated. So this is where it really gets interesting and this is where most of the people get things wrong. So many people think that Kubernetes what it will do it will simply change the image inside the existing pod but that's not exactly what happens. Pods in Kubernetes are designed to be immutable. Now what exactly is immutable? Something that 7:16:14 cannot be changed. So Kubernetes doesn't modify a running port container image. Right? Instead what it will do, it will create an entire new replica set and your old replica sets will still exist. Now if you remember deployment manages replica set and replica set manages ports. That's exactly the concept that will come handy over here. So what exactly deployment will do when we are doing a rolling update at the time it will create another replica with the newer version and your replica one will still be serving the customers right. So what happens? Your old replica still exist. It doesn't get deleted immediately. The new replica sets start creating the new pods with the updated images and those pods come up and pass their health checks. Uh and Kubernetes gradually scales down the over replica set and that exactly things are happening. So for a short period duration the roll out of two replica set uh exist and they work together and one 7:17:14 scale downs and another scales up. Let me just show you how does it looks. So here we are referring to subreository subd directory number 10 rolling updates and roll back. And here you can see the architecture of rolling update right. So I want you to remember this. It's one of the most important uh and commonly asked interview question in Kubernetes that uh deployment does not update the ports directly. It creates a brand new replica set as it is visible to you over here. Uh deployment creates a brand new replica sets and that new replica set creates the new BS. I hope this architecture gave you the clarity what exactly we are dealing with. Right? So all right theory is done. Now let's do some hands-on because I know once you do hands-on things will be very much clear to you right. So let's create a deployment. So how do we do it? Basically again see we have been doing 7:18:16 it from the starting itself. I won't tell you the copy paste method. Instead I will tell you how you can write the manifest file. Even though we have done it tons of time, I will repeat it 100 times because I want you to understand Kubernetes from the bottom my bottom of my heart because when I started at that time I faced those challenge and I don't want you to f face those challenge right. So let's get started and let's create a deployment file. So whim deployment enter. Now whenever we are dealing with any sort of manifest file in Kubernetes, what are the four building blocks for writing the Kubernetes manifest file? Yes, you are correct. API version, kind, metadata and spec. Now what exactly we are creating? We are creating a deployment. Now what would be the name of the deployment and where will it fall? It will fall inside metadata. And the name of the deployment 7:19:16 is enginex - deployment. Okay, this is also done. Now the next thing is uh API version. How will I get the API version? I don't want to refer any sort of documentation. What I will do? I will just run cubectl API resources. I will run a grab and I want to search for deployment. And that's the reason I'm uh writing deploy. What's the API version for deployment? It's app/v1. Okay, I'll again do a vim on deployment. Mamel. And here when I go to the line number one, here I will mention the deployment API version and that is nothing but app/v1. We have the kind as deployment. This tells kubernetes what sort of resource we are creating. Metadata giving additional information in this case. Basically here we are writing the name of the deployment. Now here as I mentioned earlier whenever you are dealing with deployment you are dealing with replica set. Now when you're dealing with replica set you need to tell kubernetes how many replicas do you wish to create. So that's the reason we are making use of replicas and I wish 7:20:18 to create three ports. Now on what basis the replica will create uh the ports. It will need two things. One is the labels and second is the template through which it will create the pods. Right? So let us first uh create the labels. So for that we will create first selector. And I hope you are pretty much aware about the concept of labels and selector. If not I will request you to go to the previous videos because that will give you the complete idea how does labels and selector works. Now considering that you have already gone through the concepts. Now let's get started and here I will write match labels. Now why match labels? This keyword actually tells Kubernetes uh which sort of which sort of um keywords we are which sort of labels we are targeting to right and here the label that I will be using is again the basic one that is app engineext. Now here we are done with defining the selector. Now comes the most important part when you are dealing with replica set you will be needing two things. First is nothing but the 7:21:19 selector and second and most important is template because that's the actually thing through which it will create the ports for us. So here I'll write template and here I will write the all the specification that we need for creating that specific ports. So inside template we will need metadata. Now metadata why we need this metadata? Basically it will give the attribute through which it will be targeting the pods. Right? And what attribute we are giving here? We are giving labels and this will be the targeting value. And here I will write app colon engineext because that is something that we defined in the selector and this will match the labels and then only it will know which pods it has to target to. Now the last thing that we need to do is we need to write the specs and this will be the specs for nothing but the pods. Right here I will write containers. Now since we are dealing with pods inside pod what ex what exactly is running it is the container. Now the first thing 7:22:20 that we would be giving is the name of the container. What is the name of this container? It is nothing but engineix. Enter. Now the next thing is since we are dealing with container we need some sort of image. And which image here we are using? We will make use of engineix 1 uh 27 for now. Okay. Engineix 1.27. This is will be the image that we will be using. escape colon wq and now since everything is done since our manifest file is created that is deployment.ml we are good to start with applying it right so let us apply it so how do we apply basically you will run cube cl apply -f and name of the file that is deployment and here you can see deployment engineix is created now let's verify our current state before we mark any sort of changes right this is basics you have already gone through it. I'm repeating it again and again so that it sticks into your head. Right? So let's verify uh the current states before we make any sort of changes. So cubectl get deployments 7:23:21 or get deploy. Here you can see engineix deployment is created where there are three parts which are up and running. Now since we are checking deployments let us check the replica set. So cubeectl get replica set rs and here you can see here we have the replica set created. All right. Right now since we are talking about replica set now let us check the count of pods. So cubectl get pods enter. And here you can see three pods are up and running. And I'm 100% sure now you have the complete analogy the relationship between the deployment replica set and pods. Right here you can see the name of deployment along with uh some hash. It's present in replica set. And then the same thing is repeated in the pods and there is another hash which is present over here. So that's just an observation. If you want more information about your ports, so just write hyphen wide and it will give you complete information like the more information. All right, let me just clear the screen. Uh you have enough thing. Now you have 7:24:23 to take a note of exactly what we saw right now. What we have, we have one deployment. So let me just run cubectl get deploy. And what's the next thing? We have one replica set. And when we run cubectl get ports, what we have? We have three pods. Okay. And when you just go inside this pod. Okay. Let me just do one thing. Cube ctl describe pod followed by the pod name. Enter. And here if I scroll to the top here you can see engineix 1.27. That's the image that has been used. Right? And I want you to remember this baseline because in a minute we are going to change everything in a real time. Right? So what we are going to do we are going to trigger a new update that and basically we are going to change this engine x version from 1.27 to 1.28. Okay. So let me just clear the screen and before even we start making the changes I will open one 7:25:24 more terminal. Okay. And I'll just navigate to the directory. Uh, okay. Not needed. Let me just do a little bit of zoom. And here I'll just pull it over here. Okay, cool. Now it's good. Clearing the screen. Zooming out. And here the first thing that I will be running is cubectl get replica set. And here I want to mark it under watch mode. Now here just notice the desired count and the current count. Right? I'll just zoom out a little bit so that you have a clarity and make sure uh that you are noticing the changes over this this side. Okay. Now over the left hand side what I will do I will run few commands and that will actually help us to understand how does ruling updates works. Right. Now what exactly I'm going to do? I'm going to update the engineix image from enginex 1.27 to enginex 1.28. How do we do it? So basically we will need to set the 7:26:26 changes into the deployment and how do you do it? So just write ubectl set image into the deployment and what's the name of the deployment? It is enginex deployment and what would be the value of that image? So engineix equals to enginix col.28. Earlier it was 1.27. Remember this. The moment I hit it, something changed over here. And watch exactly what is happening over here. Here you can see a new replica set appears out of nowhere. The old replica set is getting scaled down and the desired count is getting dropped and the new replica set scales up and its desired count climbs up to three. Now what is exactly happening at pod level? So cube ctl get pods. Now here what exactly 7:27:27 happened? The pods got replaced gradually and they didn't happen uh and they didn't got replaced at once. It happened one at a time. Right? So a new pod is created and what exactly happens over here? It goes into container creating then running then ready. Only once it is healthy Kubernetes terminate the older ports and then gradually this replacement comes into the action. Exactly like the analogy which we saw over here. If you remember my example from the earlier one. One second. If you remember the example from the hospital what was happening one doctor was going for getting updated then it comes back another doctor goes back for the training he comes back then goes the third one and then he comes back that is exactly what we did right now okay I 7:28:29 hope this made your understanding about rolling updates scripts and clear right now let us understand about rollout status so instead of uh us watching the pods manually and guessing whether the rollout finished. Kubernetes gave us something really very good and that wonderful command is nothing but rollout status. So what exactly this does basically it will uh definitely tell whether the Kubernetes has successfully finished the deployment or it will basically block and wait until the rollout gets completed and then it will print a successful message that this deployment is completed. So this command you should always run in a CI/CD pipeline right after you trigger the deployment. So you are never assuming success. You are always verifying it. So how do we verify whether this roll out got success or not? First thing is you can run a describe command or else you can just check the rollout status. So I will just run cubectl roll out status and here we are checking 7:29:31 the status for a deployment right. So deployment name of the deployment engine deployment enter. And here you can see deployment engine deployment successfully rolled out meaning the new changes has been rolled out to the people. Right now you might be having wondering what will happen if something goes wrong. Right? Now imagine that this newer version that is image number two that is from engineix 1.28 has serious work. First of all, let us verify whether it got changed or not. So, cubectl get pods cubectl describe pod take any pod and here enter here if you go to the image here the image is engineix.28 meaning the rolling update got successful but now what if something goes wrong right this 1.28 to it has some serious bug and the user are not able to login. The website is crashing. The payment section has stopped working. 7:30:34 So do we have to manually recreate it from version one from scratch? Definitely no. Kubernetes even took care of that thing. Remember what we just learned? The old replica set doesn't get deleted, right? It just gets scaled down to zero. Kubernetes keeps the memory of the previous revision so that it can switch back instantly. If I run c ubectl get replica set here you can see we have two replica set present right. If you remember I ran this exact same command earlier and at that time we just got one replica set right here we are getting two. Why? Because this this one this replica set is the earlier one which was serving the job and this is the new one which is now serving the traffic. Right? This is where the users have been uh actually experiencing the application. Right now, Kubernetes keeps the memory of the previous version so that we can switch back instantly. Now, let's see the revision history. Now, how do we see a revision history? So, we can write 7:31:34 cubectl roll out history for the deployment or you can write deploy name of the deployment it is - deployment. Enter. I need to do a correction over here. And here it says it's not cubect, it's cubectl. Now note over here it's very important. Pay attention because no one will tell you and this is something that I have learned based on my experience. Now here we have two columns. One is revision. Second is change cost. Now let's focus on the very first thing that you see over here that is revision. So this is the version number of the deployment. So every time uh every time the pod template changes for example changing the container image changing the environment variables maybe you're changing the labels it can be anything the cubernetes will create a new replica set and it will increment the revision number. So here it was earlier one now it is version number two. Now second you 7:32:35 have something called change cause. Now what exactly it is it is an optional description of why that change was made. Now you see none over here because no changes was recorded over here. Now if you want to visualize this uh I can tell you how you can visualize this right. So let me go back to excal draw once again and here I will draw the replica for you right the revision history for you. So here I'll just copy this step one it will be easier example for you to understand. So I'll just copy over here. So what exactly happens is this is nothing but your revision. So here this is your revision one. Delete delete. And here okay this is revision one. Okay. And this serves the traffic for uh let's say 1.14.2. Okay. And when I say 1.14.2 I'm talking about engineix image 1.142. 7:33:36 So this is revision one which serves the traffic for engineix 114.2. Now due to some reason you made some changes. Now it will create another revision. Now this will be nothing but revision 2. Now this time it will serve the traffic country the newer one and here the image would be 1.15.1. Now you made again one more change and here uh the revision will change to revision 3 and this time the version would be 1.16.1 and let's say you are done with the final change and then you released the final version and that would be nothing but revision 5 and let's say this will be nothing but 1.17.0. So each revision corresponds to a different replica set and that's what I wanted to explain. Right. So next is why this change causes none. So Kubernetes does not automatically record why you changed a deployment. So if you uh ran something 7:34:37 called cubectl set image and you change the image version to something else the roll out happens but there is no reason which is stored. So in older version of cube cuttle we used to annotate the changes. we have to define the change cause and or we might we used to make use of hyphen record. However, these things are deprecated. Nowadays, you typically add the annotation yourself if you want to change the history. Right now, if you want to view the details of a specific revision, how will you do it? Let me clear the screen. So for that you will just run cubectl rollout history followed by the deployment name. It is nothing but deploy and the name of the deployment is engine deployment and which uh revision you want to get a detail for. Here I will write revision and I want to get the detail for the revision number two. Enter. Here what 7:35:39 sort of things you get? You get the name of the label, you get the template hash and the most important is the image. Right now you see the image, the current one which is serving is enginex 1.28. If I do the same but here I change the revision to one. Here you can see the image is changed to 1.27 and that is the exact beauty of cube cuttle rule history. So this shows the bot template the container the images that was deployed in earlier revisions. Right now if you want to check the current version right of the uh now how do you know what is the current revision of your deployment. So basically you can make use of cube cuttle describe. So cubectl describe describe deployment. Let me just close this terminal. It would be better. Yeah. So cube cutter describe deployment engineext deployment. Enter. Now how do you know uh what is the current revision of the 7:36:40 deployment? Here if you scroll upwards here you need to search for annotations and under annotations you will see the revision number and here it says this is nothing but revision number two right and this is something that deployment is currently using. Now let's say you want to roll back to a previous revision. How will you do it? Let me clear the screen. I will just write cube cuttle roll out cube cuttle rollout undo and here you will need to write the deployment name so deployment uh engine deployment right and you want to restore it back to which version now see we only have two revisions right so here I will write hyphen 2 - revision reision equals to revision one right now we are at revision number two. So this will make it revision one and that would be the active deployment again. Right? 7:37:40 Enter. Now here what it says warning resource deployment uh engine deployment was previously managed with cube cut apply. Rolling back will not update the cube cuttle last configuration which may cause unexpected behavior on future. So consider using cube cuttle apply with your previous configuration file instead. And here it says the main thing deployment engine deployment is getting rolled back. It got rolled back and what it will do it will actually make the revision three and this will be your active deployment again. Right now if you want to list the revision how will you check how many revisions you have. Right? Again you have to see you have to run the command and here it will help you to check that how many revisions are present. Let us run the command and see uh what's the current revision version. So cubectl rollout history and here we will need to pass the deployment name. So deploy followed by 7:38:42 the deployment name. So engineix - deployment enter. And here you can see revision 3 is created and revision one is no more. Right? And here what we did we actually changed it to the previous stable version. And that is exactly what we do when we are not happy with the current updated changes. This is how we do a roll out undo. Right now if you want to check the current revision version again cubectl describe deployment engine deployment enter and if you go to the top here under the annotations one second here you need to search for the image here you can see the image got changed to 1.27 27 and here we need to search for annotations and here it is changed to revision number three and now I believe this actually makes sense so let us summarize whatever we learned so 7:39:44 far a deployment manages your application's pod with the help of replica set a revision is saved version of your deployment so whenever uh a pod template has been changed a new version will be created each revision is stored in uh as a replica set and what exactly is change caused. We actually saw change cost as none earlier. Now what it is used for it is an optional description why that roll out occurred and now you can inspect any revision and roll back to the previous version if necessary. Right? And that is exactly we run. Now let's actually undo the update. Now what exactly is the update? Right now you can see it is running on version 1.27. Now let me just change this and what I will do I will just set the image to version 1.28 and then we'll try to undo it right so cubectl set image engineext and it will be enginex 7:40:46 col.28 28 and we need to update this to deployment set deployment engineix deployment enter here it says deployment apps objected okay clear cubectl get deploy cubectl describe deployment ment followed by engine x col deployment. Here we are just verifying what image is running, what image it is running. And here you can see it is running on 1.28. Now let's actually undo the update. How do we do it? Clear the screen and type cubectl roll out undo followed by the deployment name deploy / deployment name engineix deployment deploy 7:41:47 and okay and that's it when I press enter it will change the it will make changes in the replica set and then it will further make the changes into the ports so what I will do I will again open one more tab that will be helping us in understanding what all life changes have been happening over the fly. I'll keep one over here and here we'll just mark one watch for replica set. So cubectl get replica set - w here you can see we only have two replica set which are present right and what I will do I will add one more terminal over here that will be helping us in watching the ports I'll split this terminal into two so that it will be visible for us so cubectl get ports - w and here it is keeping a live watch on the ports this one keeps a live watch on your replica set I hope This is visible. Clearing the screen. Okay. Now let me just undo the changes 7:42:50 and see what exactly happens. So cubectl roll out undo engineix deployment. Right. Enter. C dive changes. Watch this carefully. Kubernetes is now creating pods from the previous replica set and scaling down the faulty one that is version 1.28. It's exactly the same rolling mechanism we just watched. Right? Within moments we are back to a fully healthy enginex version and that is nothing but 1.27. So our users will never have to deal with the broken app for long and that's exactly what we did. Let me just run the command cubectl get deployment. And when I run cubectl get replica set, it's back to the previous one. And if I describe any one of the pods, so cubectl get pods here. If I describe any of the pod, so 7:43:51 cubectl describe pod, it will display the image version of the previous table one. Right here you can see it's nothing but engineix 1.27. Let's clear a few of the misconception. I see many people do it. Right. So this is something that many people repeat all the time. So that's the reason I wanted to highlight. First is rolling update. Rolling update edits existing pod. Basically this statement is really very false because it creates a brand new pod and pods are immutable. I'm repeating it once again. pods are immutable. So whenever someone says that rolling update edits exist existing pods basically it is completely wrong. Kubernetes what it does it creates brand new pods right second is deployment deletes all the part first. So basically that's the reason why rolling updates came into the picture. So this statement is wrong. Deployment does not delete all 7:44:52 the ports. It replaces them gradually one at a time. Next is replica set disable disappears after updates. So that is completely wrong. You right now only saw if I just clear the screen and if I show cubectl get rs replica set cube ctl not cube cl here you can see we have two replica set earlier it was one only so basically whenever you do any sort of update replica sort doesn't get disappear older replica set are retained for revision history. So this is subject to something called revision history limit. That is something that we'll look later. But for now just remember whenever you are making any sort of changes replica set does not get disappear. Next is roll back create the entire application from scratch. Basically this is completely wrong. It's a big misconception. Kubernetes simply reuses the previous replica sets configuration and skill it back up. This is something that I have been saying. This is something from my personal experience and that is what I'm 7:45:53 sharing with you. So uh let us wrap up things and I'll go back to my chrome and here I want to show you something and uh don't worry this deployment file I'm already pushed in I will be already pushing it to the GitHub so it will be already present over here right so before we wrap up here are few production best practices that I wanted to share first is uh whenever you're dealing in production always make use of version image never make use of latest in production ction second is uh always verify your deployment and how do you verify your deployment come back to terminal I'll close the remaining ones so cubectl rule out status deployment and deployment name engine deployment enter and here it says deployment engineix deployment successfully ruled out right now let's move forward that is monitoring right check pod readiness 7:46:53 iness before considering an update completely. Right? And next is test changes in stages before it goes into production. And the most important is always keep a roll back plan before you deploy right and that's exactly what we learn. So let's recap whatever we learned so far. Deployment don't modify existing ports. They create new replica set. That new replica set creates new ports. while the old replica set gradually scales down and if something goes wrong Kubernetes can roll back to the previous table version with the help of replica set in seconds. So if you want to understand the flow I'll come back I'll if you want to understand the flow I'll go back to escal it will be again like you have your deployment deployment will manage your replica set and your replica set will manage the ports and that's the exact flow that we have been learning from starting right and it is one of the most common things 7:47:54 that you will be asked in interview and yes before you go I have something for you that is nothing but the interview questions so make sure that you are able to answer all these questions because this is something that will be helping you out in long term. So let us go through these interview questions but I want you to pause the video answer each one of them because everything is covered right. Pause the video answer the first question. The question is what is a rolling update? I hope you answered it correctly. uh rolling update in Kubernetes is the default deployment strategy where the application is updated gradually by replacing the older pods with the newer pods in batches. So instead of doing at once here we are gradually changing the pods. Right? So this is something that you can say and if you want to add more things you can just say this approach ensures that zero or minimal downtime is been provided because some old parts continue to serve the traffic while the 7:48:55 new becomes healthy right so this is something that you can explain when someone ask what exactly is rolling update moving forward why doesn't kubernetes update pods directly the first statement that you should say is pods are immutable meaning most of their specification cannot be modified after creation. So instead of modifying the existing pod, Kubernetes will create new part and update the configuration and it will remove the older part once the newer part becomes healthy. So what happens when you follow this approach? So with this approach, it will help us in predicting the deployments. It helps us in doing easy roll back. It will help us in the consistent state of the application and this will reduce the configuration drip. So this also aligns with the immutable infrastructure principle which is used in modern cloudnative environments. Let's move forward and answer the third one. What is the role of replica set during the updates? This is one of the very 7:49:57 important question. So during a rolling update there are typically two active replica set. One is the older one which is serving the current version and there is a newer one which is serving the updated version. However, Kubernetes retains the older replica set based on the deployment history. So multiple replica set may exist in a cluster for roll back purposes. But the thing is only the old and new replica set are the active pass participant in serving the traffic during the roll out rollout period. Now which command checks the rollout status? So the command basically it's nothing but coupube cuttle rollout status followed by the deployment and deployment name. I'll show you over here. Clear the screen cubectl rollout status followed by the resource deployment and name of the deployment. So engine x deployment enter and here it states the status that the engineext deployment was successfully rolled out. 7:50:59 Right? So this command continuously monitors the deployment until it is successfully or until it is successful completely or it fails. So if you need to do troubleshooting then the first thing that I would recommend is to make use of describe command right and then followed by just run cube cut replica set get replica set and then run cube cuttle get ports. This is where you will identify where the rule out is stuck. Now the next question is how do you roll back a deployment. So basically again you will make use of revisions over here and here you will make use of cube cut rollout undo deployment followed by the deployment name and here you will provide the revision number right and that is exactly you perform the roll back on deployment. Next is why rolling updates are preferred in production. Right? Why? Because here the pods are not getting killed. We are creating a new replica set a new replica and that will be creating new ports for us that 7:52:01 will be serving the new traffic and here we are not deleting the entire source we have our base ready with us so if something goes wrong we can go back to the previous revisions and that's the reason rolling updates are preferred in productions right let me scroll down and here let us go with the key takeaways of this video right and before we close there is uh one more experience that I wanted to share that uh let's say if you want to uh and that's something that I can tell if someone asked you uh have you used rolling updates in production so what can be the correct answer or what can be the answer that you can say basically you can say we always deploy application with the help of deployments and with the help of rolling update strategy it becomes very much easier why because updating the container image uh we verify I because before even we update the container image we verify the readiness and liveless probe and ensures that the traffic has been rooted to the 7:53:03 healthier airports. So based on the application availability requirements what we do uh during the deployment we monitor the uh rollout status with the help of cube cuttle rollout status and that will help us in monitoring the current uh state of the deployment. So if any issue occur we immediately perform a roll back using cube cutle undo uh roll out undo command and this approach allows us to release the newer version with minimal down minimum downtime while maintaining the service availability. I hope this actually helped you. Now let us go with the key takeaways here. We learned about deployments. Deployment manages replica set. Replica set manages pods. Right? Then rolling updates are used to replace the part gradually instead of deleting everything at once and creating another. Now what exactly is the benefit of rollbacks? It helps us in restoring the previous version with the help of provision and that is how Kubernetes minimize the downtime during the deployment. I hope this video gave you a 7:54:05 complete idea about rolling updates and roll back and things are making sense to you and whatever things we did I will definitely push it into the GitHub. We have created one deployment file and I'll just push it right now right away so that you have everything handy in front of you. 7:54:30 One second deployment for updates. So I am adding this file so that you have handy. So add get push and yes things are in your plate. Now go to the browser refresh it and you might file the deployment.ml file too. So you have everything now you can just go through the documentation go through this video once twice thrice perform alongside with me you will get a complete idea you don't need to spend money out there for any sort of training because believe me I'm trying to make things very much easier and relatable for you so that you can get all the concept together in this video right so the video length might increase so don't worry about that just focus Focus on the concepts and don't watch all the videos at once. I would recommend all of you to just go through 7:55:32 one video, learn the concept and move forward with the next one because everything is linked with the previous ones. Right? So yes, on that note, thank you very much for watching this video and I will see you in the next one. Thank you very much and keep learning. So in the previous video we have gone through deployments. We know what exactly is replica set. How does deployments and replica set work together to make sure like your application is up and running. Right? So here we have literally covered 80% of workloads that you will be dealing with in Kubernetes. But there is another uh player in Kubernetes that literally helps you out with uh important job uh that literally helps you to save tons of hours. Uh here we are talking about demon sets. Now what exactly is demon set? why it is used, what are the application that is something that we are going to learn in this video. This is going to be a longer video. So I will request you to take your notes, grab a coffee, open the terminal and enjoy the 7:56:33 video and make sure that you are utilizing this video. You are getting maximum out of it because here we are not just only learning the theory of demon set. We are going to do the practical hands-on so that you are left with no doubts. Right? So on that note, let's get started and I'm very much excited to run demon set with you all. So let's get started on a positive note. Okay. So let's get started with demon set. So for this specific tutorial, we need to do few sort of configuration. Now from the starting of the tutorial itself, we have been using mini cube addit mode. So for this there is a small change configurational change that you will have to do when you are doing the same demonstration uh in mini cube. Right? But again feel free to explore kind and cube adm. Now again if you want to know where exactly and how exactly do we install things go to subreository number one and here we have segregated all the three installation methods. First is kind installation cubernetes and docker. Second we have mini cube installation which I believe maximum of 7:57:35 us are referring to and third we have cubeadm installation. Now if you are someone who is performing this uh practical demonstration on AWS EC2 then feel free to check out the same on cube adm basically the difference would be in uh kind basically we have uh environment setup inside docker itself when it comes to uh mini cube basically right now we have only the control plane that is acting as both is playing role of both master and worker node but again after uh the configuration which I'm about to tell uh you will be able to uh make it just like a master and slave architecture that will be working very fine for you. Right now again third uh one is cube ADM installation. Now if you are someone who is referring the tutorial and you are actually performing the operation in AWS or on any cloud uh make sure that you are running the worker node.s script uh on multiple worker nodes. Why? Because a demon set is something that will run on each node individually. Right now what exactly is demon set? Let's go through it. But 7:58:37 before even we jump into the exact configuration on dimmer set uh there is one configuration that I want you to make uh into your mini cube so that things will be easier for you. Right now whatever commands again we are going to execute in this specific video is already been documented and that is in subdirectory number 11 demons hyphen kubernetes. So there's something that you can refer and uh we are good to start with today's demonstration. So first of all the first thing that we will need to do is we need to first uh delete the current mini cube setup right now why exactly we are doing so because in the current setup you have a single control plane that is acting both as a master and worker node right but we don't want to do that because this is something uh we want to perform a live over here we want a node and for the same reason we will be increasing the count of node over here right but for the same we need to delete the current configuration so just write mini cube delete delete and this will delete your current setup in the current cluster 7:59:37 that you have set up in your local environment. Now second is when it is done then you have to just run the second command. Now what exactly this command is saying? Basically here we are defining the driver and driver again what exactly we are using here as a container runtime. Uh we are making use of docker right now here I'm passing one flag that is hyphen nodes equals to three. So basically what I want is I want three nodes to be present. one would should be the control plane and two will be the worker node by default. Right? This is something that we would be working on. Right? So once the mini cube cluster is delete let's run the second command uh where we are specifying the number of nodes we want. Now if your PC if you have good memory in your laptop in your device feel free to experiment with the nodes but for now I think three will be sufficient. Now what exactly this three signifies it will count both uh your control and worker node. So control plane will be one and your worker node will be two and uh that is how we are doing the calculation for three. Now again if you want a single control plane and you want three worker node just increase the 8:00:39 count with four right. So for now for this demonstration just I'll just keep the count as three and I'll press enter. Now what on back end it will do it will just create your cubernetes cluster the mini cube cubernetes cluster that you had earlier but the only change here would be like instead of having a single control plane which acts as an master and worker node you will have a dedicated control plane and a dedicated worker node so that you will be able to perform today's task right so meantime it is uh booting up the control plane and the remaining thing let's get started with demon set right so uh let's first understand now I believe you already have gone through this documentation and once you are done with the initial configuration just run cube cuttle get nodes and it will give you the output which will resemble just like the below okay it is something that is running at the back end so I don't want to waste time over there we will directly jump into the concept right so once it is done I will run cube cuttle get node so that you will have a clarity what exactly I'm speaking about basically the intended output would be the below which is actually mentioned 8:01:40 over here now let's come to the main point uh the thing that we all have gathered here to learn about. Yes, it is something what we call as demon set. Now before even we understand about demon set, let us uh understand about the problem statement that demons set it solves. Right? So for this uh I want you to imagine like uh let's say uh imagine that you are running a kubernetes cluster and in that cluster you have three worker nodes right uh worker node one, worker node two and worker node three, right? So basically it is nothing fancy. It is a totally normal everyday cluster. Uh now someone from your company comes and they tell you one requirement that uh we need a log collector that should run on every single node in this cluster right so it sounds really very simple right isn't it? So what is the very first thing that you that is coming in your mind like based on all the things that we have learned so far right. So basically if 8:02:40 you are someone who is following the previous videos u you will think like okay uh since we have learned about deployments so it is it is very easy thing uh what you will do we'll create a deployment and then uh the deployment will contain three replicas so the requirement will get satisfied that is three nodes three replicas and the work is done right but let's actually test that in a test that assumption right because this is exactly where maximum of us get things wrong right because here we are not even aware of the concept of D1 sets right so let us understand why deployment doesn't work here because I don't want you just give you theory that deployment won't work here but why doesn't it work that is the thing that we are going to discuss over here right so here is there uh here there is a very critical thing that we need to understand that a deployment guarantees the number of replicas it does not guarantees that it will run the pod on the node I will repeat it once again a deployment will guarantee that the number of replicas that let's say if you 8:03:42 want to run three replicas on a node right so it will make sure that those three replicas are meet that actually it is meeting the count that is it is actually meeting the desired number right it will not guarantee that when a new node will be adding into your cluster it won't add a new pod automatically by itself right the kubernetes decides whether each pod goes uh where each pod goes based on the resource availability and some scheduling contraints, right? So, uh if I put it into simpler words, the scheduleuler has zero awareness about where to schedule your nodes uh evenly on the on the pods, right? So, the scheduleuler has zero awareness about scheduling your pod onto the new nodes evenly, right? So unless and until you explicitly explicitly configure it uh basically the behavior will be like this only and even then uh it will be a very best effort constraint that you would be doing but it's not a guarantee that things will be done but again this is 8:04:42 something demon set offers you in practical when you deploy three replicas onto a three node cluster uh what exactly can happen basically like uh there will be two pods on node one uh one pod will land on node node number two and basically node three will be empty meaning zero pods present over here right so if your company's requirement is to collect the log uh if your log collector's entire job is to sit on every node and forward the log to uh some another node from that node then here in this case node 3 is actually blind uh any application log which is generated in node 3 we won't be having that visibility right and in a production basically in a production incident u that's can be the one node that you will need a visibility into right and in the current setup you don't have anything now here we are talking about just three nodes now imagine if this node count 8:05:42 increases to 50 or maybe even 200 you will have to babysit things you will have to check the replica count you will have to manually calculate the entire rules you will have to constantly adjust the nodes uh and you have to manually check whether it is added or removed in your cluster, you will have to do the autoscaler thing manually and it will be very fragile and it is something that cannot scale. Right? Now through this what exactly conclusion we can come up with right the conclusion that we can come up with is deployment solve the problem where uh basically we say give me n number of copies for this specific application but the problem that they don't solve is give me exactly one pod per node and this is something that has been solved by demonset now what can be the second problem that is node coverage so this is something very different category of requirement and Kubernetes uh gives us this purpose-built resource for this specific utility this specific 8:06:43 requirement and that is nothing but demon set right so uh if you want to understand demon set what exactly demon set is something that runs in the background demon in Linux is something that runs at the background right so when it comes to demon set in Kubernetes just imagine a cluster and there are multiple nodes so on that node node we need a single pod that should run every time whenever a new uh node is added into that cluster that thing can be performed with nothing but by demon set right now if you want to relate this with real world I have an analogy for you so you can refer this example right so let's make this a very concrete analogy so that you can actually visualize and things will hit into your brain right so imagine that you are in a shopping hall and they have that they have multiple floors Right? And the management has a policy that every floor should have one security guard and every floor must have one CCTV recorder. 8:07:44 Right? So if you map this into Kubernetes, basically your uh floors uh your mall's floor is nothing but your node. Uh the security guard on every floor is nothing but your demon set pod and the mall management policy is nothing but your demon set controller. So when the mall adds a brand new floor, say a new wing, the management doesn't wait for someone to manually notice it and manually hire a guard for it. The policy will automatically uh will do something like they will arrange a new guard immediately. Demon set exactly works the same way. So the moment when a new pod joins right what it will do the controller will notice that and automatically it will schedule a new pod onto it right there will be no YAML changes there will be no replica math that we would be doing there will be no manual intervention it just happens automatically and that's what something that demons does. So let's go with the definition itself. Uh demons set ensures 8:08:46 one copy of a pod that runs on every eligible nodes in the cluster. Right? Now here we have an analogy. We have node 1, node 2 and node 3. Right? And in this cluster basically we add node 4. So whenever node 4 is added into this cluster there will be one part that will automatically get scheduled on node number four. And that is exactly what demon set is supposed to do. And that is exactly what demon set does. Right now what exactly is demon set? U demon set ensures that one copy of pod runs on every eligible node in a cluster. Right? What is the job of deployment? Deployment job is just to sk it schedule uh it makes sure that the replica counts are maintained throughout the cluster. The scheduleuler decides where uh multiple replicas can land on the same node. Uh same nodes might get none like some nodes might get none right. But when it comes to demon set here we just say I need exactly one part per eligible node. There is no desired replica count 8:09:48 that you need to configure. The node code is not based on the replica count is basically something that is dynamic. So as soon as a new node is added into your cluster, boom, a new pod is added automatically without you doing anything over here. Right? So yep, what exactly we are doing over here? If you just go through this specific diagram, what exactly is happening? Let me explain you. So when you added the node number four, when the node four joins your cluster, what happens? You didn't touch a single line of YML. You didn't run cube cuttle scale command. You didn't run any sort of cube ctl commands. The demon set cont the demon set controller is watching your clusters node and it will monitor it continuously and as an instant uh as soon as it detects that node number four is added what it will do? It will schedule a port right there. That's the whole proportion u that demons itself. Now okay we 8:10:49 learned about demon set but what I what is the actual practical use case? So I have few uh areas where we have used uh demon sets in production that is something that I want to display to you right. So this is something uh not a theoretical thing that we should talk about like yeah definitely we have planned hand zones in this specific video itself. You don't even have to switch another window. uh but for now let's focus on the theory and let's understand where exactly demon set can come into handy and can make your life easy right so uh demon sets are running literally in every production cubernetes cluster on earth right now and basically it is invisible but it is actually present so in the cube system name space like these are the few of the things that basically we run into the production one of them is uh fluent or fluent video now what exactly it is used for it is used for node level lock collection. Second, we make use of Prometheus node exporter. Now again, if you're someone who is coming from Graphana background or Prometheus 8:11:50 background, you might be aware of this data source, right? What exactly it does? Basically, it gathers the node level matrix. Now that metrics can be CPU utilization, it can be memory utilization, it can be the disk usage, it can be the network usage, it can be anything. Now again if you are dealing with promethus and graphana and if you are into cloud native environment basically you might be again aware with this specific plug-in that is cube proxy. So this comp component implements the cubernetes networking rules on every node. Next we have sienna plugins uh such as calico flannel and selium. So what exactly it is used for? It is used for pod networking uh which has to exist on every node for the parts to communicate. Then lastly we have security agents. So these are the runtime threat detection tools. Uh now it can be anything like uh you might have heard about Felco or endpoint agents or it can be any sort of compliance scanner. So every single one of these tools shares the same characteristics that is it has to exist 8:12:53 on every node because there is one thing that is common that it can be used for monitoring. It can be used for securing it can be used for networking in local for that specific port. Right? So you cannot uh collect uh node 3 logs from a port running on node one. You cannot expose node 3 CPU matrix to node one. It has to be local and that is the signature of demons the demon set use case right now I think enough theory is done and I think uh this is the very correct time to start with the hands-on let me go and jump to my terminal and here my mini cube is ready to let me just run cube cuttle get nodes and when I press enter here you can see we have the control plane ready here we have mini cube m02 ready as a worker node And here we have mini cube m03 again present as a worker node. Right? So uh before creating the demon set it's a very standard and a good practice that 8:13:55 you should run uh you should know how many nodes are present. How do you know how do you calculate uh how many nodes are present just run cube cut get nodes and you will get the output like this. And here you can find how many nodes are currently present. Right? Because that number tells you exactly how many ports you should expect once the demon set running. Right. So here in this example we have one control plane and here we have two worker nodes. Right. So basically here uh we can do the work and again like in few of the case it's been seen that uh your D1 set also runs on your control plane but again that can be avoided with the help of taints and tolerance. What exactly are taints and tolerance? Don't focus on it now. Just remember the words taints and tolerance is something that helps us in uh not scheduling pods on few specific nodes that helps us in identifying the current uh node that we want to target too. If you didn't understand don't worry we are going to cover that thing in depth later in this video in the coming videos but for now 8:14:55 just focus on the concepts of demon set. So just keep these numbers handy and remember the concepts and I think let's start by writing the demon set file itself. Right? what you see. So let me write the demon set file. So whim d a m o n demons set yiml and this is the extension. Now let's start with the manifest file. So what we are going to do we won't go to Google chrome search for kubernetes docs. Yes the entire world is doing that but no one actually helps you to understand what exactly each line means. Right here we are going to do each and everything on terminal. We are going to troubleshoot everything on terminal. we are going to understand what is the meaning of each and every line because that is something uh that we came here to learn for right because if you want to learn copy paste thing then I'm not sure that this video will help you for that but again if you're here to understand everything in detail then this is something that you should definitely give us a shot right so let's get started and create the manifest file 8:15:56 from zero itself right so whenever you're creating a manifest file in kubernetes or any resource In Kubernetes, what are the four building blocks that you should remember every time? Pause the video and write the answer in the comments or write the answer in the description. Let me know. I hope you all have answered. Yes, the four building blocks are nothing but API version, kind, metadata, and spec. So API version API version kind metadata and we have the last one nothing but spec. All right. So these are the four building blocks for creating any sort of manifest file in Kubernetes. Now what exactly are we trying to create? We are trying to create demon set right? But I'm not sure what exactly is the API version. Where do I check it? Well basically we have two methods. First go to the cubernetes documentation. Search for the demon set documentation. Copy the file. Paste it over here. And another simpler method is 8:16:58 just run cube cuttle api- resources and when you press enter you'll get the entire list. But again here we are making use of GP to make our life easier and that's the reason when we are learning Kubernetes it's said that you should know basic Linux and you should have a good understanding on docker so this is where things come handy it's not like you have to be professional in everything just know few of the things that will be helping you at helping you out in some operational thing and like life is easy right so here we want to grab a demon set so I'll just write d a m o n and when I Press enter. Here you can see we can see the API version as app/v1 which is exactly what we are going to use. Here we came to know about uh the kind that we should use the short alias that we can use for listing the demon set. All right. So on that note uh with this information let us uh correct our manifest file. So here I'll just try 8:17:59 to update the API version and here the API version is app/v1. So apps / v1. Then what exactly is the kind? Right? Now only in the documentation we saw it's nothing but demon set. So d a e m o n demon set and s is in capital letter. Third is metadata and then here in the metadata we'll define the name of the resource and what's the name of the resource. I'll make use of engineix that uh that the reason I'm making use of uh engineix over here. So engineix demon set. So d and city t1 set again now comes the configuration and where do we define the configuration? Basically we define the configuration in nothing but in the specification. Now again as I mentioned earlier uh when you are creating the manifest of demon set just keep one thing in mind what's the difference between deployment and demon set. So basically if you see the manifest file for demon sets and deployment it is 8:18:59 pretty much very same. The only difference between them is demon set does not contain replicas and deployment do contain replicas right that's the only difference rest everything is same I'm going to show you more both the manifest file side by side so it will make sense to you so now the next thing is since we are dealing with the specification what all things we need to do now hereh we want the port to run on the new node every time uh whenever it is added to a cluster Right? So on what basis it will make sure that the things are getting scheduled right here we need a mechanism through which we can look at it and yes we have something called labels and selector that will come handy into this specific section. Now again if you're not sure about what is labels what is selector and you want to do a deep dive into it. We have a dedicated video on uh labels and selector. So feel free to check out that now. So assuming that you have already gone through that video and you have maintaining the consistency. So let's start with the 8:20:00 selector first. So I'll just type selector. So in selector we basically on what basis we are going to match the things. We need the labels on which we are going to match the things. Right? So here we'll define the match labels. So this keyword basically defines the labels that we are targeting to. And here I'll define the uh label as app and the value the key is app and the value would be engine x - day one. So whenever u in a cluster a node is added and it contains the label app coline xdemon it will search for that label and based on that label it will target it and once it is located the next instance when you check it you'll get a new pod running on that new node right now since we have defined the selector the next thing that we need to do is we will need a template through which it will create the part for it right so here I will define the template so selector and Just at the same level we will define the template. So template now inside this template we will need to 8:21:01 pass the metadata. So metadata and metadata basically again he will here basically we will pass the labels uh that will be added to that new port which has been created. So labels and here we are targeting to targeting to nothing but app engine x- demon. Right? So template is also done. Now here since we are creating a pod here we need to define the template for this specification make sure you're following the indentation because again Kubernetes is very strict with it strict with this with its indentation and YAML provides that indentation rule that will help us to write the manifest file. So I'll write spec over here. Now again if you're not comfortable in terminal uh try to do maximum work in terminal. If not feel free to do the same in Visual Studio Code because that will help you to uh write the ML file in the easiest way. uh I would request you one thing that uh refrain using AI over here because see if you have a practice of 8:22:01 writing the manifest file from the scratch then uh it would be very much easier for you to understand the entire manifest file uh into the production environments and believe me this is something that is coming from the manif uh from the experience itself because I have seen engineers who know Kubernetes but they're not even sure how does the structure looks like that confidence can be built when you are actually writing the manifest just file by your own hand right so enough GAN for now let's continue so here in this specification what exactly we are trying to create we are trying to create a pod right and basically what exactly that pod run it runs a container right so let us define the container over here so containers now that container will need a name so what would be the name that you you will give to that container so here I'll give it as engineext now that container Here in order to create that container, we'll need a blueprint, right? We need a docker image. So here I will pass the docker image. So here I'll write image and here I can use any image uh engine 8:23:05 latest or engineext uh 1.27. This is something that I'm using. Now again uh if you want to add more detail over here. So basically you can also define the ports ports basically on which port basically your container runs. So here I'll write the container port. So, engineix as we are already aware that it runs on port number 80. This is something that we have created. Now again escape WQ. I know there will be few people who will be like what exactly just happened? Can you explain it line by line? Well, exactly that's the reason I'm over here and I'll be able to help you out with that. First thing, let me just verify whether the configuration file that we created is actually valid or not. Just type cubectl apply - app demon set.l enter enter. And here it says demon sets app enginex demon set is created. Let me take you to visual studio code because I want to explain you the demon set file line by line in 8:24:06 detail so that you will have a good picture on what exactly happening in the scene. Right. Let's go with line number one here. What exactly do we have? We have API version. So what it exactly does it tells the Kubernetes uh which API group and version to use to interpret this resource. So demon sets like deployments and replica set this fall under this API version that is app/v1 right earlier people used to make use of API version like extensions uh you know uh version one beta 1 but if you're using uh the latest version of cubernetes the modern cubernetes cluster will actually reject manifest right away because that API was actually removed years ago but again you won't see it uh anywhere as of now but again if you see some line commented where you see version 1 beta 1 it's actually the older version of Kubernetes the older API version that it used to support right but again what exactly is API version it tells Kubernetes which API group and the 8:25:08 version to use for interpreting this resource next we have kind and in kind we have defined demon set so this tells this basically this field tells Kubernetes API server what kind of objects we are actually asking it to create everything else uh uh is in spec is interpreted according to the uh demon set schema because of this exact one type. Now here we have metadata. Now if you want to read the metadata basically we are giving the name to this resource and what's the name of this resource? It nothing but engine demon set. So when we create this demon set the name of that demon set will be nothing but engineix demon set. So this is simply the name of the demon set object itself. uh how you will refer it with cube cuttle get ds command and cube cuddle describe command and so on. So this name has to be unique within the name space. Next is spec spec basically here stands for the specification the configuration and the first configuration that we have is nothing but selector. So this is one 8:26:10 of the most important and the most misunderstood parts of the whole manifest file. Uh what exactly selector does basically tells demon set which pod it belongs to. The demon set controller consistently will watch the cluster for the new node and as soon as it sees that it will check it will try to create the pod only if this selector labels match. Right? Next we have template. How do you read this? Basically if you are referring something inside the spec you will uh read it as spec dot selector. If you are referring something inside spec and you are targeting to template so spec template right and if you want to refer match labels inside selector it will be spec dot selector dot match labels. I hope that analogy is uh clear now. So let's talk about spec.mplate. Now what exactly it is? So it is the part template. It is the blueprint uh Kubernetes will use every time uh 8:27:10 whenever it needs to create a new pod for this demon set. So whether that's the very first pod or a replacement after a crash or a brand new uh one, it is something that this template will be taken care of. And if you remember earlier we have created pods with the manifest file. And if you exactly cut this and if you just match it with the previous one, you will get the exact same output because this is something that we have created earlier. And now if you are able to jot down the pieces here we are actually creating the template that will help us to create the pod and that pod will be created on the nodes as soon as it is added to the cubernetes cluster. Now again let's talk about metadata and inside a metadata here we are defining the labels right and the label is nothing but app engineext colon demon uh did you notice one thing on line number 12 and on line number eight we have the same labels that we are referring to right basically it's the key is app and the value is engine demon right so basically this should match 8:28:13 this must match basically this is the connective tissue between the selector and the actual plots. If uh these two doesn't match, Kubernetes will reject your manifest with the validation error. And um this is single most issue that most of us actually try to make when you are trying to create the manifest file for the initial time. But again uh with the practice uh you would be able to mitigate those issues and it will be completely normal that if you're facing issues with the manifest file feel free to paste the error and definitely cubernetes community is really very awesome many people are learning many people are breaking things many people are sharing their knowledge so there will be always one person in the entire world who will be facing same issue as you are facing right it can be anything no question is a silly question the thing is whether you are asking yourself the answer. You should know where exactly you're pointing the things because you will have the question only if you try to understand the things. Right? 8:29:13 So on that note, let's continue further. Here we have specification. Now under that template, we have defined a specification where we have defined the containers. Now again what containers uh basically we want to create? We want to create the container namex which will make use of the image called engineext col.27 27 and it runs on port number 80 and that's the reason we define the same this define the actual containers that will run inside every pod uh the demon set will create in our example it's simply engineext 1.27 27 container which is listening on port number 80. Right? So in a real production demon set is u where you define your log shipper your metric exporter or your security agent. Uh basically along with any volume mounts it needs to be a read hosted level uh for providing us the logs and the metrices. So if you are someone who have a graphana architecture in your company basically you can relate to it with it. Basically uh we keep a log 8:30:16 exporter on every node which helps us in identifying which CPU is uh running fast which node is consuming maximum memory. So those sort of information we get with the help of this sort of things which we call as nothing but demon set. And if you notice something interesting compared to deployment there is one thing which is missing over here. I'll tell you there is no replicas field present anywhere in this specific section right what I'll do I'll just open any of the deployments that we have created I will open this deployment side by side it will give you a complete idea exactly what I'm talking about so here if you see here we have the API version okay that's correct then again we have the demon set that's again correct here we have the kind as deployment under the metadata we defined the name of the deployment and here we have defined the name of the demon set. Then under specification here you see replicas is equals to three is mentioned but again here in demon sets case that is not 8:31:17 present and if you see everything clearly everything matches the same. All right. Here they have selector. Here they have selector two. Here they have defined the template with the labels. And here we have defined the label. Uh here we have defined the template with the label. Again here we had defined the specification for the container. The blueprint is also defined. And again here in the same case we have used the same specification that we made using in deployment. And I hope things are clear to you what exactly is the difference. If someone comes and asks you what is the difference between demon set and deployment. The only answer that you can give is demon set doesn't contain replicas. Deployment contains replicas. Second uh what you can say is uh deployment make sure that desired number of pod run into a current node into the specified node. But demon set make sure that whenever a new node is added into a cluster, it will make sure that one pod will definitely run on that matching 8:32:19 node. Right? And that's the basic difference that the actual difference between demon set and deployments. I hope things are easier for you and you are able to understand things right. Let me go back to my terminal and we have already applied the configuration file. Right? You should see the confirming output like this which is mentioned over here. So now let us verify whether the demon set is actually created or not. So I will run cubectl get demon set answer and here you can see the output present over here. You should see output like desired is three, current is three and red is three. Right? So what exactly it says basically look at the desired column right? This one what exactly it says it says three matching your uh worker node exactly uh just like we predicted earlier right we have created node equal to three and that's the reason where we have desired count as 8:33:21 three right and this is the moment conceptually like things click for lot of the people didn't ask you how many pods you wanted it looked at the cluster it counted the eligible nodes and it figured out things on its own and that is the actual beauty of using demon sets. Right? Let us verify the pod. What where exactly it is created. Now you only tell me if you want to verify uh where the pods are created. How will you get it? How will you get that information? Pause the video, remember things, memorize it and then let me know what exactly think that you are going to learn. Right? How do you get that pod? How will you list the pods? I hope you have the answer. If not, please go through the previous video under understand things and come back again. Yes, in order to list the ports, you will run cube cuttle get ports hyphen ovite for getting more information. Why? Because cubectl get 8:34:22 pods will just list down the ports. But where exactly it is created? This is something that will get you by hyphen ovite. But again here you can see demon set is created. It's up and running in mini cube m03. D1 set is here up and running in mini cube M02. D1 set is up and running in mini cube and that are these are the actual nodes that we have created earlier after deleting the current configuration file in mini cube right. So that is exactly uh what we were learning right. So in this output basically uh we are paying attention into the desired number of nodes. Uh basically how many nodes uh how many uh nodes should have a pod. Here we have current number of nodes scheduled how many nodes currently have a pod and number of node misscheduled. So basically what exactly is it is uh that's something that we can get after running the describe command. How do we get those information? Basically you need to describe your demon set. So cube cdl describe 8:35:25 demon set or I'll write d s and followed by the demon set name. What exactly is the demon set name? It is nothing but engineext happen demon set. Enter. And here is something that I was referring to. Right here you can see uh design number of nodes scheduled current number of nodes scheduled current number of nodes scheduled with up toate ports current number of nodes scheduled with available parts. Here we have number of nodes which are scheduled. Now what is the meaning of this? So pods running on nodes uh they shouldn't be like this should always be zero in uh healthy cluster. So that's the meaning of it. And then we have the port status. Now what exactly is the port status? It says uh it it is running the pod where there are zero waiting ports. There are zero succeeded and there is no failure. So in a healthy demon set desired and current should always match. That is exactly what is happening over here. desired number of nodes is actually matching the current number of nodes. So if you don't see this number matching 8:36:25 then there is something uh issue with that thing right. We'll cover the troubleshooting scenario later but again just f uh just focus on these two thing that desired number of nodes and current number of nodes should always match. Right now since we were talking about demon set let me just list it once again. So cubectl get odds and when I press enter now what I mentioned is uh let us uh see self filling in action. So in this part uh basically this is one of the favorite part because this is something that will help us to understand uh demon set in a very next level. So what I'm going to do is I'm deliberately going to delete one of the part. So what I'm going to do I'll just write hyphen ovide to get more context of it. So hyphen ovide and here you can see let's delete a pod from anyone. So I'll delete this specific pod from mini cube m02 right. So cube cuttle delete delete pod and followed by the 8:37:26 name of the pod. It is nothing but this. So I'll just paste it over here. What it says it got deleted from the default name space. Now immediately let me just run cube cuttle get pods iPhone you see there is another pod which is created over here right within a second or two you'll see a brand new pod created on the exact same node so the deleted one was running uh so the deleted one uh was running on this is the demon set controller uh doing its job it's continuously checking the actual state of the cluster against the desired state defined in your manifest file The desired state says that one pod on worker node one, one pod on worker node two, another pod on worker node three. Likewise, if anything is added in future, there should be this part which should be present over here. So the moment the pod is disappeared, the actual state fell out of sync and the desired state and the controller immediately corrected it. Right? So this 8:38:28 is the same reconciliation root pattern that you have seen in replica set in deployments. So demon said just apply it per node instead of per replica account. Kubernetes really is just running this uh reconcile loop constantly at the back end that we are not even aware of. So in the background so basically the background is like uh the controller who is taking care of everything. Once you say this pattern then you will be able to uh visualize Kubernetes literally every everywhere. Right? I want you to take uh notes from the MD file which I have prepared because everything uh whatever we discussed including the manifest file is already present over here right so that's the thing that I request you to go through it right so uh let us first understand uh the difference between demon set versus uh deployment so it's actually mentioned over here uh port count controlled by here in deployment it's controlled by replicas as you are already aware in demon set the port 8:39:29 Pawns are controlled by the number of eligible nodes. Now again here a new when a new node join what happens in deployment nothing happens automatically. But what happens in demon set pod gets scheduled automatically over here. Then uh does deployment have replicas? Yes. But in demon set no we don't. That's the only differentiator that you can see from your own eyes. Then what's the use case of deployment in this case? So here deployment can be fruitful can be useful for apps API and microservices but demon set on another level is something that runs on node level that will be very much handy when it comes to uh collecting the logs collecting the metrices uh for installing security tools that keeps a monitor on everything that exactly is demonet can be used for. So basically what we covered so far uh if you are uh adding a replicas field it does nothing demon set won't use it it will throw an error the note count is uh the node 8:40:29 count is the replica count right so that is something that we came a conclusion with right so now uh let us see few of the production cases and the challenges while uh we usually face during the scheduling so let's go with the first one that is Where are the demon set actually used in production? So uh we literally touched demon set but now we understand the mechanics. Let's go into much deeper and uh we'll see real world use case almost in every uh production kubernetes. Uh so right now the thing is in all the prod cubernetes clusters demon set is something that is running like literally every time everywhere right now as well. Now let's talk about the production use cases when we are dealing with demon set right the first and the most important and the highlighted one is nothing but log collection right so imagine a real production cluster with 50 worker nodes application are running on every single 8:41:32 one of them and they're constantly generating the log output right uh now what can be that log it can be your application log it can be your container log it can be your system log it can be your error log so if you try to collect those logs manually you will need to install and configure a lock shipper on one of those 50 machines by hand and then you will need to keep those configuration in sync uh until that node is up and then uh the thing is you will need to do manual operation work and it will actually become a nightmare. So instead of that what you can do you can make use of demon set that runs one lock collector on the port. Uh now what can be that tool that you can use over here? It can be fluent, it can be fluent bit right. So it will what exactly it will done? It will run on every node and it will read the log and it will share with you right. So each fluent bit pod uh will mount a host log directory. Uh typically it is with I remember its host 8:42:32 path and it will uh read the logs locally. there will be no network hop required to collect them and then it will forward those log to a centralized back end. Now it can be anything it can be electric elastic search it can be your graphana it can be a Loki or any SAS uh login uh logging platform right so this is the testbook uh demon set use case something that must exist locally on every node because the data uh it needs is to be in local to the specific node. So now what's the second use case of demon set it's nothing but in monitoring like in log connection you already might have guessed what exactly it is used for here we are correcting the lot but basically we need to monitor something right whenever we are talking about monitoring the first thing that hits into your mind is nothing but Prometheus right so Prometheus is widely used Kubernetes monitoring system here we make use of the plug-in called cube statrix that helps us in getting all the information of the cluster so if you need monitoring if you want to monitor 8:43:33 cubernetes system and you need more node level metrics such as CPU usage, memory usage, disk pressure, network usage u from every node in the cluster, this thing will come in handy. So a demon set will run a node exporter on every node and each node exporter uh will expose an HTTP endpoint with the matrix directly from the host uh running on it and then Promethus what it will do it will scrap each one of the uh these endpoints and then it will schedule and store it into a time series database centrally right so if you have learned Prometheus then I think these things are making sense if not don't worry just understand that Prometheus This is something that is used for monitoring and it generate logs. So those logs has been generated by demon set. That is something um that we are doing. But again you if you observed it's the same pattern. Uh the matrix for node 3 can only be meaningful if it is coming from something that is 8:44:34 running on node 3. Exactly. Right. Let's go with the third one that is networking. it comes handy cubernetes networking collectively known as CNI or what we can call as container network interface plug-in it is mostly uh run on demon sets for example calico flannel and celium so what exactly this is for basically it matters more uh than what exactly it seem so without a CNI plug-in running on every node pod on different node will literally cannot communicate with each other Pod networking is fundamentally uh per node concern. Each node needs its own local networking configuration. Um their routing, their allocation, their IP allocation and the policies that port should schedule on it. This is a foundational requirement that most managed Kubernetes offering install CNI like like Calico. So demons set automatically uh you know um 8:45:37 configure it the moment you spin up the cluster right then next we have service networking and here we are talking about cube proxy so let's look at a real demon set running in in your own cluster right now so what I'll do I'll just go back to my terminal once again and here what I'll do I'll just run cubectl get demon set a when I press hyphen a the hyphen name flag lead demon set across all the namespace on most of the cluster you'll see something like cube proxy running a cube uh system namespace as a demon set so this is something that we are getting output to right so cube proxy is basically responsible for configuring the networking rules so basically I don't want to go in deep dive into networking basically here we have something of IP tables or IPvs that makes the cubernetes service actually work it uh helps helps us in routing the traffic from a service virtual IP to correct the backend process ports. So 8:46:38 that is again taken care by nothing but the demon set right now let's talk about scheduling on a specific node. So basically here we have something called node selector. So, so far we assume that you want to uh you want a node on every node but sometimes you don't want uh maybe your log character needs to run everywhere but a specific uh specialized storage agent uh should only run on those nodes uh such as for SSD backend local storage. So this is where node selector comes handy and basically what exactly it does basically here we define the node selector and the type of the disk that it should utilize. So with this in place only the nodes carrying the label uh disk type equals to SST will receive a pod in this case right. And how do you get the details about the labels by the way right? So basically if you want to list down all the labels uh just go to the terminal just write cubectl 8:47:40 get nodes hyphen show hyphen labels enter and here you'll get the entire label information which are actually used over here and here you can see all the labels which are present over here right now uh let's move forward uh and yeah I'm deliberately skipping this section because this is something that we are going to cover in depth later. For now, just keep in mind that these things exist too, right? Uh we already discussed about taints and toleration. So by default, uh most of the cubernetes clusters apply a taint to controller plane that is master so that nodes are prevented for running the workloads into the control plane. So including uh the regular event set from being scheduling there. So basically why we use such sort of thing why we make use of tainted over the control node. Basically this is something that is intentional that's been done you don't want a random application pod uh com uh competing for 8:48:41 resources with the API server at CD and your schedule itself right but sometimes what happens is you genuinely want uh demon set in your uh controller plane right to keep to keep a monitoring for it. uh it can be a monitoring agent for now just take an example for now. So this needs to report on that uh node right so that we can get a matrix we can check whether the node is healthy or not. So in that specific section we will make use of ts and tolerations right. So what exactly is toleration? So toleration uh what it does it doesn't force the pod into a control plane node. It simply tells the scheduleuler that this pod is allowed to tolerate that t. So uh you don't automatically exclude it. So combined with the demon set's normal behavior that uh it is eligible on every node uh the pod will now also land on your control plane node. This exact pattern is extremely very common in monitoring and networking u with 8:49:42 demon set in real clusters. Right? If you don't got taints and toleration don't worry don't panic about it. This is something it's a very big topic that we are going to touch. uh taints and toleration is definitely that helps us in scheduling nodes on a selected uh nodes right so that is something that we are going to see later for now just focus on the concepts right so so far so good I think things are going really very good for us right here you can refer all the documentation here we have talked about updates rollouts demon set versus deployment which we already have covered so I want you to go through the documentation This will give you a complete idea what exactly things are currently going on. Right here in the hands-on quick lab I have already shared the commands that I am using right now currently. This is handy when you are doing the practicals by yourself. And again if you face some issues such as pod is not created then you can run this commands to check what exactly been 8:50:43 happening. Right? So before even planning this video while I was doing the hands-on at my own local desktop at that time I faced few issue. The first thing that I did is I just documented the issue right and like this is something that will help you so that yeah again whenever you are doing the revision or something you know like whenever pod is not getting created what exactly you need to check and this is something that we should know right so yes and here is again the cheat sheet uh whatever we have executed so far is presented over here so that you don't run here and there for uh you know the things okay Now here we have few interview questions that uh you can pay attention to. Uh for example uh what exactly is the problem that is solved by demon set that is not solved by deployment. Now pause the video and answer this and I know like maximum of the things are already clear to you. So things will definitely make sense to you right 8:51:43 now. What exactly is the problem that demonet is solving? Basically whenever there is a situation where the company is asking you to you know run a log collector on every node whenever a new node is added it should automatically create a pod inside it here we will make use of demon side deployment when not it's not applicable in this case why because here deployment is something that takes care of the replica count it maintains the desired set but what if a new pod is added from nowhere who will take care of it it's demon set that will take care of it Right. So yes, likewise you can go through the second question. Why doesn't the demon set have a replicas? I already have shown you. So I think you can pretty much answer it, right? Because demon set we are not caring about replicas. That is replicas is something that has been managed by deployment. Right? Demon side has nothing to do with replicas. So next is what happens automatically when a new node joins the cluster. Now you only tell me what happens uh automatically 8:52:44 when a new node joins a cluster. A new pod is created. A new pod with the matching results gets created over here. If we have configuration, right? If four real production issues case for the demon set. This is something that we discussed uh upwards, right? How do you update a demon set at once or uh or gradually find it out? You will get the answers, right? How will you troubleshoot a demon set if it is not scheduling as the expected uh nodes? Troubleshooting methods. You can go through this specific section where you'll find the answers. How do you restrict a demon set uh to a subset of node? Again, you'll find this answer on the same documentation. Eight. How do you allow a demon set to run on a control plane node again here what we are going to use? We are going to make use of ts and tolerance. Don't worry if that didn't made sense because uh we are yet to cover that. We are going to cover that later in depth in the coming video. So yes, that's the final mental model. uh deployment is something that uh make sure that the desired number of pods are maintained. Replica set is something 8:53:44 that maintains the pod count. It is managed by the deployment and demon set basically it maintains one pod per node and that exactly why cubernet is designed and launched demon set in the very first place right so yes that's the complete master class on demon sets and I hope maximum things are covered and you are left with no doubt even if you faced doubt in future feel free to write the things in the comments and description I will definitely try my best to help you out with that. If it is something that requires more attention, we'll create a dedicated video for it so that you can have all the answers that you are looking for. So let's take a final gut check on everything that we have covered so far. Actually, we have covered a very uh huge topic. So uh we started with why deployments uh cannot guarantee node coverage and why demon set can and then we discussed we built a demon set from scratch and explained u like the yaml we 8:54:44 have gone through this yl let me do one thing like before even I close this I'll open my terminal and push this file right now itself so get addit commit- m and here I am adding your demon set file so you will have it handy so demon setl added and then what I'm going to do is I'm going to push this to origin so that things will be present at your end. So get push origin and yes I think you have all the resources with yourself. So yes then what we did we basically saw the live demonstration what will happen if we delete a pod from a node uh will demonet respin it? Well exactly that is something that we saw. So uh these are the things that we have learned so far. So if this video helped you uh finally to understand demoncent end to end. So please share it with the people who would love to explore this concept and yes uh there are many things that are coming on the way right. The length of 8:55:46 these videos might get lengthier but uh focus on understanding one thing at a time because you cannot understand everything at one day right. So on that note I think we are good and like I'll just refresh to check whether the file got uploaded and yes demon set.l is also present and we are good now on that right. So yes that was all in this video and I will see you in the next one. Until the next time keep learning and thank you very much. A deployment job is to run an application forever. A demon set jobs is to run a pod on a node forever. But nothing in this world that uh want to keep running every time, right? Same is the case with Kubernetes too. So let's say if you want to run a database migration that is something that is a one-time activity. It just want to start do its work and then stop. If you want to run a night audit report, if you want to run a migration so these are the activities that need to start, run once and get completed. So for that we need a 8:56:48 different controller in Kubernetes and that problem is been solved by jobs. Now okay you understood why we need job. Now again there is one more thing is if I want to schedule something if I want to run everything in a scheduled manner but again it should start do it work and then stop. What do we have? We have chrome jobs right? In this video we are going to discuss about jobs and chron jobs that helps us with many benefits because jobs and chrome jobs are literally used in all the production environments. So make sure you are following this video. This video may be a lengthier one. So, make sure you are taking enough breaks so that you will have a complete idea what you are dealing with. Again, make sure you're watching the video twice and thrice so that you can get a maximum out of it. Take breaks, make the notes and then follow along with the hands-on. And again, I will emphasize on doing the hands-on because this will give you the complete idea of what you are dealing with. Make sure you are experimenting too. And again, everything is documented into the empty file. So make sure 8:57:48 checking out the same right. So on that note let's get started. So enough theory let's start with the hands-on but there is one thing that I want to mention is you can perform this demonstration on either of the cubernetes environments. Maybe it is cubeadm maybe it can be with kind maybe it can be with mini cube. I will personally follow mini cube because that is something that we have been start that we have been doing from the starting itself. So I'll continue with the same. If you are jumping in between uh this video, so make sure that you are applying this configuration which is mentioned in setup zero. Okay. And again uh all the things are documented in subreository uh 12 under kubernetes tutorial. So please uh check out the same. Okay. So the first thing is we now know that we are going to learn about jobs and chron jobs. But why we are not considering deployments in the first place? Why deployment is the wrong tool for this? Right? So let us first understand the same because this is something that we need a clarity with because see learning things is another part but understanding and implementing 8:58:50 thing is that is something that we are going to learn today. Okay. So right now what I'm planning to do is I'll just launch my terminal and here I will create one bad deployment. Okay. And that will prove the problem that instead of like me describing it, let's let us try it, space the issue and then we'll get to know what exactly is the issue. Okay. So let us create a deployment file. So when uh bad deployment dokml uh okay so one second we bad deployment. camel 8:59:32 bad deployment. ML enter. So now whenever you are whenever you are working with any sort of Kubernetes manifest file what are the four building blocks that you have to keep in mind. Yes. API version kind metadata inspect. So let me just write API version. API version kind meta data and spec. Okay. Now again since we are doing everything from scratch. Now if I want to know what API version should I use for this bad deployment how will I find it? I will make use of Kubernetes documentation. Well definitely it's a good source but again uh I want to do the same in terminal itself. I don't want to leave my terminal. I love my terminal. So I'll just write cube cl api- resources. And here I'll run a grap for deployment. 9:00:33 Enter. And here you can see the API version is app/v1. I'll again just go to my bad deployment file. And here I will just update the API version to app/v1. And okay, I'll just remove this colon too. 1 second. Here we need a colon. And here we don't. Okay. Now I will define the kind. So deployment again the metadata. What would be the name of this deployment? So I'll just write uh bad deployment. And then again the specification. Now since we are dealing with deployments, deployment manages replica set. So we need to define how many replicas we want. So I'll just define replicas for now. I'll just keep it as one. Then I will define the labels and selector. And here match labels. So app should be report 9:01:34 gen. And then uh I will make use of a template that uh would be used for creating the part. So template and for that template we will again need a metadata and in that metadata what I will do I will define the labels and then inside this labels I will just add the exact same labels that I have mentioned in the selector and then finally the next thing that we want to do is we will create the spec and now this spec will be for the pod for the container that we are planning to create. So containers and here what should be the name of that container? I should said bad report container and bad report container and the image that I would be utilizing for this one is nothing but busy box. Now what exactly is busy box image? It is a lightweight uh Linux uh distro that is used to run lightweight tasks such as running echo command doing pinging. So these are some of the operation done by 9:02:35 Vybox and here I'll just write the command and so basically whenever you define command basically what it does whatever things that you will write inside this braces will be considered as a command. So sh and here I will just pass hyphen c and what commands I want to run. So basically I want to run an echo command. So I will write echo and here I'll just write um testing and I will just uh end it and I want it to sleep for 10 seconds. So that's all we did. Escape WQ. Okay. So now what I want to do is see this was a very basic deployment file that we have created and what exactly we are planning to do. I will just apply the file and we are going to see the live change and we are going to watch what exactly happened. Uh before even we do that I'll open a new terminal so that we can keep and watch on the existing pod. I'll just 9:03:37 keep that over here or maybe at the bottom that would be better so that you can see the live changes happening over here right I'll just keep that in bottom okay cool that that's great okay so I'll just do a little bit of zoom over here and I'll run cube ctl get pods hyphen w for keeping an watch keeping an eye on the existing pod and the upcoming pods that we want to actually monitor right I'll just put it upwards. And now the next thing that I'm going to do is let me just apply the manifest file. So cubectl apply -f bad deployment it is right enter. Now here we got an error. Now what error says basically error from the server there is a bad request. Error when creating the manifest file deployment in version v1 cannot be handled as a deployment. Strict decoding error. unknown field spec dot selector dot match labels. So I believe there is an 9:04:39 indentation issue and here it already highlighted that where exactly we are getting the issue strict decoding error is mostly related to the YAML based errors and secondly he mentioned where exactly we should check into the match label section under the selectors right I'll go to my visual studio code and here is the file that we are looking into right so here it says spec dot selector dot match label so I think here it is and I I think the issue is with the letter it should be labels with capital L match labels and now when I again apply it this time it got created see that is how you do the troubleshooting right what we did we didn't follow any uh documentation we didn't went into Google itself we tried to decode the error what we got right we understood why it is saying a bad request then we came to know okay there is a decoding error now whenever a decoding error is that it is mostly related to the YML based error and 9:05:40 finally we got to know where exactly we need to check it. It told exactly basically spec selector match labels that is the area where we need to check right now if you see at the bottom I'll just pull it up. Okay, now watch here what exactly is happening. The container finishes after 10 second but the pot doesn't uh just say that it's done right. It will restart it then it will finish it again then it will restart again and that is exactly been happening over here and that is what I wanted to tell you over here. Now why this is happening? It's happening because a deployment's entire job is to make sure that the desired number of pod is always up and running like whenever the container exist even uh successfully the deployment controller sees that there is a gap that needs to be filled right and it fills it by starting a new container right as the backup right and that 9:06:40 behavior is perfect for something uh which we call as a web server uh that should never go down, right? So, uh the thing is uh it's completely wrong for a single task that you want to execute once, right? That is just supposed to just run once and stop. So, for that specific case, deployment is not a good option, right? So, let me first delete it and let me just explain you what exactly I'm referring to. So, cubectl delete-f followed by the manifest bad deployment. ML. Okay, I'll again go to my GitHub repository and here VR that exactly I want to explain. See deployment what exactly it is doing the main goal over here is just one sentence that I I want to say over here right the one sentence will make a difference between the goal and that goal that that job actually tells what exactly it is created for right deployment is optimized for 9:07:40 availability as it says just keep one pod running if it get killed create another one if that kill create another right with the help of replica But when it comes to job, what is the uh what is the what is the thing that job is supposed to do? Basically, job is optimized for completion. It will just check whether it got finished or not. Once it is finished, it will stop after the success. But when it comes to pod, it will again create a pod and that's where job is needed. Right? So now what exactly is a Kubernetes job? So a Kubernetes job represents a task that is meant to run an application. Right? So if I put it into simpler word, the job doesn't run your code directly. It creates a pod and that pod runs your container. Right? The job's real responsibility is to track that the pod uh whether it got succeeded or not. Right? It it basically if it didn't get succeeded then does it need to be retired or not. Right? So once the job 9:08:42 has the number of successful completions it need by default. uh for example it is just one it marks itself as completed and then it stops creating a new pod that's basically what exactly is a job right so if you just go through this diagram it will give you a complete idea what I'm referring to so here notice that there is a layering because here it matters a lot for troubleshooting right the job is the controller over here right and what exactly it controls It controls the pod, right? It holds the policy, how many uh successes are needed, how many retries are allowed. The pod is where the actual works happen, right? The container runs over here, the command runs over here, the exit code is displayed over here. And this is the exact same layer pattern which you already know in deployments and replica set, right? Kubernetes almost always separate the policies from 9:09:44 the execution. So basically Kubernetes will separate your controller from the pods and that's the reason we have this sort of hierarchy. So now here if you see there is a layering present over here. This layering I have specifically added for understanding the YAML file that we would be creating. So the job object does not contain a container right it contains a pod and basically when I say this spec basically it contains a pod template right. Kubernetes uses that template to stamp out the pods whenever they need a newer one and that's the reason we have created this hierarchy. Okay, if you didn't understood from this visual, don't worry. Let us do a hands-on because that will give you a complete idea what I'm referring to. So what I will do, I'll just close this terminal and let me clear the screen. Okay. Now let us create a job. This will be our first job. So I will just write vim job.l ML enter. Now again whenever you 9:10:44 are dealing with any sort of manifest file around the world across the group in Kubernetes what are the four components that you would be focusing on? Again API version kind metadata and spec. So I'll write API version kind. Now what we are trying to create it's nothing but job metadata and spec. Now again I will tell everything from scratch. Let me just do escape colq. And here what exactly we are trying to do? We are trying to create a job. But what is the API version for that job? Where will I get to know? Again go to chat GPT go to Google Gemini or go to Kubernetes documentation. But again the same thing you can refer in your own terminal itself. Right? Then why you are switching the tabs? Just o open your terminal and just write cubectl api- resources resources and run a grap on job that's it work 9:11:46 done now here we have chrome job and job both are into the API version as batch/v1 now as I mentioned earlier deployments replica set this falls under app/v1 now when it comes to jobs and chron jobs this follows a batch process saying that's the reason it's into b / v1 right so now let me just update the manifest file and here in the API version I'll mention b / v1 now metadata right again what would be the name of this job so here I will write hello job and now come the specs now inside spec if you go to this documentation what exactly do we have we have a template all right and what exactly this template is for this template is for nothing but our pod right so I'll write template over And here let me define the metadata. Meta data. And in the meta data I will define the labels. And the label would be nothing but hello 9:12:46 job. And this is basically your first job. So no need to worry like there is I I'm I'll make sure that there are very less complexities and that's the reason I'm using very basic uh manifest file because see I have seen multiple people teaching out Kubernetes out there. They tell you the concept they'll copy the manifest file from Kubernetes but no one will exactly tell you line by line what exactly this thing means. And that's the reason I want to make sure that uh through this method I'm able to explain you things in a very crystal clear manner so that you are able to understand each and every line of the manifest file. So you don't have to worry here and there. Right? So on that note let's get started. So here when it comes to spec here we need to define the restart policy. Not what exactly is restart policy we'll cover later but for now just focus on creating the manifest file. So restart policy here I'll write never and then again uh what exactly we need to do we want to run the container. So containers and what would be the name of the 9:13:48 container and here it would be hello and now I will define the image. So image again I will take use of make use of busy box. Now again what is Bybox? BZbox is a lighter version of Linux distribution that helps us in running basic Linux commands. Okay. Command command. Okay. And here I'll just pass the commands that I want to execute. So there is one way which is like passing hyphen. And by passing this hyphen you will be able to run the commands. And there is another method that I will tell you later in this video that will again come handy. Now it just depends upon you which one you prefer. Right now after passing this pipe you can literally type all the commands that you want to run. So I want to first run starting the job. Next what I want to run I want to run an echo that says doing the work. And lastly I want to take a sleep I want to wait for 10 seconds. So sleep for 10 9:14:51 second and again after that I will pass one message for the completion. So echo job is completed. Okay. Escape colon wq. And now I'll go to visual studio code. I'll open the job. ML which we just created. And here I will explain you everything line by line. Right? So the first one API version batch/v1. So this is where the job leaves. Job lives in batch in the API group. So it lives in batch not in apps. That's the reason we have maintained batch/v1 into the API version because they represent batch work rather than doing longunning application work. Right? Second we have job right job. Uh second we have kind and basically what kind denotes what sort of resource you want to create using this specific manifest file. Third comes the metadata right and inside a metadata we have given the name of this job that is 9:15:52 nothing but hello job. So the name of the job is hello job. And now comes the main part that is spec. So inside spec you have template right. This is the port template we just talked about. Notice here there is another spec which is present right and it is nested inside it. So basically that is the inner spec that belongs to the pod. it is not for the job and that's the reason I have created this diagram so that now it will make sense to you right this spec is basically nested inside this template so it denotes that it is the specification for the pod not the job okay so coming back now inside spec we have a template and inside this template we have this nested specification right and inside this specification we have this specification that belongs to the pod, right? Then we have container. So what exactly containers tells? Basically it it contains three echo commands. Name of the container and also the image that it 9:16:53 would be utilizing. Now again what are the three commands that we are going to use? First is the echo for starting the job. Second echo for doing the work. Third echo for displaying that the work is completed. Right? And this is something that we are going to use. And then we added a uh we added a 10-second sleep. So that we will wait for some time and then we are going to print the finished status job. Right? And here there is one line that matters uh matters the most that is restart policy where we mention as never. So uh when it comes to job pod restart policy must be either never or on failure. So I'll just write another value for it but it will be in comment right. So on failure, right? So this can never be always because always is exactly uh the restart for forever behavior which we just proved just couple of minutes ago with the help of deployments. When you are using never so that if the container 9:17:53 fails, the job controller decides whether a brand new pod should be created or not, right? Rather than cube deciding it and restarting the pod again in that same place. That's the reason we are making use of never. Right? So now let us see things in action. Let us apply our first job that we have created. So clearing the screen. Now applying the manifest file. So cubectl apply - f job.l enter. And here it sees job is created. Now when I run cubectl get jobs. Okay, here you can see completion 01. Okay, it says 8 second. Let me run it once again. Now it says completion 1 / 1. What exactly this denotes? So that 1/1 is the number to watch. One successful completion out of one required. Now let's go and see what 9:18:54 exactly pods is doing. Right? So cubectl get pods. Enter. Okay. Now see here we have 0/1. So do not misread it because for a running pod 01 usually means uh something is broken. But when it comes to jobs pod 0/1 completed means zero containers are currently running because the container finished successfully and exited. Right? Completed is a healthy expected end state of a job pod. It is not the same signal as 0/1 that we get on deployment pod that is uh that supposed to be which is supposed to be running right now what we are going to do is now since we have implemented the echo command let us see what the job port actually did. So for that we will need to see the logs of the job. How would we look that? So cubectl 9:19:56 logs followed by uh the job and the name of the job is hello job. Okay, let me just add a slash and here you can see it printed a output. So the work ran the container exited cleanly and the job recorded a successful completion message. And this is something that we actually wanted to see. Right now let us go back into the screen and here uh I have already added the manifest file that you can actually go through. Here I have also added the field and their purpose so that you will have the complete idea what exactly we are referring to. Now let us talk about the job life cycle and the troubleshooting order. Right? So let's put a name on to every stage of what we just uh saw and what we just watched over here. Right. So if you have remember uh exit code 0 what exactly exit code 0 is and I am 9:20:57 referring to this one. Right? So exit code 0 is the universal Linux signal for success. Right? And it just says that the job got completed the task got completed right and Kubernetes basically since it is Linux native Kubernetes respect the same convention. So any non-zero exit code is treated as a failed execution which we are about to trigger on purpose right also u let's build uh the troubleshooting habit now while things are healthy so it's automatic later when something is broken right so let me go back to the terminal and now let me just run cube cl describe the job and the name of the job is hello job Enter. Now see here we have all the details right such as the name of the job, the name space where it is created, the selectors, the labels and remember this label where exactly it is coming for it is coming from nothing but the 9:22:00 manifest file that we created. Right? But here we are exactly interested into the event section because this actually tells us what exactly happened. Right? So this is where the job records the completed or the failed at controller level. Right? So now if I go over here there is another command that we are supposed to run and see what exactly output we will get. Right? Don't worry I'll decode everything so that you will get a complete idea what exactly I am referring to. Okay. So that's the pattern. It inspects the job first then it will inspect the pod then the log. So it will let me just repeat my statement. It will inspect the job first right and the job name is hello job then it will inspect the pod cube cuttle get logs and then it will show us the log and here we are describing the pod that's what happened. So for a job specifically uh 9:23:01 so for job specifically don't stop at part status jobs owns completion and failure counters will tell you the real story especially when uh retries are involved right now what exactly retries are there we are going to cover in this same video so don't worry on that basically the purpose of telling me this thing was we actually just saw things at pod level and we just saw the description the describe command at job level. Right now comes the fun part. Let's break the job on purpose. And here we have nothing but failure rate back off limit. Now this is something that you might have heard a lot, right? So imagine this uh a container is a database migration and database happens to be down right. So the container exist with the exit with a failure code. uh we don't want Kubernetes to give up early uh give up after one try uh and uh we 9:24:02 also don't want to uh make it hammering like it is a dead dependency forever so that is where backup limit comes into the picture right so if you understood basically we just want cubernetes not to retry every time just apply the things for some time and then just display whether it got failed or not right let me create the manifest file once again it will give you the clarity what I'm talking about so vim failed jobl again what are the building blocks API version metadata and spec okay now as we saw earlier for job what is the API version it is nothing but batch/v1 you don't have to memorize it. Everything is present at your doorstep. Just run cube cuttle API resources grab job. You will find the results. Now here 9:25:03 in the metadata, I will give the name uh for this job. So since we are talking about a failed scenario, I'll just type failed job and specification. Now see this is where the things come right. We are demonstrating backoff limit. So I'll define backoff limit over here. Right? So the number of part failures tolerated before the job is marked as failed that is defined by backoff limit. So in the spec I will define the backoff limit and here I will define it as three. And again now let's follow the same process that we followed earlier. Uh that is nothing but for creating the manifest file for job everything is same exactly at uh exactly like we did earlier. So template under template we will pass one specification and in that specification we'll define the restart policy. So restart policy and we want it as never and again now what we are going to do is we are going to define the container right and 9:26:03 that will fall under over here. to containers and here I will give the name of the container as there is a space required over here. Okay, this is failing container and failing container. I will provide the image. I will use the same image throughout the uh this demonstration that is nothing but busy boxy box col 1.36 enter and I will need to run few commands. So command. So I will run this command like s. And now I will print few echo statements. So like earlier. So echo starting new field task 9:27:03 job then echo again. Something went wrong. 9:27:17 And then I will just exit it with error code one 1 escape colon wq. Okay. Now let me just apply this and I want you to watch closely so that you can see the live changes over here. Okay. So clearing the screen and here I will run cube cl get pods get pods w and now I will just do a little bit of zoom and here I think the earlier job is running so let me just uh delete that so cube ctl delete job followed by the job name was hello job enter and it deleted the job from the default name space here I'll terminate it clear the screen so that we have a clear idea of what exactly we are up to. Before even we do that, let me just run 9:28:19 cubectl get pods w and here it will keep an eye on the pods right and you have to uh keep an eye over here at the bottom and at the top what I will do cubectl apply-f fail jobs.ml now see what exactly is happening at the back end watch closely you'll see multiple pods are getting created one after the And here you can see few of them might get failed right and the job controller is retrying the work because the previous attempt uh was exited with because the previous attempt exited with non-zero character right so now there is one thing that I want to uh I want you to observe over here and that is nothing but the completed number 1 2 and three right so here is where we are going to discuss about back off limit so if I go to failed job. Here you can see we have mentioned three as a backoff limit. 9:29:19 Right? So back off limit is the number of pod failure uh the job will tolerate before giving up entirely and marking itself as failed. Right? If you don't set it uh the default number that will go into backoff limit is nothing but six. But since we explicitly mention that three here is the uh demo that doesn't take forever. Right? That's the reason we mention three over here. And there is one thing that uh is worth keeping uh uh worth keeping in mind that is back off limit isn't u run the container exactly and number of time back to back instantly. Kubernetes applies an increasing delay uh back off between retries specifically. So a genuinely unavailable dependency doesn't get hammered and an endless burst of immediate retries get lose off. Right? If you want to visualize it, you can visualize it in this manner. Right? So 9:30:20 one more thing that is worth saying out loud because it's easy trap in real production system. If your task particularly does its work before failing. Uh so basically is it safe to retry? If a a migration writes half of its data and then crashes, does that uh does running it again will produce the final result or does it create uh will it create a duplicate data? So uh the thing is uh it's not a Kubernetes setting. That's a design question uh for whoever writes the task because Kubernetes will happily retry for your container whether uh the retry is safe for you or not. Let me delete the failed job which we have created. So cube cuttle delete-f followed by the manifest file failed job. Okay. And we have removed the failed job. Now let's talk about completions. Right? How much successful work do you need? That 9:31:22 is something that is defined by completion. So so far uh every job we have built needed exactly one success. uh real batch often uh is bigger than uh maybe five successful runs or 500. That's where completions is for you come into the picture. And there is a so there is again a catch that trips a lot of people. So uh let's say it clearly up front. Completion is not how many pods will be created. It's how much successful work is required. boost number can be different in any attempts fail uh which can be followed along the way. So let us create a completions job. This time we'll do it very much quickly. So what I'll do I'll just copy the failed job file and we'll create a new completions file. So completions dotyl enter okay so again the same thing API version batch v1 kind will be job. I 9:32:24 will change the metadata this time and here I will just mention completion job and here in the specification instead of back of limit I will define completions and I'll keep the same number completions as three then in the template in the specification I have mentioned restart policies never will keep it as it is and here in the container let us rename this to um completion container and here busy box image again the same and we are going to uh let me just change the echo over here. Right here I will just write uh processing the task and then uh sleep for 5 second and then print a success message. So sleep five and tes task completed successfully. Okay. So I think our uh manifest file is ready. Now what I'm going to do is let me terminate this. Clear the screen and 9:33:27 I will just run cube cl get pods w under watch mode. And this time we are not just going to watch the pods. I will just keep an eye on jobs and pod both. Right. Cube cuttle get jobs and pods hyphen w. Okay. cube ctl get jobs, odds in watch mode. Here it says you may only specify a single resource type. Okay, so I think we can only see one resource at a time. So okay, no, no problem. cube cdl get pods w. We'll keep an eye on u the pods and parallelly I'll create one more tab and here we'll keep an eye on the jobs. So cube ctl get jobs - w. So here we are keeping an eye on jobs. Here we are keeping an eye on the ports. Now let me clear the screen at the top and here I 9:34:28 will apply the completion job. Mamel which we just created. So cube ctl apply f completions dot job. ML and here just notice what exactly is happening here. See what we did. We mentioned that completion should be three. So completion three what exactly it will do? It will tell the job controller I need three successful pod completion before you are done. And notice this doesn't mean three pods to be run simult simultaneously by default because uh that's can be set with the help of parallelism right so parallelism is something that helps us in executing the jobs parallelly but here you can see it is doing the work sequentially right so just see what exactly is happening over Here 9:35:26 you can see the job completion says 3x3 right here. Uh like there this is something that I promised earlier. Uh if one of those attempt will fail the job wouldn't stop. It will uh wouldn't stop at three part. it will create the fourth one to make up the failure because the goal is three successful attempts not three attempts right so here basically that's what is exactly happening over here earlier there were zero parts which were running then finally the desired number met success criteria met and then here it says it is completed right and that's the reason uh we are making use of completion so instead of making use instead of just executing the manifest file and waiting for the result we make use of completion that makes that exact count has been made, exact attempts have been made, right? Let me just stop this. So, cube cuttle delete-f and the file name completions dol. Okay. 9:36:26 Now, since we were talking about completions, there was one term that came in between and that is nothing but parallelism, right? So, let us talk about parallelism, right? So, parallelism, what exactly it is? Total work versus concurrent work. That's the exact definition of it is right. So completions tell how much work is needed. Parallelism tell how much should run at once. So now separates uh these two ideas uh which sounds very much similar but the answer is completely different. Right? Completion will answer how much successful work uh I need to do in total. Well parallelism will answer how many of those can run at the same time. Let's build uh one that needs u six total successes but only two at a runtime. Right? So let me go back and here we are going to create another manifest file. I'll use the same one and here I'll just mark it as parallel jobl enter. I'm going to make use of the same 9:37:29 manifest file which we made use of earlier. Just making the small changes. So parallel parallel this will be named as parallel job. Here we want six completions and as uh as a requirement what I want uh it should parallelly parallelly run two jobs right. So parallelly p a r a parallelism it should be two. Okay again the template would be the same. The restart policy will be the same. the name of the container let me just mark it as worker container busy box again same uh and here we'll keep the sleep timing this time with 10 second and here there is one thing that I want to do I will print the host name also host name will be nothing but this yep and worker started here also I'll mention the name, 9:38:29 host name for the host. This should be just host and successfully completed for the host. Okay, this also makes sense, right? And here we have sleep is 10. And now let's get started and let us see what exactly we are dealing with. And here we need to define a pipe. That's the reason we were getting that red mark. Now everything is looking fine and we should be good to apply the parallel job. So clearing the screen and before uh that let me just uh delete this terminal. So yep. So clearing the screen again. So cubectl apply apply f parallel job. Ml it says parallel job is created. And now let me just go back and this is the exact manifest that we have used. I will just run this command cube cuttle get pods in the name uh and I want to list the job 9:39:29 where the job name is parallel job and we are marking it as a watch. Enter. So here what we need to watch we need to watch the pod count carefully. You'll see two pods running at once here. See every these two are running at once. Right? As each finishes, the controller starts a replacement always keeping the most two as active until it is accumulated six in total. And what exactly we are referring to? We want six pod as total to be completed. Right? So if I go back into the uh GitHub repository here, you can see exactly I have written what exactly I'm referring to. One important reality check that Kubernetes controls how many pod run not what work each pod actually does. If pod A and B pod A and B both run identical code they might both process the exact same data unless your application 9:40:30 mention it. So Kubernetes coordination uh coordinates which of the unit of the work each one picks in real system uh the coordination usually comes from the work sequence or uh index of the job right so that can be made with the help of completion mode or index where each port gets its own index. Now what exactly index indexing is nothing but giving a role number to a student right. So and what exactly it is you it can read from an environment variable or similar work distribution mechanism. So that exactly has been happening over here. Kubernetes give you the execution model your application gives the work meaning right let me just stop this process C clearing the screen cube delete f parallel jobl and it is deleted too. Now let us scroll down and here you can see there are two more keywords present over here. Active deadline seconds and TTL seconds after finished. So uh two 9:41:32 seconds worth knowing before we move to chron jobs because this is important because you'll see them in almost every production setup in the job manifest. Right? So let me just tell you what exactly is active deadline seconds. It is a hard ceiling for total runtime. So if I put it into simpler words, so a back of limit controls how many times job retries but what if a single attempt just hangs it doesn't fail. Uh it doesn't succeed or it doesn't run forever. Back off limit won't save you right because nothing technically is failing. That's where active deadline seconds comes into picture. It's a hard ceiling on the job's total runtime including every retry combination. So once the clocks run out, Kubernetes terminate the job and mark it as fail no matter what the back of limit says. So let me just create a deadline job for you uh so that you will get an idea what 9:42:33 exactly we are referring to. So let me do the demonstration for active deadline seconds right. I will make use of visual studio this time. So again uh active deadline seconds. I will copy the same manifest that we are using from starting because uh that's something that we would be using again in the same sense. So here uh this is nothing but completion completion job. Okay. And here in this specification instead of u this thing instead of parallelism and completion we are going to make use of active deadline seconds and let me mark it as 20 and back off limit as five for now. Okay. And under template we are keeping the restart policy as never. And in the containers, let me just rename it to as the stuck task. 9:43:33 The image again busy box 1.36. And here in the echo, let me just change uh task started. Started will take time. dot dot dot dot. And here we want to mark it as 300 for now. This will be sufficient. And the main thing is since you have entered that the problem over here would be you will never see this because the job terminated after 20 seconds, right? Now notice the setup. The container sleeps for 300 seconds. That is nothing but 5 minutes, right? Approximately. So which is pretending to hang but active deadline second is just sent for 20 seconds right. So uh let's apply it in watch it in action you'll get actually what exactly I'm trying to do. So cubectl 9:44:35 apply f the name of the file is active deadline cell seconds. So active deadline seconds. ML cube ctl get pods w for watch. Now see I mentioned uh that it should wait for 5 minutes that is 30 second uh that is 300 seconds. The pod will get terminated on its own well before it could even finish or fail naturally. Why? Because we have mentioned the active deadline seconds just 20 seconds right. So let us wait for some time and see what exactly is happening over here. Right. After 20 seconds we'll get the result. Okay. Now it's already more than 20 seconds. So let us describe the job. Here no activity was done right. So what I will do? I will just run cubectl get jobs. And here we have completion jobs present over here. But here what's 9:45:37 the name of the job that we have created? It's completion job. All right. Cool. So the next thing is let me describe the job. So cube ctl describe job job 9:45:55 completion job. Okay. Now here look add the conditions into the events. My bad. Basically it got successful. Why? Because uh there was a mistake from mine. I did enter the active deadline seconds. Let me just update it. And now it should work fine because this is not something that we were expecting, right? So what I will do cubectl get jobs and cube clmp completion job. And now clearing the screen. Cubectl apply - f uh name of the file is active deadline seconds.ml. And now I will just run cubectl get ports under the watch. Enter. And now let's wait and see what exactly is happening. This is from the earlier one and this is from the current one. Right? It's been 8 seconds. It's running. Right? 9:46:55 And now uh basically you can see it is getting terminated right what exactly is happening the container sleeps for 5 minutes pretending to hang but active deadline second is set to 20. So when we apply it we'll see an error right. So this is exactly happening over here. So let me just close it and let me just describe the um completion job once again. So cubectl describe job completion job enter. And here you can see we are getting q event error right. So here you can see uh the condition failed right. Why? Because of two things. First is we mentioned the uh active deadline second that is nothing but 22nd and that's the reason we are getting this specific error. Right? Basically this is used when we don't want to wait for the pod. So just in case if it getting hang we know what exactly is the issue. So 9:47:56 that's cubernet explicitly telling you why the job died not because the container crashed because the deadline clock ran out. Right? So this matters because back off limit alone cannot protect you from a task that stuck rather than failing out right away. uh if you don't set a deadline a hung container can occupy the cluster resources and that is something that is very precious. Active deadline seconds is your safety net uh that exactly tell uh the failure mode. uh nightly report for example this would absolutely must not still be running but it should be once per the business hour start right so that's exactly what I wanted to demonstrate let me just remove it so cubectl delete-f active deadline seconds right so if I go back to the repository here it terminates the job as failed if it's still active and if pass the limit regardless of back off limit it's kind of supporting mechanism Now let's talk 9:48:58 about TTL seconds after finished which is used for automatic cleanup after the uh after the completion. So basically what exactly it is uh let's solve a different a much quieter problem. Every job that we have created so far in this video that is hello world fail job completion that is still a job uh right there right. So I think we have cleaned everything cubectl get jobs right. So right now nothing is present right. So the thing is we manually deleted the jobs right the finished job don't claim themsel by default they just sit there forever uh even though they are done with the task that they are supposed to do uh and they will never do anything else once uh in a cubernetes cluster uh just imagine there are dozens of jobs are running and inside that job uh and inside that cluster running cube cuttle get job and deleting them and 9:50:00 spotting them would be a harder thing. TTL seconds after finish fixes uh by telling Kubernetes once the job is finished success or it get failure doesn't matter uh wait this many seconds and then delete the job and the pod automatically. So that's the main use of TTL right. So if you see it just like garbage cleaner for Kubernetes manifest file. So let us create one. I'll just copy the same manifest file this time and I'll make use of TTL - jobl enter and here I'll change the metadata so ttl - job and here instead of back off limit and active deadline seconds I'll remove it here I will mention TTL seconds after finished and here let me mention it as 30 seconds right so again the templates will be the same and here instead of 5 minutes I'll just keep it as 5 seconds And here I will mention uh quick run. So quick run 9:51:03 quick run. And here the last message would be completed. Okay. Now let us do the same. Let me just apply the file. So cube cuttle apply -f dtl job. ML cubectl get jobs - W enter now keep an eye on it right so once it is done the job it will wait for some time it will meet the success criteria and it will get completed the task itself finishes uh about 5 seconds you'll see a flip that is one by one uh it completed almost immediately now uh just wait don't touch anything and just see on the screen So 30 second after the job is completed like after it is completed 30 seconds what we did we want it we want to job to disappear from the 9:52:04 list entirely on its own right so here it says completed again okay now once it is done we will run cube cuttle jobs and we will run cube cuttle get pods we'll see nothing should be there right we didn't even executed cube cutle delete command because that is something uh tl seconds after finish is actually doing. Right? So, uh this can this you can run without a crown without a chrome script of your own uh because this is something that will help you to clean up your cluster. Right? So, if I go back over here, TTLC automatically clean up and finishes the job and it doesn't pile up. It helps us in clearing the resources in your cluster. Let me just run Ctrl C and here I will run cubectl get jobs enter. No resources found in the name space. And now when I run cube cuttle get pods you can see no resource founds in the default name space. That's the basic thing that we learned today. Let us do a quick comparison. Right? So active 9:53:06 deadline seconds acts while the job is still running. It's running in a safety limit. If you mention the job will run for 5 minutes and if you mention the active deadline second as 20 it will delete the parts after 20 seconds. Then second is TTL seconds after finished. Basically what exactly it is used for? It acts after the job is completed. It's a kind of cleanup timer. So one protects you from the task that won't stop and the other tracks you from protects your cluster from finished task that never got a chance to clean up. Right? I hope this made sense. Now let us do a comparison between jobs deployments and the demon set. So let's connect the whole uh thing that we have learned so far. This is genuinely how I recommend thinking through uh it in a real design and decision workflow not for just this video. Right? So basically when we want to run an API continuously what exactly we will use? We will make use of deployment. Now when you want to run a 9:54:08 logging monitoring agent this is something that we run at the back end make use of demon set. Now if you want to run a database migration once once basically just make use of job. If you want to run a backup every night here the keyword is every night make use of chron job. Now if you want to process 10,000 independent work items and you need 10,000 successes make use of job along with two parameters that we run that is completions and parallelism right I hope that makes sense you are not memorizing unreal resources you are matching your controller to a life cycle ask does this need to stay alive does this need to you know exist every on every node does it need to finish the successful does it need to finish successfully once or does it need to finish successfully on a repeated schedule the answer uh picks up and that is how you will get the answer for which one which resource type should I select right now that was a finisher line for 9:55:10 job now let's start with chron job so now what exactly is a chron job now for the uh second half we are going to discuss about chron job so chron job is not just a job it's a job with a timer right conceptually it's separate it a separate controller whose entire job is to create job objects on a schedule right if you want to imagine basically this is the chain that you can visualize what exactly is a chrome basically chron comes from Linux foundation Linux uh environment if you want to run a specific task a specific job into a schedule you make use of chron job right we are first we are also going to learn what exactly is a chron job how do we write it everything is covered in this video. So don't worry on that if you don't know what exactly is a chron that is also we are going to cover today. Right? So think of chron job as a calendar the job uh as the assignment it hands out and the pod as the person who actually does that work. This layer is exactly uh why chron jobs are easy to troubleshoot once you know the 9:56:11 hierarchy. If uh if schedule runs aren't happening at all uh look at the chron job. If the job exists but keep failing look at the job. If the job has failing pod then look at the pod any logs always work down the chain. Don't start by random uh entiting into the YAML manifest file. Right? So let's build one of the uh chron job. Perfect for the demo. Uh since nobody wants to wait until 2 a.m. to see if that works or not. Right? So here let me just go to terminal clear the screen and I will create a chrome job. So chron jobl don't worry if things are new for you I will make sure that things are making sense for you so let's first write the manifest file for it so API version what are the building blocks API version kind metadata and spec okay now how do I know what's the API version for chron job so cubectl API resources 9:57:13 grab on chron job. Enter. It's nothing but batch/v1. Okay, I'll go back again to the chrome job and here I'll update the API version to nothing but b / v1. Now what is the resource type we are going to create? We are going to create we are going to make use of chrome job. Okay, chron job is done. Now let me define the metadata. So name hello chron and in this specification let me write the chrome at what schedule we need to run. to schedule CD schedule and here you need to define the schedule at what schedule you want to run. So basically you can make use of this chronab website. It's a really very good uh handy website that you can make use of. Let me clear everything. Okay. So here see this is something that we call as a crown. Okay. 1 2 3 4. What exactly it says? 9:58:14 run at every minute right that is exactly what we want if you don't know how to read it I will tell you in the same video so don't worry on it let me just first finish the let me first creating the manifest file so here I'll update the schedule and then I will define the job template now so job template the job that needs to be finished so for that we need a template that we need to do and this this specification for that job template and here I will pass the template and under the template we need to pass the specification. So spec restart policy as never 9:58:59 and here let me define the container. So containers the name of the container is nothing but hello hello chron and I will define the image and image we are again making use of busy boxy box 1.36 okay and here I want to fire the command so command H see and here I want to run few you know the echo commands so echo one second I think there is this yep okay and here I want to run few echo commands so that is something that I would be listing over here so echo chron job started 10:00:00 And here I will uh print the timestamp into date and time format so that we know what where exactly it started. And then echo running and then I will wait for 10 seconds. So sleep for 10 seconds and then I will finish I will print the success message task completed. add the mention time. So, dollar date escape colon wq. Right. So, if I go back and let me open this chron job file. So, here it goes. Okay. So, notice that the structure is uh one level deeper than a plain job. A chron job doesn't have a template directly under the specification. It has something called job template. That is something that we notice because that's uh what it's creating. It is not creating a pod. It 10:01:03 is creating a job. Then the job has its own template which is responsible for creating the pod. Right? This is something that I'm pointing to. Right? So here this highlighted box is nothing but the template of the pod which we are already familiar with. If I go back to my documentation over here, here you can see the exact uh format of chron job. Inside chron job, you will have a job template. That job template will contain the pot template and that pot template will run the container and the pod inside your this thing. Right? So now let us apply the changes and see things in action. So cube ctl apply -f chron job. Mml and now cube. Okay, we are getting an error. So what it says error bad request error while creating chron job chron job in version v1 cannot be handled as chron job strict decoding error. Okay, so again we have a yaml issue unknown field spec dot job template dotspec. template spec. Restart 10:02:06 policy. Okay, so there is an indentation issue that uh we are facing. So let me just check what exactly the issue is with. So spec dot job template. So spec dot job template. Okay. And here in this spec dot job template we again have one spec that we have passed. And inside that spec again there is a template passed. Okay. So here it says spec template spec restart policy. Okay I got the issue and here the issue is with restart policy. The thing is we need to make this as uppercase. Now things will be good. Let me clear the screen and I will apply cubectl file again and again we did a live troubleshooting right now right away we don't even have open uh giant gbdmini nothing needed first do the initial level of troubleshooting the root troubleshooting from your end by understanding the logs right and then apply the changes right now let me just see the result so cubectl get chron job 10:03:07 enter and here you can see there is a schedule present over here so this single command is the best demo uh in this entire whole video because you can watch the entire chain appear live. The chron job shows a last schedule, right? And uh the chron job shows a last schedule time. uh job appears with a generated name based on the chron job and the schedule time and that's job uh and that's the jobs pod which shows up to the pillow and give a couple minute uh so that and after that we are again going to run the same command. we'll see the second job appear because the uh because the schedule fired again right so let us wait for some time and then we'll get to know what exactly things are present over here and then we are going to learn about the uh syntax of cord like how we can u learn about chron how to design this schedule on what basis uh we are writing those values those those are something that we are 10:04:07 going to understand now right so let us wait let me just run the u cube cuttle Chron jobs pod and jobs again after 1 minute. So yes, let's wait for some time. 10:04:27 Okay, now let me just run cube cut chron job again. And now let me run cube cuttle get jobs. cube cuts. Okay. And here it says everything is completed after 1 minute. Let us try and fire this once again. 10:05:08 And here you can see the third part is running. And that is the actual beauty of chron job. If you remember we mentioned uh that it will wait for 1 minute and it will create a new job again and again. And that's what exactly has been happening. If I run cube cuttle get jobs here you can see another job is present right and if I go to chron jobs okay here it says again it is here you can see again the output present over here. Right. Let me clear the screen and here what I'll do I'll just delete the chrome which is present over here. So cubectl delete f chron job. Mml clearing the screen. Now I mentioned that we would be discussing about the chron syntax. So let me go back and here is the syntax that I was referring to. So let's decode the scheduling screen uh scheduling string itself because getting it wrong in production means your backup runs at the wrong time and it doesn't uh run at all or it doesn't run at all. 10:06:08 Right? So let's read it uh let's focus on this table right let's read few of the example together instead of memorizing the table. See there are five stars in total 1 2 3 4 5. Now here the last star defines the day of week. It can be Sunday, Monday. So it starts from 1 to 7. Okay. And here it's from 0 to 6. My bad. And secondly is the month. Month again January till December. Then here we have the day of month, right? Day of month basically till what date? Till date 1 till 31st. Then R in minute we have 23 24 hours in total. But here we are starting the uh designated from 0 to 23. Then minute from 0 to 59. That is something that we have mentioned over here. So the goal is to isn't to have hundreds of this memorized. It's just to understand five position well enough to read any sequence and confirm the matches that actually matches the business requirement before we can deploy it. And one more thing that uh 10:07:10 catches people up that is the time zone. So if the requirement is 2:00 a.m. in India that is IST time zone don't assume that the cluster default time zone matches the same. Modern Kubernetes explicit have a explicit field for this and uh that is nothing but spec equals to time zone and here you can mention the time zone also. So setting this explicitly makes the business element uh uh visible to everyone. So instead of silently depending on whatever time zone the controller manager uh happens to running it. Uh we will make use of this thing right again you can again make use of chron tab guru here. Just click on random. it will generate random values for you. So what exactly is the meaning? So let me just break it once again. This star starts for the week day right. So again as I mentioned 0 to 6 again here it says star. So second one starts for the month again here it will run for 10:08:10 every month and again for which month basically day one for each month that's the reason we have mentioned one over here. So on every first uh first date of every month it will run the schedule. Then here we have 14. So at R14. So at 14 meaning uh if you convert this into uh 12hour format this will be at 2. At 215 it will run at 1 for every month right and that is something that is mentioning. And next it will sc it will run on this specific date at this specific time. That's the main use of of this thing. Play around this tool. Click on random. It will generate multiple values. That will give you a complete idea what exactly we are dealing with. And again follow the documentation mentioned over here. That will give you a complete idea. So the goal is again not to have 100 of this thing to memorize. Just make sure that this concept exist. Clear it and then play with chrome tab. That will give you a complete idea. So that was all where we 10:09:11 wanted to discuss about chron right. So now let us now talk about concurrent policy right. So what happens when uh any sort of uh run overlap. So here is a scenario that comes up constantly in production that your backup takes 90 minutes but it is scheduled to run every hour. the next schedule uh when the time arrives uh before the previous run was ever finished um what will happen to Kubernetes what it will do right so this is exactly what concurrent policy controls so if I if you can see on this table basically we have three values allow forbid and replace so what exactly allowed does it let uh basically it uh let the job start anyway and both run parallelly concurrently and this is a default default setting. Second we have is forbid. So what forbid does it skips the new schedule while running the previous one as the active one. Okay. And the third one is replace. So it will 10:10:13 it will kill the current running job and it will start a new one in its place. So there is no universal correct choice here. It depends completely on your use case and what task you are actually performing. So if each run is fully independent overlap might be totally fine. uh if two backups are hitting at the same database u at once it will be dangerous. So for weight again is the safe option over here and if only the latest run results matters to us then replace makes sense to us right. So on that note let us take an example for creating the forit and I think the same will be done for the remaining two. So I will give you the demonstration for um chronop for bit right. So let me create a file. So vim chron chron job forbid doty yamel enter and again uh I will be using visual studio code so it 10:11:14 would be easier and I will save this file first. Okay. So chron job for bit and I will make use of the previous chrons that we have created and I will modify it accordingly. B / v1 the kind will be chron job. Then metadata here I will change it to uh forbid forbbit crown. Okay. And under this specification we have mentioned the schedule and here in here here basically inside just below schedule you have to define the concurrency policy. So I will just copy concurrency policy over here and here in the concurrency policy basically I want to forbid. So I don't want um things that are currently running that should be present. and it should forbid that and it should allow the remaining one which are present. So it will skip the new schedule uh while the previous one is active. So if existing backup is running it will continue to let it do his work and it will forbid the newer one. Right? So 10:12:14 here let us keep everything as it is at it is saying. So let us leave it for 10 seconds. And now let me just apply the thing. So cubectl apply hyphen f Chron job for bitid.ml and it is created. So cubectl get bots enter. So it says no bs present. cube kl jab get jobs. No resource found. Okay. Cubel cubectl get chron job. Enter. Here a for bit chron is running. Okay. Get jobs nothing is present and get ports nothing is present over here. So the uh schedule fires every minute but the task itself will take 90 seconds. Uh so let us wait and watch what exactly happens in um every minute. So as you can see right now no new job appear because forbit is 10:13:14 actively skipping it while the first one is actively running. Once that job is finished then the next schedule uh the next is scheduled to the next minute to create the new job. So let us wait for some time and let us see what exactly happens. Here you can see one for bitron is done because this activities was running. Now here you can see one job is present. Now let me just run chron jobs once again. And here when I see it says the duration is age is 38 second. Let us wait for another minute and let us see what exactly it does. Okay, now I'll run cube cuttle get jobs. And here you can see another for bitcron is present. So that is something that I wanted to demonstrate today. So let me just delete the current one. So cube cuttle delete f chron chron job forbbit.ml and the resources delete. So now let's scroll down and here you 10:14:16 can see in minute one job A start it ran for 90 seconds then in minute two act job A was still active. So due to concurrency policy it skipped the earlier one and then once job A got finished in the minute third it started the second job. Right now let's talk about history limits and suspend. So these are the two more settings both operational uh both are like um to maintain the operational hygiene for rather than the core behavior. Uh but they matter a lot for a long running cluster. Uh first is uh chron job running every minute for months and it will create enormous amount of finish job objects. Uh if it is lag uh if it is lagged unchecked if uh that's the why history limits exist. So say this basically tells chron job controller keep these three most recent successful job and basically I'm talking about this. So this basically tells the chron job controller to keep the most 10:15:16 recent successful job and the most recent uh and the most uh recent failed job for the inspection and clean everything older than the auto than that automatically. So without this we need to manually delete the old jobs forever or we will write our own cleanup script which uh defeats the point of using Kubernetes. So second uh second thing that we have that is nothing but suspend equals to true. So imagine a maintenance window where you explicitly don't want any new schedule run to start. Right? If you need to stop uh something already which is in progress, you need to delete that specific job directly. So yeah, what suspend does uh suspend basically it does not automatically stop the job that is already running. So when you flip the switch, if you need to stop something that is already in progress, you need to delete that job specifically directly. Right? So that was lot of learning I believe for today. Let us see 10:16:16 few real life uh examples. So let us uh bring everything into one place so that we have everything into uh one hood. So picture that you are running uh uh like imagine that you are running a e-commerce company platform every night at 2 p.m. Right? So there are several things that needs to happen. You need to uh generate previous day sales report. You need to archive old records. You need to clean the temporary files. you need to run a reconciliation job against the payment provider. So every one of these is a strong chron job candidate. Basically you will make use of schedule one time per run and then basically success and failure will matter. So let us take an example of uh a CI pipeline. Okay. So uh and basically what you need to do you need to resize uh 10,000 of product images after a catalog import. Right. So here you can see completions as 10,000 and parallelism 10:17:17 runs at 20. Right? So that's a testbook batch processing job. Uh it's a large total work bounded by concurrency. So you don't have to overwhelm the cluster or downstream the image processing or uh picture a one-time schema migration before a new application version rolls out. That's not continuously running the service. Its task is to uh it need to finish successfully before the next stage of the deployment pipeline proceeds. That's exactly the job pattern. So before shipping anything to the production, you need to check few uh checklist. So these are the things that you need to check. How long will it take? How what will happen if it fails? Is uh retry safe? Uh is that task is addent? Uh can two execution safely overlap? which time zone will it need to execute? How much job history should we retain? What are the CPU memory usage uh task we need? What happens if dependency is unavailable? How we will pause the 10:18:19 scheduling during a maintenance video and how we would be alerted when a schedule task fail. So these are the all the questions that you need to like ask whenever you are dealing with jobs right. So uh almost none of it is a YAML question. Kubernetes give you back of limit completions, parallelism, uh we saw concurrency uh policy, we saw suspend and uh basically these are uh this is used for designing the actual workload work life cycle around this uh primitive things for making an engineering decision for your team which will help you in long run. Right now let us see the common mistakes when it comes to jobs and grown job. So mistake number one is using deployment for one-time activity. So we proved that at the starting of the video itself a deployment will restart a finished container forever. Second is uh forgetting the restart policy. So for a 10:19:19 job it must be never or on failure. If you use always then like it makes no sense. Third is confusing the completion without a port count. So completions is a total number of successful work which be required if it attempts to fail more parts are get created than the completions number. Next we have uh thinking about chron job uh that it runs the pod directly. Well that's that's not the case. Real change is always chron job first then it goes to job then it goes to pods. There is no shortcut. This is the hierarchy that we have to follow. Right. And next is ignoring the concurrency policy when the task can outlast its own scheduling interval. So if your uh task is scheduled for longer run than its own interval. So explicitly des uh it explicitly decide whether uh we need to allow forbid or replace. Right? So these are the three option which we saw and we even did a practical for for bit too. it will run the 10:20:20 existing data migration once it get completed then it it will allow for the next migration to happen. So don't leave it to default by accident. Just make sure the proper uh architecture and engineering decision has been made. Last is unlimited job history. So set successful job history limit and like fail job history limit and TTL seconds after finished as a standalone job. So finish job object don't accumulate indefinitely. This is the cheat sheet that I have shared from my um terminal history which you can just make use of. And if you remember basically this diagram you have the cool mental model for every controller in this video that we have discussed so far. Deployment basically it ask uh is my application running. Demon set is basically ask do I have the required part on every eligible node. jobs basically did my work successfully finished. Chron job basically it ask uh 10:21:21 basically it ask is it the time to create the next job and keep this thing uh the short definitions with you the ones which are mentioned below. Completion total number of successful work required parallelism how much of work runs concurrently back off limit how many failures are tolerated before giving up. So to summarize everything that we have built, we created a basic job and watched it complete. We deliberately failed a job and watched back off limit retry the event uh retry and eventually it gave up and we spin up the total work per concurrent work with completions and parallelism. We made use of both of them. Then we built a chron job and was it uh creating a new job live on the schedule. We control the overlapping issue with the help of concurrency policy and we cleaned up with the history limits and suspend. The mental model is like matching the controller with the workload actual work life cycle uh because uh it's worth far 10:22:22 more than like you know it's worth far more memorizing the YAML. The YAML is easy to look up knowing which controller reaches the actual skill. I hope uh this video helped you all out. There are many concept that we covered today, many uh demonstration which we took. Uh what I'll do as of now I'll just push everything to the GitHub repository. So get add 10:23:00 Okay. So, whatever files we have created, we have been using so far. Everything is now pushed into the G GitHub repository. Feel free to explore all the uh uh repository file. And again, uh I will request you to go through the documentation. This will give you a complete idea what you are actually doing, right? Yeah. At first you won't get things but you have to try once again you will get the things practice it do the hands-on then you will get the things about right so chron and chron jobs and jobs are the two concept that are used in production in literally every company where uh they are using the cloud where they are using cloud native tools so make sure you checking out those things too so yes that was all from my side and I will see you in the next one till then keep learning and thank you very patch. So till now we have learned about the workloads such as replica sets, deployments, we have seen batch processes like jobs and jobs. But let's 10:24:02 say if I give you a condition when I ask you to manage the databases, right? So for you the answer might be simple like you might say that okay we can manage it with the help of deployments right because it just like we have to manage the parts but again when it comes to databases it uh things changes because here the data is stateful right and here is where stateful sets comes into the picture. In this video we are going to do a deep dive on stateful sets. We are going to understand what exactly stateful set is why we should consider it in the very first place. We will also do a comparison between replica sets, deployments, jobs and chron jobs. So that you will have a complete clarity where the state pool sets fits into the Kubernetes right we are also going to see the life cycle the identity the scaling that has been provided by stateful sets right so yes this will be a complete hands-on video that we will going to cover so yes on that note let's get started and let's start with stateful sets all right so on a quick note so whatever things we are going to learn today is documented under sub 10:25:03 directory number 13 that is 13 hyphen stateful sets in Kubernetes Please feel free to check out the documentation and yep on that note let's get started. So here before even we begin with stateful set since it is a very good concept that we should be aware of uh because it will be mostly dealing with the backend database. Uh so before even we start understanding stateful cells. Uh let us establish a concept of stateless application. So imagine that I have a simple web application where the user is requesting the data uh basically from pi. Then the next time any request data it goes to port number B. The third time he requests the request is forwarded to port C. And if pod B is suddenly disappeared then Kubernetes will create another pod. Now the catch over here is the new pod uh doesn't necessarily need to be pod B. The application actually doesn't care. Why? Because these pods are interchangeable and we don't care uh which particular pod uh processes the 10:26:04 request. We are just we just want basically the request to be served and that's the important idea between behind the and stateless workload. Right? Now we know stateless workload. So now what does stateful actually mean? Let us break down this term. Right? So what does state actually mean? So state simply means information or identity that needs to be maintained. Now let's take about let's think about an database. So imagine that I have to create a database called MySQL0 and another one should be MySQL 1. So these aren't necessary uh just two random copies in real database architecture. Different instances can have different uh roles or there can be different relationships. For example, one might be the primary and another might be the participant in their application. And the important point for us over here is the identity of the instance right. So 10:27:05 if mysql one the example which I was just telling you. So let's take the example from here. So if my SQL 1 disappears and cubernetes creates some completely unrelated pod with a random identity that can be very different from recreating um that is expecting from my SQL one identity. So this is where stateful sets comes into the picture. Now I think you might have got the analogy. If not let us take another example. So imagine that you are in a hotel and there are room uh such as room 101, room number 102 and room number 103. Now imagine 102, room number is temporarily unavailable due to some cleaning activities. So if the hotel repairs it, they do not rename the room number 102 as 207. Right? It will remain as 102. The identity of that prroom matters. Right? So a stateful set gives Kubernetes pod a similar sort of identity. So instead of getting some 10:28:07 random names like we used to get in deployments, we get something like MySQL happen 0, MySQL happen one. So that predictability is one of the major difference between deployments and stateful sets. I hope now with this analogy things are clear for you. Now you know what exactly stateful set does but the question is why not just use a deployment right so uh you might say jubam we already know deployments why don't we just create a deployment with three replicas now think of it like designing uh what now think of it like uh for what deployment has been designed to do so basically we have been using deployments because we want that specific replicas to be running and that's the reason we define replica count whenever we are creating the deployment file. So Kubernetes is free to manage those pod as these are interchangeable application instances. Now in what case this can be perfect for? It can be perfect for the APIs. It 10:29:08 can be perfect for front ends. It can be for perfect for stateless microservices. But stateful application often need more than just um like it it is just like give me three parts. They need a stable identity and that is where stateful set come into the picture and Kubernetes gives a stateful set for this sort of workload. Right? So let's actually see what exactly is stateful set and what is the definition. So uh what exactly is a stateful set? A stateful set it a kubernetes workload controller which is designed for application that require stable identity. Here the keyword is stable identity and predictable life cycle behavior. Right? If I put it into simpler words, deployments are deployments manage interchangeable parts and stateful sets manages part whose identity matters. And that's the mental model I want you to remember. Right? So now let us go through the architecture 10:30:09 of stateful set. So here we have the uh stateful set architecture for MySQL. And here we have here Kubernetes will create MySQL0, MySQL 1, MySQL 2. So notice the uh naming convention over here. Naming pattern. This is not random. The pods have ordinal identity. It starts with zero then one and then two. Right? So that is one of the most important thing stateful set gives us. So why does it starts from zero? Right? It can start from one. why it is starting from zero. So, Kubernetes uses a zerobased ordinal numbering system. So, if we have three replicas, it will start from state uh MySQL 0 1 2 and then when you scale it to five, then at that time it will add one more pod over here and that would be named as MySQL - 4 instead of MySQL 4 and 5. So once you understand this naming pattern, stateful set become much easier to visualize. 10:31:10 Okay. So now enough theory let us create um um the state pool set. I'll go to my terminal and before even we do that let me just check the cluster. So cubectl get nodes here I'll just identify that how many nodes I have. But again uh for this specific demonstration we don't need multiple worker nodes uh because stateful set is about pod identity and life cycle. So we can demonstrate the core behavior even on a local cubernetes cluster. Now what exactly I'm using? I'm currently on mini cube. Feel free to do the same on cube adm and kind that is kubernetes in docker. So yes. So let's get started with the same. So before uh creating or state creating a stateful set we need to clear one more kubernetes concept and that is nothing but headless service. So stateful set commonly work together with a headless service. So what exactly is a headless service? Uh don't worry it is 10:32:10 not a very huge topic. The reason uh we are using is simple. We want a stable network identity for our stateful port. So first of all what we are going to do is we are going to create a service. So let me just create a service file over here. So vim service doyamel enter. And again uh whenever you are dealing with Kubernetes there are the four building blocks that you will have to follow and that is nothing but API version kind metadata and spec okay escape wq now uh we are not sure what exactly is the API version for service. So for that what we will make use of yeah we will make use of API resources. So cube cdl API - resources and let me do a grab on services. Enter. 10:33:13 Okay. And here you can see the API version is v1. All right. We'll follow the same. I'll again go back to the manifest file. And here I'll just update the API version to v1. Right. And here let me define the kind. kind is nothing but service. We are trying to create a service. Now let me give the name of that service. The name of the service here would be MySQL. Then here it should be spec for the specification of this service. All right. So here I'll define cluster IP and here the cluster IP should be none. Now what exactly it is? I'll just tell you because uh it it is a headless service. uh normal service gives us a virtual IP. So a headless service doesn't provide a normal virtual cluster IP. Instead, it helps Kubernetes to provide DNS records for the individual part. So that's the reason we have defined the cluster IP as none. Okay. Now let me define the selector. So 10:34:13 selector and here the selector will be based on app and the label that we would be using that we would be targeting is nothing but my SQL. Now let me just define the ports and here my SQL runs on port number 3306. So that is what I'm going to define over here. And the target port. So target port target port would be again 3306 skip wq. I hope this makes sense. Now once the manifest file is ready, let me just apply the cube cuttle file. So cube apply - f service dotl and when I press enter the service is getting created. When I run cube ctl get svc or get service you can see my SQL is present over here. Right now since the service is created it was a very small topic that we wanted to cover. Right now here let's jump 10:35:14 directly to state pool set. So let me just create the file for state pool set. So state full set dot yamel enter. Now again same uh what are the four building blocks uh for any sort of service any sort of workloads that you want to create in kubernetes again it is API version metadata and spec. Now again in order to validate in order to verify what is the API version for stateful set we will make use of API resources. Now again you will you can also do the same with Google you can also follow the cubernetes documentation but uh we want to do the same with command line itself. So cubectl API resources and let me do a grab on stateful set. So I'll just run state over here and here you can see stateful sets is mentioned over here and the API version that has been utilized is nothing but app/v1. I'll go and update the same into the 10:36:16 manifest file. So API version is nothing but app/v1 and here the kind is stateful set. Now metadata what would be the name of the stateful set? So here I'll give the name as my SQL simple as it sounds. Now under the spec what exactly will come? Now now if you remember we have created service earlier right so we need to provide the service name over here. So service name is my SQL. Don't worry I'll explain you each and everything line by line. Right? And here we want to make a replica count as three. So I will define replicas as three. And then here again if you remember in the service itself we have defined the labels. So here I need to define the labels and selectors both. So selector we will be targeting to those pods where uh it matches the label as my SQL app. So match label and here the label name. So the key is 10:37:18 app and value is my SQL. Now here we will need to define and provide the order template. So template here would be for that pod and here let me just give the metadata. So metadata again in the metadata we will need to define the labels. So labels and here I will give the labels. So label will be again apps colon mysql. And now again uh what I will do now since we have done and defined the template. Now I will define the specification for that part. So here inside at the level of metadata I will define the specification and inside the spec I will define the container and let me just provide the name of the container and here the name of the container is nothing but my SQL. Now I will just give the image name 10:38:22 my SQL. You can make use of any image uh like you can make use of MySQL latest MySQL 8.28.3. I'll use the known image that is MySQL 8.0. And now let us define the port. So we will need to define the port on which MySQL runs. So here just below at the level of image I'll define the port. So ports and here I'll define the container port and the target port. So here container port is 3306 because MySQL runs on 3306. And let me define the environment variable. Now why do I need environment variable for MySQL? Basically if you remember whenever you want to run MySQL, you will need to pass to environment PL that is uh that it is expecting from us that is uh the password value, right? And where you can get that detail from. Okay, you will need to just go to Google and search for a docker 10:39:23 MySQL and here they have provided a good documentation where they explicitly mention what are the environment variables that has been expected and here you can see in order to start any MySQL instance uh you need to pass environment variable and the mandate one that you need to pass is nothing but MySQL root password that is something that we would be passing. So again here one more thing that we are covering right now over here is the environment variable. So here in this section I deliberately have chosen MySQL because here we have to deal with environment variable. Now just inside enviable define the name of the environment variable that is my SQL root password and give the value. So value is root password for now. Escape colon wq and we have saved it. So let me just go to Visual Studio Code and I'll open the file which we just created and I'll explain you everything line by line. Okay. So let let's break down this 10:40:24 CML file. So the first line which is mentioned over here is it is API version app/v1. So we have seen this before also deployments uh like before with the deployments and replica set and stateful set also belongs to apps API group. Second we have kind. K kind is stateful set. So what exactly it does it tells Kubernetes that you want to create a stateful set. Third is the metadata. So the name of your stateful set is MySQL and this name becomes important because it forms the base for the pod name. Then here we have the important section that is specification. Specification is nothing but the configuration for the specific kind that is stateful set. So the first configuration value that we have set over here is the service name. Service name here is MySQL. So this is one of the fields you need to pay attention to because we are telling the stateful set which service provider uh which service provides network identity to this pod and we have created a service exactly with the same name that 10:41:26 is MySQL. If I go to the service file here you can see MySQL is the same name that we have referred over here. Right? So I'll again go to stateful sets. All right. Next we have replicas. Now you are already aware of what exactly replicas does. So just like deployment, stateful set can have replicas. But don't uh make the mistake of thinking like stateful set is just deployment with different name. It's just not like that. The important difference is what Kubernetes does with those replicas. So with these three replicas the stateful set will get MySQL 0, MySQL 1, MySQL 2. This is something uh the identity that we were talking about earlier, right? And then what we have, we have the selector. So we would be targeting to those pods where the app is MySQL, right? So this selector tells this stateful set which pod it belongs to. And just like uh we learned with deployments, the selector must match uh with the labels in the pod template. Now 10:42:28 since we are talking about template, here is the template for the pod that we are talking about, right? So this is the this is basically nothing but the pod blueprint and Kubernetes uses this template to create the pod. Right now we are simply running my SQL container for demonstration. And here you can see we have defined the name of the container along with the image. Right? And I'm intentionally keeping this YAML very much simpler because we are not going to uh we are not going deep into persistent stories in this video because that is something a separate topic that I would like to cover in depth in detail later. Right? So now uh what we are going to do is like again here one more thing that we have done is we have provided the port number for MySQL as we are already aware that MySQL runs on port number 3306 along with the environment value that is MySQL root and the value that we have provided. Right. So yes on that note what I want to do is I will just apply this manifest file. So when I do a ls I will just run cube ctl apply - f 10:43:31 statepool sets.ml and here what it says it says there is an error mapping not found for the name myql name space from stateful setsl no matches find under stateful set in version one app/v v1 ensure custom resource definitions are installed first cds see whenever you get some sort of error like this that is ensure CRDs are installed first. The first thing that you will need to check is the API version right and secondly if API version is correct which we already made sure that it is correct. Second thing that we need to verify is nothing but the kind when I do a vim on stateful set. See here it was supposed to be this smaller letter S was supposed to be into uppercase escape colon wq. Let me just apply the file once again. And here we are again getting one more error that is error bad server request error when 10:44:31 creating stateful sets.ml in version v1 cannot be handled as stateful set strict decoding error unknown field spec. selector template. Okay, let us verify the same. Let me open the file once again and this time we'll just check what exactly is the issue. We'll go line by line. Okay. So we have defined app/v1 which is correct. Then we have defined the stateful set metadata correct. Then the service name is also correct. Then replicas is equals to three. Selector we have defined match labels as my SQL. Then we have template. Template. Yeah template is correct. Okay. So here the issue is with the spelling over here. It is metadata not metadata. Escape colon wq. How do I interpreted it? Now see here again it specified where the issue is around spec dot selector.template. If I go back again spec dot selector tempmplate so area the issue was re the issue was just around 10:45:34 this specific keyword right so we just searched the next line and here the issue was with metadata. Now I believe we should be 100% good and when I apply cubectl apply happy we are again getting the issue. Okay let us troubleshoot the same. It says bad request error when creating stateful set uh in version v1 cannot be handled as stateful set strict decoding error. Unknown field spec dot selector dot template. Okay, the issue is again in that specific area. So we need to just check what exactly can be the issue. So here let me just add some spacing so that it would be easier for me to do uh for the readability. So here we have defined the metadata then we had spec and under spec we have selectors where we define the labels and at the at the level of uh uh basically it should be selector this template should be at the level of selector. Yes, I think this is the correct time for me to use visual studio 10:46:35 code because that is where uh it will solve maximum of my problem. So template should be at the level of selector. And here we have metadata, labels and everything. So I'll just pull it to the left hand side just by one space. Okay. Now let me just reapply the file. So cubectl apply f stateful sets.ml. And again see this is how we troubleshoot the things. I didn't went to Google didn't went to charge GBT. The first level of troubleshooting should be from the logs itself. Now how do we read the logs? Basically whenever you're trying to read the log here you itself you you will get one hint what exactly it is trying to say here it says unknown field spec dot selector. Template and the issue was over this side only. If you remember earlier there was a spelling mistake at metadata there was a uh uh spelling mistake basically this was written as in lower case then we fixed it then that issue got resolved and that 10:47:36 is how you uh troubleshoot the manifest file whenever you're facing issue right so yep now since stateful file is created now let's verify the results right so let me just run cube cl get stateful full set. Enter. And here you can see our stateful set had been created. Now let me just verify the port. So cube ctl get pods and see there is an important observation that I want you to uh take a look into. Here you can see the name of the part starts with MySQL 0, MySQL 1, MySQL 2, right? And this is the major uh stateful sect behavior uh that I want you to remember. Uh the pods have predictable names. They have an identity which we can target too. Right now uh what will happen if I uh delete a pod right? So here let me just clear the screen. I'll open one more tab over here and let me just pull 10:48:39 it at the bottom. That would be better. Okay. So cubectl get pods under the watch. Enter. And here you can see there are three pods which are currently running. Right now what I will do I will just delete either one of the pods. So cube ctl delete pod and the name of the pod would be my SQL. Let me just delete something from the bit between that is pod number one. Enter. Now here you can see pod number one got deleted. But again here you can see there is one more good thing happening over here is as soon as pod one got deleted that is my SQL one got deleted. It created another pod but with the same name. Now if you run cube cuttle get pods it is back as it was earlier. Right? And that is something that I wanted to tell you. Right? So let me 10:49:41 just close the above terminal. Okay. And we are back. Let me go back to the documentation into the readme.md file. We have seen the stateful YAML. We have troubleshooted. We found the issue. And again the breakdown is already been provided over here. So please do watch the documentation that will literally help you. And there is a headless service that we created that is again mentioned over here. And what is the significance of cluster id that is also I covered right now. Okay. Now we have created the uh service and like we have validated the output right and we also saw how do we create a stateful set again uh what we did we again deleted the stateful set we related one of the pod and under the watch we saw when my SQL one was deleted another pod with the same name was created over here and that's the beauty of stateful set right now here uh there is one more thing that I wanted to observe is let's say if we want to uh scale till the replicas to 10:50:41 five for this uh stateful set how would things will look like. Again we will need to run a watch over here. So again uh what I'll do I'll just open one more terminal and I'll just pull it downwards. So uh what I will do I will just fire this command and just before that let me just do a zoom cube ctl get ports under the watch command and here when I run cubectl skates uh cubectl scale stateful set uh name of the stateful set is my SQL and replicas to be five. Here you see it will create two more pods but again it will follow the nomenclature that is cardinal uh system that is used to follow that is it starts with zero. Now since we said that we want two more replicas it will create pod number three and pod number four which was not present earlier. Now if I terminate this current terminal and I clear the screen and if I run cubectl get pods you can see we have four pods which are currently present on the screen. MySQL 0 and MySQL 1, MySQL 2, 10:51:46 MySQL 3 and MySQL 4. So if one of the pod crashes, uh, Kubernetes will create one more pod based on the identity. So this doesn't automatically configure the database replication. It does not automatically configure or make my SQL highly available. But Kubernetes is providing this table identity and the life cycle for this stateful system. Right? And that's the reason we should consider uh stateful sets when it comes to backend databases. Right now uh again um if you want to go into deep dive you can just uh run a describe command to check what exactly is present inside the pod. So let me just take example of MySQL one. So cubectl describe pod MySQL 1. Now here you can inspect the pod just like any other part that we have created earlier right. So the difference is in the life cycle that is 10:52:47 it is controlled by stateful set that would be the only difference nothing else right. So uh again the main purpose of uh doing the scale up over here was nothing but uh to validate uh whether stateful set as we were discussing in the theory that it follows a sequence. It gives an identity to that part whether that is followed or not. That is something we validated just right now. Okay. So let me just go back and here we just scale it to five. Now there is there might be one more question is what if I scale down this pod? what will happen? So okay, let me just scale it back to two. So cube cutle scale stateful set my SQL and stateful set replica count should be two. So cubectl get pods. So now before even I execute the command you only tell me based on this uh if you still understood the stateful set concept which I believe you might have understood so far. So what should be the count of uh pod which are currently 10:53:47 present and what would be the nomature? Yes, you are correct. When I press enter, we have two ports currently up and running. That is uh MySQL 0 and MySQL 1. Here you can see MySQL 2 present over here because it will get terminated. Let me just run it once again and let's wait. Let me clear the screen. It will take some time to reflect and then it will also get terminated. 10:54:26 So here there is one more observation that is uh the higher ordinal pods were removed parts. So if I put it into simpler terms the pods with the higher number are deleted first. If you remember first it deleted MySQL - 4. Now currently it is deleting MySQL - 3 and then it will delete MySQL - 2 until we reach the desired replica count that is right. So that is why stateful set comes into handy. Let us wait for some time and here you can see exactly whatever I was talking earlier it actually performed the same right. Let me go back to the definitions. Right? So uh scaling here is not just giving a number. So when you're working with stateful set don't think that uh replicas equals to five random parts and you're thinking like replicas equals to five order identities that is nothing but a mental model. So here stateful set gives a identity right here I have something to 10:55:27 share and if I scroll down here you will find the difference between stateful set and deployment right here you can see the typical use of uh stateful set plus deployment right. So the typical use for deployment is for stateless application whereas stateful set is used for uh stateful application. Here replicas is supported at both the end. stable port names is just given in stateful set not in deployment. And if you want me to verify that, so let me just uh give you an example for the same. Let me just open any of the deployment file that we have been working earlier and let me just take this uh engineix deployment file. Okay. And here I'll just paste it. One second. Engineix deploy. Copy. I'll just move it over here so that we are just uh providing you the entire bun so that it would be easier whenever you're doing the hands-on. So what I will do here you can see the replica count is five right. So when I do 10:56:27 cubectl apply - f engineext deploy. ML when I do cubectl get pods here we are getting some random names and here it is the combination of nothing but the deployments plus uh replica set right and that's the reason it is not giving us the uh stable pod names and that's the reason I have written over here then predictable identity identity that is again like if I delete either one of the pods the next pod that will get spin up we are also not sure what would be the end hash present over here. But whereas whenever we are dealing with stateful set, we know then if I uh do a scale up then what would be the next name of this specific part that would be nothing but my SQL 2, right? Then order of basically order life cycle. So basically here uh we are talking about the order of creation and order of termination. So here uh it's not a core behavior in 10:57:27 deployment but yeah here whenever we it comes to deletion of the pod uh the deletion will be done from higher to lower and when it comes to creation it will be again from it will again start from zero to the incremental number. Then when it comes to stable pod network identity it is not a per pod by default in deployments but here uh it is supported with headless services. And if you want to know where exactly we should use deployment. So basically we can make use of deployments in APIs in frontend application in web application. And when it comes to stateful set basically it is mostly used for clustered stateful set systems such as databases right and again don't interpret this table as deployment is for everything except data database. That's too simplistic. Uh the real question is does my workload need stable identity and stateful life cycle behavior. If yes then stateful set is 10:58:27 your correct answer and that can be the approach that you can follow. There is one more thing if you see over here if I scroll down uh what are the benefits of stateful set. So basically uh stateful set does not solve everything right. Basically it does not uh automatically create a production ready database cluster. Stateful set does not automatically provide with the database replication with leader election automatic database failure backup disaster recovery. These things are not provided by state stateful set. So what exactly stateful does stateful sets provide Kubernetes level workload identity. The database software is responsible for database specific behavior. Right now let's move for storage. Storage basically is a separate topic that we would be covering earlier. Uh you might be noticing that we deliberately haven't configured persistent storage today. Uh because that is intentional. Uh stateful set and persistent storage are related concept 10:59:28 but they are not the same thing. Stateful set provides stable identity and persistent storage is a separate Kubernetes topic. So in a production database deployment, you absolutely need to think about data durability uh the backups, the recovery and the storage. But uh since uh I want to make it simpler, I don't want to mix all those concept into one single video. We'll keep that focus on some another day. Right now today the current focus was on stateful self itself. Let's talk about pod management policy. So uh now let's introduce one optional advanced concept uh that is u there is one interesting thing in stateful set setting that I want you to know about uh so by default stateful set use ordered pod collection creation behavior but kubernetes also provide the pod management policy. So here uh the default we uh default behavior the default value for the pod management policy is ordered already. 11:00:29 But again here we have another option that is parallel. So what exactly is ordered ready? Ordered ready basically means uh Kubernetes will follow the order behavior that we have been observing. Now what exactly is uh pod management policy when it comes to parallel. So parallel text tells Kubernetes that the pod can be created or terminated without waiting for the previous pod to become ready. So where it can be useful? This is useful when you create uh this is uh helpful when your application doesn't require uh strict uh startup order. So on that node you can make use of this specific policies. Now now uh let me just inspect the current stateful set because that will something uh that is something that will help you to understand what exactly I'm talking about. So what I will do I will just clear the screen and I will run cube cuttle describe stateful set my SQL right and here if I scroll at the top 11:01:30 here see the replicas that we were dealing with is two right and here we have the port template where we have defined the label as my SQL the container configuration that is nothing but mysql 8.0 zero the port and the hood. So whose code is mentioned again the environment variables that we mentioned is also present over here right here here in the environment sorry here in the events you can see all the events that's been done into the specific uh stateful set. So this is a great command when you are learning Kubernetes. So instead of get guessing what Kubernetes stored uh you can directly ask Kubernetes what exactly has been happening. Now let us go back to the documentation and here uh there are a few troubleshooting guides that you should be aware of and these are already the things that we have covered in today's video. So yep these are the troubleshooting steps. So if uh you face any sort of issue feel free to use either of the commands which we already used of and now you have the complete knowledge about it. So let us discuss about few common mistakes that we 11:02:31 usually do. So the first mistake that has been seen is thinking stateful set is simply a deployment with ordered number of ports. So uh the answer is uh it provides the stable identity and ordered life cycle that are the important concept over here. Second mistake that we do is thinking stateful set automatically provides database replication. It does not. Third uh thinking stateful set automatically provides the backup. It does not help you with the backup. Fourth is forgetting the headless services. So basically if you need a stable DNS identity for individual stateful set pod, the headless service is the an important part for the design. Right? So that's the reason I covered that specific topic today. Now fifth mistake is using stateful set for every application. So don't use stateful set simply because it sounds more advanced. If your application is stateless, deployment is usually the simpler option and more 11:03:33 appropriate workload. So that's the thing. Now let's look at the types of application where stateful set can make sense. For example, here uh if you see a production architecture, uh stateful set can be good in MySQL, postcale SQL and MongoDB. And basically it can be good in distributed systems such as zookeeper, kafka and elastic search you necessary don't have to manually create the stateful set every for every database. Uh many database platform provide kubernetes operators. So operators basically understand the database itself. They can automate things like your replication, your upgrades, your backups. This things is already been provided by few database provider. So here stateful set is an important concept for primitive uh databases but it is not for entire database management system right so that's that's the thing that we need to keep in mind now let's uh see one more thing that is 11:04:33 state pool sets uh versus other workload so when it comes to deployment what deployments is keep n number of interchangeable pods running when it comes to demon set what demon set does it should be running a eligible pod on every eligible node whenever a new new node is added into a cluster. Now job basically it's uh it is used to run the task until it gets completed. Chron job basically to run the task on a schedule node. Stateful set basically run pod whose identity and life cycle matter. So that's the basic difference and I think this entire chart covered entire thing that we have learned so far. Now let us cover few interview question. So let's test the understanding. First is what is stateful set? Now again uh this is something that we learned today. A Kubernetes uh workload controller which is designed for application that requires stable identity and predictable life cycle behavior. That is something that you can say. Second is how is stateful set different from deployment. So deployment here generally manages the 11:05:34 interchangeable uh replicas whereas stateful set manages the pod with stable identity in ordered life cycle behavior. Third is why do stateful set pod have names like MySQL zero? Because stateful set assigns table or ordinal identities. It follows an ordinal system. Then fourth here we have what happens when MySQL 1 is deleted. This is something that we have saw recently. So whenever you delete that pod uh stateful set will expect an identity by the name MySQL 1. So when you delete it uh same pod with the same name will get created. Likewise, you can cover all the remaining questions, right? And this is something that will really help you in the learning. If you don't find the uh answers for that, don't worry. You may go to Google, you may go to the documentation because I personally want you to refer all the documentation and that is how you will find your answers. I'm deliberately not adding the answers over here because this is something I want you to craft your by your own self. 11:06:34 Okay? And by the end of the series, I'm planning to provide one questionary because that is something that will really help you in your learning because it's just not just learning things. We will have to think it from interview point of view also. So here is the mental model that we have learned of the things. So deployments basically maintains the pod which are interchangeable. Stateful set here the pods are having with the same uh stable identities. Right? Five things to remember about uh stateful set. First is it provides stable identity. Second is predictable naming. Third is ordered life cycle. Fourth is stable network identity. And here the last conclusion over here is stateful set is not a complete solution for databases. Right? So stateful set provide Kubernetes uh workload prim stateful set provide Kubernetes workload primitives uh database replication failure backups disaster uh recovery. These are separate concerns which is actually managed by the database management system. Now here again is the 11:07:36 cheat sheet for the commands that we have ran so far. And here you can take the final takeabase. So as we started today's video uh with a simple question why we can't treat database exactly like we do and treat normal web application. Now we have the answer. So with stateless application individual parts are generally uh you know interchangeable. uh so if one of them disappears another takes his place and the application doesn't care about the identity of the pod but when it comes to state stateful application they care about who I am uh what is my identity what is the predictable network address when I should start when I should stop and that's where stateful set comes into the picture so we literally saw the hands on where we deleted the pod where we created the pod and we saw how does the nomature matters in stateful set. So again don't memorize stateful set equals to database. Instead remember stateful set is for workloads where pod identity 11:08:37 and predictable life cycle behavior matters. That's the main concept. So once you understand that so YAML will become very much easier whatever I have shared and again on that note let me just p push it so that whenever you're working around you will have some hands-on. So get add dot. 11:09:03 Okay. And here I have pushed the files into the main branch. And I believe now you should be good. You will have everything all the resource material. So yes, I think that was all in this video. Uh I will see you in the next one. Till then keep learning and thank you very much. And don't forget to check this documentation. This will really help you out. And if you feel like something needs to be added, please uh feel free to raise a pull request. I'll definitely merge it. Hey everyone, welcome back. So till now we have been learning about deployments, replica sets, but we haven't clearly answered about how does these ports communicate with each other. So going forward we are going to talk about networking in Kubernetes. In this video, this will be just an introductory part for you because here we are going to understand what all terms we would be facing going forward. Right? This will be your baseline where we would be talking about what exactly is networking and what all things we would be dealing when we are working with Kubernetes. Right? So, grab your pen, grab your 11:10:04 notebook and get start with this networking video. In this video we are going to understand after the workloads are created how will they communicate with each other and if me as an user want to access those workload how these things are been accessible to me and that is the main reason we have introduced cubernetes networking right so going forward and the coming videos will be dedicated to cubernetes networking and I believe this video will definitely help you in clearing your basics right also do not expect that you will understand completely because here this will be just an introductory part of the components of Kubernetes networking. So the main reason for creating this video is just to give you an overview the road map for Kubernetes networking that we would be doing going forward. So yes, that was all. Let's get started with Kubernetes networking because this is the foundation that will help you to understand Kubernetes networking in a very good sense. All right. So before even we start with the networking in Kubernetes there is one thing that I wanted to make clear and 11:11:05 that is nothing but fundamentals of networking because when you are clear on basic networking then networking in Kubernetes will make sense for you and yeah don't expect any heavy terms of networking in this video because we are going to break down each and everything and yes this video will set a foundation for future and coming videos in networking in Kubernetes. So please pay attention and yes feel free to check out this readme.md file which is present in subdirectory uh number 14 networking in kubernetes right so once you are done with this video you can just refer to this readme file as a revision material so that you can get maximum out of this right so before we talk about networking in kubernetes let us first understand what networking actually means so imagine that you are sitting alone in your house and you want to call your friend right so you need something to contact your friend right now. It can be their phone number, right? Just like that on a computer network, we commonly use IP address to identify a device or a network endpoint. Now, what do I mean by 11:12:07 an IP address? So, you might have seen numbers like this 10.244.1.0 or maybe I'll make it easier 1 192.168.1.10. Right? So, you can think of this as IP address. Now what exactly is IP address in human terminology? It's just like your home address, right? If you know your house address, you actually know where do you want to send that parcel to. But again there is another problem and that is nothing but here I want you to focus on this 80. Right? If I know your house address and if I want to send something the problem is like that address can be of an huge apartment where multiple buildings will be there, right? So uh this building has 100 but there are hundreds of apartments inside it right. So knowing only the building address isn't just enough right we also need to know which apartment or which quarter you are living into right and that is where port comes into the 11:13:07 picture and yes here I am talking about this number 80 right a port is like a particular door inside a machine or a network endpoint so here you can see 10.244.1 244.1.10 is nothing but your IP address and col 80 the number 80 is the port. So it is very simple what exactly IP tells us IP tells us that where exactly things are and port and ports tells us which application or which service are present at which location. So this is the first concept I want you to remember and I believe this concept makes sense for you because this is something that will act as a foundation for us. Right? So IP tells us where and port tells us which application or which service at that location. Right? Now let us map the learnings with docker. Right? So here I want to explain you one thing. If you have worked with docker you probably have seen networking. Right? For example, you might run a container 11:14:09 containing engineix. Inside that container, engineix could be listening on port number 80 and another container may need to communicate with it. So what docker actually does? If you remember, we have learned about docker networking. So not docker basically provides a networking mechanism that allows the containers to communicate with each other. So Kubernetes will take this further ahead because Kubernetes isn't just managing one or two containers. It can manage hundreds or maybe thousands of pod across the machine. Right? So Kubernetes needs a networking model which works across the entire cluster and yes that's brings us to the pod right. So we are already aware what exactly is pod but how do pod do the network? how do they perform the network connectivity? So now let's imagine let's say that I create the pod name engine pod. Inside that pod I have an enginex container. Kubernetes will give me uh uh 11:15:11 the IP address for that pod. For example 10.244.1.10 is the IP address of that specific pod. Now imagine I create another pod by the name by the name client pod and I will get another IP address for that specific pod that is nothing but 10.244 244.1.11 right so conceptually we are here right now if you can imagine the client pod can communicate to the engineix pod that sounds really simple at this point you might think great if pods have IP addresses why do we need anything else and that is definitely a very excellent question because that should really come into your mind and that question leads us to one of the most important ideas in Kubernetes networking and what exactly is so the problem here is with pod IP address right so let us understand why pods IP address are not enough so let's say our application has three pods right so here it can be backend one back end two or back end three or maybe we can 11:16:12 consider front end one front end two or front end three right so our back end applications wants to connect with these pods uh we could technically give the back end all the three IP address from the front end but now imagine if uh let's say the pod front end to get crashed. So what exactly Kubernetes will do? Kubernetes will create a replacement pod and that replacement pod will receive some another IP address. Now our back end still have the IP address of the previous pod. But since that pod is deleted, we don't have the back end. We don't have the front end exist, right? But since that pod is deleted, uh we don't have the access to it. And this is the problem. And remember uh what we have learned throughout this Kubernetes series pods are disposable. Let me repeat pods are disposable. Kubernetes can create them, it can delete them, it can replace them, it can reschedule them. So we should not build our applications communication around the assumptions that a pod uh let's say a 11:17:13 pod's particular IP will remain forever. We need something stable. We need that clarification. We need that confidence and that confidence will provide to you by services and this is the exact place where services comes into the picture. Right? So now let's discuss about services. So uh what are services? So a Kubernetes service gives us stable way to access uh the changing set of pods. Right? So let's imagine that we have three backend ports. Backend one, backend two and backend three. Their IP address might change over the time. Now let's say due to the workload it uh we got a requirement that we should delete that pod. So you have deleted it and now it will get another IP right. So their IP address might change over the time. So instead of our front end application remembering the backend IP address for those backend pods we create something called a backend service. Right now what will happen that front end will talk to the backend service. Right? the service 11:18:15 figure out uh which backend port should receive the traffic and this is one of the biggest uh shift in Kubernetes networking. So instead of saying that I want to talk to a specific port whose IP is 192.168.1.0 we will usually say that I want to talk to the application which is represented by this backend service. Right? So the pods behind that service can change but the service gives us a stable networking endpoint which we are going to cover in services in much more detail in coming videos. But here I want you to complete focus on the services. What are the offerings provided by services at the same end. But again there should be another question that should pop up in your head and that is how does a service know which part does it belongs to? And if you remember ladies and gentlemen, we already have learned about labels and selectors right. So this is where uh the concept that we have learned uh are actually coming into the picture and believe me all the videos right now will be linked because I was trying to create 11:19:16 the base for you and now that base is ready so things will eventually make sense. So yes services makes use of labels and selectors. Now suppose we have the pods and that pod uh that pods use uses the labels as app back end right and our services has the selector called as app back end right Kubernetes will use those selector to identify the pods belonging to the services so it will be something like this if you can visualize this this will be easier so what exactly is happening service is not magically guessing the uh pods which it should belong to it actually makes use of this label that we are utilizing. So it uses labels and selector that we define and that is why labels and selector are such an important foundation in Kubernetes. You have learned them earlier and now you can see why they really matter for networking. Right? So uh there are three different uh addresses that you will be hearing uh 11:20:17 about uh whenever we are dealing with networking. So for now I I want you to ignore this specific section. I will cover the theory and then I will show you the practical at the same time. So yes, these are the three important IP concepts that you will be hearing frequently with me. So uh as we continue through this Kubernetes networking, you are likely going to hear this. Let us first discuss about pod IP. So we have three sort of networking concepts present over here. Pod IP, cluster IP and node IP. These are different things. So let us understand the differences. Okay. So first what we have? We have pod IP, right? So this is the IP address assigned to a pod. For example, we have 10.244.1.10 it is used for pod networking. But again we discussed pods IPs can change and that is where we can head to cluster IP. So what exactly is cluster IP? A service can have stable internal IP address called cluster IP. For example 10.96.0.10. 11:21:18 So the application inside that cluster can use the service through the stable endpoint. And the third that we have is node IP. So a Kubernetes cluster can consist of multiple nodes. A node has its own network identity. For example, 192.168.1.20. Right? So that's the node IP address. So don't mix uh this up. Uh very simple picture of this is node IP. A node consist of multiple parts. So you can have individual pod IP also you will have a node IP and then again a service can also have a cluster IP for the selected ports. So later when we discuss about node port and load balancer these different addresses uh will become much easier to understand. Right? So now let's talk about port versus target port. Now if you are someone who is coming from docker you already know about how do we define the port mapping in docker right. So another thing that you will see in Kubernetes service configuration is nothing but port and 11:22:18 target port and yeah we already have covered what exactly is port. So you already have a complete idea what exactly is port. So when we were launching the uh engineext container at that time we have seen the what exactly we make use of so that exactly is something that we are talking about and here I'm highlighting to this ports container port right. So what does container port mean? Let us discuss the same. So another thing that you will see in Kubernetes configuration is nothing but this ports, right? And there is another thing that is called as target port. So uh this name can be confusing initially but let us take a very simple example. So imagine a service is listening to port number 80 just like this right. We might have something called container port uh col. So this indicates that the port is associated with the container. But remember container put itself does not expose the application outside the cluster. And in order to provide the stable network 11:23:19 access to pod, we make use of something called services. That is something that we are using. And again I made use of another term that is nothing but target port. What exactly is target port? So target port is the port where the application actually is listening on the selected port. So think of service as a receptionist. You call the receptionist at one number. The receptionist will forward you forward your request to the correct department. So if I show you so it will be something like this. The client will call the services. The service will forward it to the exact port to the application. And that is how things work. Right? In real application service port and target port don't have to be the same. For example, you can see over here right? That means if you can see here the target port can also change. So here what exactly is happening? client talk to the service on port number 80 and the and the service sends the traffic to the target port that is on port number 8080 11:24:19 right so we will spend much time on this uh in the service video here we just wanted to tell you about what exactly is this right so I hope now you have a complete clarity on port and target port now let us scroll down and here we will talk about kubernetes DNAs right so let's solve another problem imagine that you have a backend service and it has the cluster IP as 10.96.0.10. So should your front- end application have the IP address of this backend service hardcode? No. So Kubernetes provide DNS-based service discovery. So instead of remembering the IP address, an application can communicate using the service name. For example, here we have created the service called backend service. So instead of remembering the IP as 10.96.0.10 we can conceptually use http/backend service. So kubernetes DNS resolves that service name to the appropriate service address. And this is extremely useful 11:25:20 because application don't need to know the IP address. Uh they just need to know the name. They and they need to so they just need to know the name. And if you remember earlier the analogy that I mentioned, you don't normally remember the exact IP address for every website you visit. You just go to the domain and Kubernetes provide a similar service discovery experience inside that cluster. So you will also hear a qualified name such as backend service.default.sv.cluster.local. So the exact DNx structure and how name resolution works. uh that thing is something that we are going to cover later. So for now just remember that service gives us stable access and DNS application helps us in finding the service by the name. Right? So let us do some hands-on because I want to tell you how things are actually working. Right? So let's jump to the terminal. Let me just uh open my docker. Let me just boot 11:26:23 up everything and then we should be good. So here I'm turning on Docker and here I'll just open my item. Okay. All right. So I hope now things are visible to you and it is eventually making sense. Right. So the main uh reason of giving me the entire theory was not to just bore you because I wanted to give you the foundation because going forward we are going to do a deeper dive on the things and this is where uh this foundation will come handy. So now let's quickly uh do the hands-on. So the first thing that I will do is I will create a very simple engineix pod. So I will just run cubectl run engineext and I will provide an image. So image equals to engineext enter. Okay, I need to first start the cluster. So mini cube start. Okay, it happens sometime. So yeah, the first thing that I will do is I will just create a simple engineix 11:27:25 pod and then we are going to check the pod and we are going to notice the IP address, right? And then eventually what we are what we will do we will create a temporary client where we would be trying to uh reach out to the uh pod that we just created. So basically we would be dealing with two parts one engineext port and there will be a curl port that we would be creating right. So that is something that we are going to plan today. So now our uh our mini cubit started now and now I will run the command cubectl run engineext image equals to enginex. Now here it says it already exists. So let me just clear everything. So cubectl uh get pods and cubectl delete pod. Let me delete everything. So delete pod engineix for now. I will clear everything. So cubectl uh get deployment. Get deploy. Cubectl delete deploy. And I hope right now you have um uh all the hands-on that we have done so far. So 11:28:26 things are eventually making sense for you. I won't be cutting this segment because like see uh that's the reason uh I have started this series because I want to make sure that everything is presented raw to you and yes that's the main purpose right so now let me run cubectl get pods okay spell mistake so get pods enter okay so right now let me just delete these two so cubectl delete pod girl and after that we will delete I think this This is that thing running. So 1 second the color pod is deleted and now we are good to go. Right. So let us create the engineext pod once again. So cubectl run engineext and here we will provide the image again. So - image equals to engineext. Enter. Now here it says pod/genext is created right. Okay. Now let us check the pod. So cubectl get pods oy to get more detail of it. And 11:29:26 here you can see engineix port is running and here we do have one IP address. Now uh notice that Kubernetes shows us an IP address for this part and you may see something similar like this. Okay, maybe the IP address will be different for you. So yes and that is uh completely fine. So now let us create a temporary uh temporary client. So let me run cube ctl run girl. So this is the utility that we would be using. So why exactly curl? So basically we are trying to create two pods where the curl pod will act as a a sender where we would be sending the request and we would be expecting out output from the engine export that we have created earlier. So cubectl run curl - image and the image is curl images/curl and I want to run it into interactive mode that's the reason I will run hyphen 11:30:26 it and then I want to go inside that pod so that's the reason I am making use of sh enter so from inside this pod we can try to reach out to the engineix pod which we just created and the main thing that we would be doing over here is we will have to curl on this specific IP which is present over here. So yeah, things are very easy and here yeah how do you verify whether this command actually executed or not? You can just make sure that this dollar display so that it will give you an idea that the command actually executed and here you will get this output also. So all commands and output from this session will be recorded in container logs including the credentials sensitive information passed to the command prompt. That's it. So we are not interested in that. So we won't be uh thinking more about it. So curl http col/ slash let me copy the IP of the engine pod and yes once you are done uh here we can see networking actually 11:31:26 working. So once we press enter we are seeing something like this and here you can see the default page from engineext is listed over here. Right? If networking is working correctly, we should receive this enginex response. And this demonstrates something very important. Pods can communicate over the cluster network. But now let's think uh about what would happen if I delete the engineext pod. Right? For that, let me exit from this pod. And here I will run cube clenx. Enter. So now engineext pod is deleted. And now if I create another pod, right? Or if a controller recreates it, the pod will receive a different IP. Let me demonstrate that too. So cubectl run engineext along with the image engineext. And here I will run cubectl get pods ovite. And here you can see the IP address that it received is different this time. And if you remember earlier the curl operation that we performed was 11:32:28 on different IP address. Let me just paste that too. One second. I have it copied over here. So yes, so earlier the IP address for engineix pod was 10.244.2.5 but here right now the after recreation of that engineext pod the IP address is changed to 10.244.1.6 right so uh this is the exact problem that services solved because IP address and pods are something which are disposable. So what service does service basically helps us in mitigating this issues. So instead of talking let us create a deployment instead of services and normally we are going to group the application pods right. So let us create and see what exactly uh it will behave when services comes into the picture. So for that uh let me just navigate to my directory. So desktop and here it is in kubernetes. We would be navigating to 11:33:29 folder 14 clearing the screen and now let me create a uh deployment file. So whim deployment dot camel enter. Okay. So what are the four key components whenever you're dealing with uh any sort of manifest file in Kubernetes right so it is nothing but API version API version kind metadata and spec but again where do you get the information from right the first thing that you will have to do is you need to run cube cuttle API resources and I believe right now you have done the hands-on you are very much familiar with API resources So you don't have to refer the documents here and there. Everything will be present on your console too. API resources. Enter. And here we are looking for deployment. So let me just do a graph for deployment. Here we are searching for app/v1. So okay, let me just go back 11:34:31 to deployment and here I will define my deployment file. So API version app/v1. The kind what exactly we are trying to create? We are trying to create a deployment. So deployment. Now what should be the name of this deployment? So the name of the deployment would be nothing but engineix. All right. Done. Understood. Now let's move forward and here we'll define the main segment of deployments that is nothing but replicas. Now who will take care of this replicas? It's nothing but the replica set. Who will make sure that these things have been matching the current and desired state. Now here on what basis we would be targeting the parts. We will define the labels. Right? So here I will define the selectors. So selector and it will select all the pods where the labels are actually matching the below value. So match labels labels and here what are the name of that label? So it would be nothing but app engineext. Enter. And now let us define the template through which it will create the ports for us. So it should be 11:35:32 add uh selectors level. So yes, let me create the template. to template and this template will contain the metadata. So metadata data metadata okay and in that metadata we will define the labels that we have defined earlier in the selector section. So it is nothing but app engineext. So yeah this will fall inside labels and again now we have defined the metadata at the same hierarchy of metadata you will have to define the specification and this specification will be nothing but for the container. So containers and what should be the name of that container. So the name of that container would be nothing but engineext and here we will define the image that it should utilize for creating the container. It is nothing but enginex. You can also define the tag. So engineix colon latest and yes here define the ports. Now I believe you are already aware of ports and target port. So this will eventually make sense for you. And here we are talking about container port. So 11:36:33 container port and the container port it listens on port number 80. Escape colon wq. If you noticed one thing if I go back I'll just run a cat into the deployment file. There is one thing I want you to notice. uh there is one thing I want you to notice that is app engineext that is the label that we are referring to right now let me clear the screen and cubectl get pods let me just clear the existing part so that it won't create any conflict for us so cubectl delete pod engineext okay so this is also done now let us uh imagine that we create a service so for service we are going to create another file so service dot camel enter then again we are going to define the four building blocks API version metadata and spec escape col wq now again we are going to 11:37:33 make use of the API resources so cubectl api- resources and here we are searching for services enter here we are searching for services and if you remember here we are dealing with v_sub_1 version one and this is nothing but the API version for us. What would be the kind for it? It is nothing but services right. So here is the kind here is the API version right and here is the shortcut that short acronym that you can use while uh searching for services. All right. So let me just do a vim back to services and here as per API resources we will define v1. Okay. And what is the kind what is the type of service workload that we are going to create? It is nothing but service. So service then metadata what is the name of the service. So I will define it as engineix service. Now again let's give the specification. The best part of service is you don't have to provide multiple things. You will just have to define and focus on 11:38:33 one thing and that is nothing but selectors and the port that it would be working on. So selector and what would be the value that you would be pro providing? So basically if you remember earlier we were targeting to the app engineix and this is nothing but the labels that we defined in the template of the uh deployments for the pods right and now uh at what port number it runs right that is something that we will need to define. So ports and on what port basically here we need to define ports and target port. So it runs on port number 80 and the target port that we want uh uh and the target port is basically the port where the application listens right. So target port it will be again it escape colon wq here the important part is sorry here the important part is nothing but the selector that is app engineext wq and here uh that selector tells us find the pods with the label app engineext. Now the structure will look 11:39:33 something like uh there will be a service who will be managing the pod one pod two and part three. So just in case if port two disappears the Kubernetes will create port number four. But the service doesn't uh needs us to manually update the backend list. It continues selecting the ports using the label. And that is the power of Kubernetes networking model. Right. So now let me just apply the changes. So cubectl apply -f deployment. Enter. Okay. Deployment is created. Now let me apply the service file to. So cubectl apply f services.ml. And here it says there is an issue. All right, let us see what exactly is the issue. So if I scroll over here, so mapping port does not contain in declared merge key part error calculating patch from open API spec map issue over here does not contain declared merge key port. So here it says map port. Okay. So I got the issue. So here it says there is an issue right and 11:40:33 issue is with this specific section and here I have done one typo. Okay, I'll do a vim on services and this is not port. I need to remove this s from here and it is nothing but port skq. And now let me just apply the service file. Things are good. Clear cube cdl get svc for service and here you can see engineix service IP is also present and enginic service is created up and running. All right. Now let me just list the deployment. So cubectl get deploy and here you can see the deployment is also present. Now let me just list the pods. cubectl get pods enter and here we have all the parts up and running right. So now whenever you are trying to pinging from one part to another it will definitely ping and let's say if you delete either one of the part then you don't have to worry because service is something that will take care of it right. So now let us go back to the 11:41:35 theory and here let us talk further about let me scroll down and here I think we should be good with we we already have covered cluster IP we have the node port load balancer it exposes a service through external load balancing infrastructure where it is supported so don't worry if these terms are new for you because This is exactly the very first time we are learning and basically why we have added this because I want you to be familiar with this term. So the next time whenever we are uh doing the actual interaction the actual hands-on things will eventually make sense for you. Right? So that's the main thing for introducing these terms. Now let us talk about ingress. Right? So we have multiple application and uh for example we have a website called example.com and maybe uh whenever you 11:42:35 are hitting on it it should hit on example.com/api / ai will denote the backend service and the slash that is exampample.com will load the front end page for us but for http and https traffic kubernetes also provides a concept which is nothing but ingress So conceptually if I show you this is the diagram ingress is about HTTP and HTTPS routing to a service. For example, if someone hits to the webpage example.com, it will show the front-end service. But uh if someone uh types and search for example.com/api, it will redirect it to the backend service. So uh an ingress resource by itself does not magically handle the traffic. uh you generally need an ingress controller to implement the routing behavior. So we will cover ingress properly later but for now service gives this stable access to the application and ingress will provide HTTPS and HTTP routing to the service. 11:43:35 Right now we already talked about services ingresses. Now let us uh discuss on network policy. So, so far we have mostly talked about how do I allow applications to communicate but networking has another side which we would be talking about that is nothing but who should not be allowed to communicate because if you are working in a company there are scenarios where we don't want specific people to uh view the service right so imagine we have a front end we have a back end and we have a database right and maybe what we want is we want the front end to connect with the back end and we want the back end to connect with the database but we don't want want direct interaction from front end to database right and that is where network policies comes into the picture. So network policy helps us in defining the rules about the network traffic between the prods and the other network endpoints. So it depends upon on what the cluster networking uh supports. So conceptually 11:44:36 uh it is just like we will define a rule which will allow the front end to connect with back end and it will allow the back end to connect with uh the database but it will deny the direct access from front end to the database. Right? So that is the main use of network policy over here. So if service helps us to answer how do I reach the application network policy will help us in answer who is allowed to communicate. We are again going to see network policy separately. uh we are again going to see network security separately later but here we are just here to understand the concept. Now if you put everything together uh let us create one mental model that uh let's say a user open um xyz.com the user enters uh in our infrastructure and at the HTTP routing layer uh ingress decides that okay if he goes to xyz.com/appi it will redirect it to backend service the service will provide the stable access to the backend ports and the 11:45:36 service will uh select the ports using the labels and the pod will have their own IP address and at the network policy it may control which pods are allowed to communicate. So conceptually the user will talk directly to ingress ingress with the backend service and backend service will connect to the pod and pod will be controlled with the network policy controls right so let's say if out of those pods which are controlled by the service something goes wrong kubernetes will create another pod but we don't care because here we are dealing with services we don't have to worry about the new IP address that has been given right so service continues selecting the appropriate parts based on labels And that's the key idea right now the things that I was explaining that the user is uh connecting with the ingress and services are connecting with the pods and pods are being controlled by the network policy. So just in case if you don't want don't want to allow the things it will be taken care by the network policy itself that we have an application and 11:46:37 yeah I'm taking this example because this will literally make sense. So you have front end, you have back end, you have database. Each component runs in a Kubernetes. Uh we might have a front- end service, we might have a backend service, we might have a database service. If front end doesn't need to know the back end port IP, right? Uh it can communicate with the backend service. The back end can communicate with the database service. So the application architectures will become something like front end pod. Okay, this will connect with the backend service. Backend service, it will connect with the back end pods. back end uh then database service it will connect to the data uh back end ports can communicate with database service and database service can uh interact with the database port. So the application can communicate using a stable service name rather than the individual pod. So this makes things more manage uh more manageable than hard coding the individual pod IP and this is one of the reason why networking is important in Kubernetes. Right? So if here you can 11:47:38 actually see the actual end to- end flow of the service request. So now uh since we have discussed about networking let us talk about what are the issues that we can face whenever we are dealing with uh networking and where it can where it can be confusing right because there are too many terms that we have learned about today a port IP cluster IP node port load balancer DNS ingress and honestly uh when the first time when you are learning things it will be very overwhelming but don't worry instead of them organize the things uh by problem and then it will be easier for you to remember. So let's say problem number one is if a pod need to communicate regularly. So Kubernetes will provide the uh pod networking and let's say problem number two is if the pod uh IP gets changed. So what thing you will use? we will make use of service. And now the third thing is if the application need to find the service basically we will make use of cubernetes 11:48:40 DNS and whenever we are dealing with HTTP and HTTPS routing we are dealing with ingress. So this is how you can club the things and it will be easier for you to understand. Now let's talk about the common mistakes that usually uh we can do that is first is using the pod IP address as the permanent address. So let's say if you delete that part then uh the port can disappear and it can be recreated but the IP will change. That is one of the mistake that we can do. Second is thinking that the container port exposes the application. Right? For example you defined a ports inside the port you define the container port at 80. Right? So here uh the this basically documents that the port associated with the container it does not uh by itself create external reachable service. Third is uh forgetting the service selector. Here we are talking about selector. So you can create service but its selector doesn't match your pod level. So that is something that will be creating the issue because these things 11:49:40 need to be matched and that is only service will know which port which port to target to right. Port is confusing port and target port. So uh remember port is equals to service port and target port is the application port that we are referring to. this will actually make sense. Now mistakes uh next mistake is about treating ingress as a replacement for service. Basically ingress is normally uh used for routing the traffic to services where service is usually taking care of all the networking for the pods where it helps us to locate the pod without triggering without targeting the IP. Right? Next is assuming network policy is automatically enforced. See network policy behavior depends on whether the cluster networking implementation is actually enforced on the policies or not. Yes, that was all in this video. Uh this was just an introduction. You can definitely go with the documentation because we have intentionally gone extremely deep into every concept. Uh this was just an 11:50:42 introductory video. If you didn't got uh in depth, don't worry about it because we are going to cover things in depth later in the coming videos. This was just to give you an idea what all things will be covered in networking right. So then uh once you are getting a this was just to give you a small introduction to the topics that we are going to learn further because this will give you a basic foundation what we are dealing with. So when we are going to do a deep dive on cluster IP note code this is not a new term that you would be hearing. So yes, we will also do hands-on demonstration so that you can actually see the traffic flow instead of just memorizing the definition. So here the goal is not to memorize the networking term. The goal is to understand the request flow. If you understand who is sending the request, where the request is going and how Kubernetes finds the destination and you understand what uh and whether the traffic is allowed or not, then Kubernetes uh networking will become very much easy. So yes, that's our introduction to Kubernetes 11:51:43 networking. If you're completely new to networking, don't worry if uh some of these terms uh still feel unfamiliar. So that exactly what we are going to cover them one by one. So it will eventually make sense. So yes, that was all in this video and I will see you in the next one. Till then keep learning and thank you very much. Hey everyone, welcome back. So in the previous video we literally started our journey with networking in Kubernetes. We saw what exactly networking is. We actually saw what is networking from Kubernetes context and during that specific session we discovered that the IP address in pods are not permanent right. So let's say if I create a new deployment with three replicas so basically three pods will get three IP address right so what if if I delete pod number two or what if pod number two get crashed so basically as per the design of deployment it will create another pod but again the thing is it will get a new IP address. Now imagine that you have an application where you have hardcoded the IP address which actually you should not do by design but let's say if you have 11:52:43 created an application where you have hardcoded the IP address what will happen in that specific case basically your application won't be able to connect to that specific pod why because the pod is no more right and another pod is pinned up but your application is not aware of and that's the reason we discovered that services is something that will solve this issue and here in this specific video we are going to discuss about the same. So basically whenever uh any pod get crashed so basically service is something that will take care of each and everything. So here your application will not directly communicate with your pod service will come into the picture. The main question which we are going to address in this specific video is how do we communicate with an application in Kubernetes without worrying about the pod's current uh running IP address and without uh even worrying about what would be the new IP address that would be generated without having without even doing the guessing work and the answer that we will be getting through this entire video would be Kubernetes services and by the end of this video we are going to understand services from absolute zero 11:53:44 and we are not just going to memorize the thing with the help of YAML. We are going to actually understand the thing. So we are going to understand what exactly is service, why it does exist, what problem does it solve and we are going to see how does service finds a pod, right? What is port versus target port. This is something that we already saw but here we are going to do a deep dive. So on that note let's get started. So uh let's first understand what exactly is service. So before even that first let's understand what exactly is a service right. So let's imagine that you are in a company and inside the company there are three employees who work in the backend team. Let let us call those employees as employee number A, employee number B and employee number C. Now suppose that another employee is there with whom I need to talk and like but I'm not sure who he is. Basically I just have the context that I need to connect with someone who is from the back end team. So uh what I want you to remember here is uh I won't remember the employee 11:54:45 ID of that specific person. The only thing that I will be remembering is the that person belongs to a backend team. Right? So because uh let's say in that backend team let's say there are a number of employees right now working but uh after a specific period of time the employees leaves the company but that specific domain still remain intact. So uh what I will usually do the general statement that I will make use of is connect me uh from connect me to a person who is from a backend team right. So what exactly will happen someone from the team uh will figure out uh which person that they should connect with me. So basically they will search for the backend team and from that specific backend team whosoever is available he will connect me through that. So a service basically uh works similar like this only. So it will give us a stable way to reach out to group of pod. So instead of saying send my request to pod with the IP 192.168.10.24, it will uh say send my request to backend service. That's it. So uh the 11:55:48 service basically handles the connection to the appropriate products. So basically the architectures looks like this. So here what I will say I will say basically I am here the client. I will say to the service that I want to connect to the pods which belongs to the backend service group and here it will basically directly do the communication with it. So here the client doesn't need to keep the track of individual pod IP address that is the fundamental purpose of service and I hope this actually made sense for you. So now let us discuss one more thing what exactly is service and why uh service is not a pod right. So uh before even that let us first discuss why we should not use the pod ids because this will give you a complete clarity why we are considering service in the very first place. So let's make this problem very much practical. Suppose we have front end which is connecting to our backend service and in back end we have three pods which are running back end one back end two and back end three and each pod have their 11:56:49 own individual IP address. So our front end could be theoretically communicate to those IP. But what happens is when back end two uh is deleted, new pod will be generated and then the IP of that backend pod associated with it is will get deleted. Then what will happen based on the design of deployment it will create another backend pod for us. So we don't want every application to implement this logic. That is the something that has been done by Kubernetes. So instead of that we introduce Kubernetes service and what Kubernetes service will do basically here we will be talking about the backend service. So what it will do it will create a backend service and that backend service will have individual parts backend one back end two and back end three. So the service will be stable at the entry point the pod behind it can change but the key idea here is we don't have to memorize the IP address. All we need to worry about is the backend service. Now here we were discussing about a service is not a pod on what 11:57:50 node. So a common mistake that we usually think is since we are writing the YAML file we think that service is another pod but exactly the thing is very different a service is not another pod right a service is not your application container your application still runs inside your pod right so basically if you create a pod if you create a manifest and where you actually run a pod name engineix server so what will happen uh it will run the engineix pod inside your uh engineix container inside your pod But the service basically sits logically in front of those pod. Think of it as a networking abstraction where the service sit sits at the top and the individual pods will connect to that service. So a pod is a place where the application runs. Okay, one second I'll just show you that thing. Yeah, the pod is the place where the application is been executed. Okay, and service is the place uh which actually provides a stable way to connect to your application to reach out to your application. This distinction is extremely very important. So now let us 11:58:52 scroll down and here let us create a basic engineix deployment file. So what it will do? We'll use a engineix because uh it is easy to see the result. Suppose we create the deployment with three replicas. Right? So let's not discuss theoretically. Let me jump directly to my item so that I can explain you each and everything so that you have the context of each and everything. So now I'll switch to my item. And here let me first turn on docker first. And now let me just start mini cube. Okay. So meantime mini cube is getting started. Let me just tell you what exactly we are up to. We are going to create a deployment file with three replicas and then we are going to see what is the behavior that we can expect from a service. Right? That is something that we are going to see so that you will have a complete idea what we are dealing with and what exactly service will do to us. Right? because understanding service is one of the most important concept in Kubernetes networking. So let us wait for some 11:59:53 time. Okay, clearing the screen and now let us create a deployment deployment file. So deployment dot YML enter. So what are the four keywords uh what are the four uh building blocks of any manifest file? So see whenever you are dealing with any sort of workloads any sort of resource in Kubernetes there are four building blocks that you should keep in mind and that is nothing but API version kind metadata and spec. So let me write the same API version kind metadata and spec. Now where do we get the value for API version? So basically it's very easy. We will either we can either go to Kubernetes documentation or we can either use the cube cubectl API resources. So let me run cubectl API resources and I will run a graph on deployment. Now why I am explicitly rerunning this command so that you will get into a 12:00:54 habit of running this command and getting the values out of yourself because believe me no one ever will tell you these things. This actually comes through practice and that is the thing that I want you to develop. So let me just create the manifest file for deployment. So API version will be app/v1 client will be deployment. Okay. And now let us give the metadata. Now what exactly the metadata denotes over here? Here we are going to write the name of the deployment. So here I will define the name of the deployment and I will call it as engineix. Now specification. Now what are the configuration that we want to put over here. So basically we want three replicas. So I will define the replicas and the replicas should be three. Now next thing is here we would be dealing with labels and selector. Now see whenever you are working with uh networking in Kubernetes one of the core components one of the important component over here is labels and selector. I'm emphasizing on labels and selector. Why? Because it plays a significant role in networking in Kubernetes. Because through that only we 12:01:54 are able to identify which pod we are looking to which pod we are targeting to. So if you are someone who don't know what exactly labels and selector is I will highly recommend you to go through the previous video where I have covered labels and selector in detail so that you will get a exact context what we are dealing with right if you are someone who have already an idea about labels and selector feel free to continue the same. So now let me define the selector first and then we will define the labels. So here let me just write the selector. So selector enter and here we would target those pod which match the given label. So we are going to make use of match labels enter and now here I will define the uh label. So basically here let's use app would be engineix engineext enter so here we have defined the labels. Now let us go further because deployment will help us in creating the uh pods for us and for creating that pod we need a template. So 12:02:55 here I will define the template. So template enter and inside this template I will define the metadata for that template. So metadata enter. Now comes the main part. So inside that metadata we will define the labels of those specific part where the selector will target it to. So here I will define the labels. labels labels labels and here inside that I will just copy this exactly from here and I will use this label. So here the template is also ready and now let me just create the specification for the port. So here I'll define the spec. All right and inside this spec what exactly we are trying to create we are trying to create containers and now what exactly will be the name of that container? That is something that we are going to define over here. Yeah. So here the name of the container will be nothing much engine or maybe engineix container whatever you want. Now here I will define the image of that container and the image can be engineix colon latest or you can even use any version 12:03:55 of engineix because here we are interested in knowing how does services work. Now again the last thing is on which port does enginix container runs on. So here we are defining the container port. So under the ports I'll define the container port and it will run on port number 80. So here we have defined the port number. So you already have learned all of these in deployment. So most of this thing should look very much familiar to you. So now what exactly we are doing? We are creating a deployment named engineix and we are asking the kubernetes to create three replicas for us and then kubernetes will create a pod for us and the most important part in today's topic is label. So basically these are the labels that will be defined on those part. So every pod which will be created by the deployment will receive this label. So conceptually it will create three pod with the label app equals to engineix and the pod one will be having the label app equals to engineix. Part two will be having app equals to engineix. Port 3 will have the label app 12:04:57 equals to engineix. Now since everything is done, we can ask the service uh and we can say give me the parts where app is equals to engineix. So here the idea the mental model is created. So now let me just run escape colon wq and let us create the deployment in the very first place. So cube ctl apply - f deployment enter and here you can see deployments is created. So let me just uh run and verify the changes. So cubectl get deploy enter. And here you can see three out of three pods are running and let me run cubectl get pods o white enter. And here you can see all the three pods are actually up and running. And that is something that we were expecting. Okay. Now the initial thing is done. And earlier I was very much emphasizing on labels and selector. So let me just run a cat over here. CAD on deployment. Enter. And here we would 12:05:57 be focusing on this area. So please put your focus into selectors and this specific section that is label. Right. So what are labels and selectors? So basically it's just like a key and lock pattern where we are actually telling the deployment that these are the values the environment tags that we are uh targeting to that we are referring to. So this is probably one of the most important part for understanding services. A services uses a selector to determine which pod it should send the traffic to. For example, here we have mentioned the selector and here we have mentioned that it should only target the pods where the value is app equals to engineix. Now our pods have the label called app coline. Now what exactly it is saying? It says kubernetes whatever pods have the labels uh app equals to engineix. You just go find them and assign this label to them. So whenever the deployment is creating the pod uh what it will do it will assign these label values to them. So ideally it will 12:06:57 look something like uh your service is there it will have the uh label for app equals to engineext it will target only those part which will have those labels present. So here at the hierarchy level we have service and at the bottom you have three individual parts with the label mentioned as app equals to engineext. So this is why I keep emphasizing on labels and selector throughout this entire networking series of cubernetes because they connect different cubernetes object together. If you want to relate this with AWS, so if you remember when you are creating your EC2 instance at that time you add the tags right and why do we make use of tags? We make use of tag for identification of the services. Likewise we make use of labels and selector in Kubernetes to identify the workloads to identify the jobs to identify uh the workloads to identify service that we are creating. Right? So services use selector. If I put everything into simpler words, uh what actually labels and selector does, they connect different Kubernetes object together. 12:07:58 Deployment uses selectors, services uses selector and other controllers also make use of selectors. So once you understand labels and selectors, Kubernetes becomes very much easier to understand and it will give you a reason why you should understand why you should learn cubernetes networking and why labels and selectors are very much important in learning cubernetes networking. So enough theory done. Now let us focus on another part another segment uh for this specific video and that is nothing but service. So now we have created the deployment. Now let us focus on creating the service. Now again I will create another manifest file. So I will write service.yml. Enter. Now again what are the four building blocks whenever you are working with any sort of manifest file in Kubernetes. Pause the video and let me know the answer. I hope you have answered it. So it is API version kind metadata inspect. Remember this keyword API version kind metadata inspect. See all sort of manifest file that you will create in 12:09:00 Kubernetes it will contain these four keywords for sure because these are the building block the baseline for creating any sort of manifest file. So I'll again start with it API version metadata and spec. I hope the font is visible for you. Let me just do zoom for you. Now where do you get the value for these four keywords? Now again if you are someone who have been following this video so far you already know there are two methods basically there are three to four methods but usually that I recommend personally based on my experiences I will 100% make use of API resources why because I don't have to switch my terminal everything is present over here or else second best option is cubernetes documentation third option is you can even go to stack overflow and search there and fourth option is yeah chat GPT which I don't recommend because here we are learning learning. We should not uh we should not uh make our mind think like we already have things 12:10:00 prepared. Go through the hard way. So when the actual times come things will be very much easier for you because whenever you are learning things I highly recommend you to clear your basics once you have the understanding that then make use of AI. Okay. There are few people who make use of AI everyday. There is no problem in that. But what I suggest is learn the things first. If you have the understanding then make use of AI because at that time you are not blindly making use of AI. It will literally help you to go forward in your career. All right. So on that note let's get started. So next thing that we were searching for is what are the four key value pairs. What are the values that we would be using for services right? Again we will make use of cube cut API resources. So cubectl API resources and here I will run a grab on service. So services or service. Now here we are actually referring to this one. So here the API version for service is v_sub1. And again what is the kind? 12:11:01 The kind will be service. All right. Let us edit the service yl. And here we have the values for API version. API version is v1 and kind is nothing but service. Now again what will fall? Okay I'll just correct it. Okay. So what will fall under metadata? So here we will need to give the metadata the name of that service. So what should we call now? Since here we are dealing a tutorial with the engineext, let us give the service name as engineix service. So here I will define name as engineext - service. All right. And under the specification uh what all things we will mention. Now see I was very much emphasizing on labels and selector and here we will be defining the selector. So here service will actually know which to uh which pods it should target to. So here I will write selector and here inside selector I will define the label where it should be targeting to. So here uh remember the earlier deployment that we created this is the exact label and key and value pair that 12:12:01 we have made use of. Enter. And now apart from that what all things that you can mention in service. Now basically here we are dealing about a client calling a specific service and it gets uh moved to a specific port. So here we will define the port number two. So here I will define ports. Enter. And now basically there are two keywords that we would be dealing dealing with that is ports and target port. Now what is port and what is target port. We already have seen it and don't worry if you don't remember. I will just explain you each and everything from scratch with uh so that you don't have to look into documentation here and there. So but let me just cover uh let me just complete this uh manifest first. So target port and target port is nothing but it escape colon wq and now the service file is ready for us. Let me just run a cat on service file and let me explain you each and everything. Now what exactly is API version? API version basically here we are using the core cubernetes API version for the service. Uh and now next 12:13:03 what exactly is we have services. So basically we are telling Kubernetes that I want to create a service. Now next comes the metadata. Now what exactly is metadata? Metadata is the data of data. But again if I put it into Kubernetes term, we are telling Kubernetes that I want to create a service where uh I want to call that service as engineic service. We are giving the name to that service. So this name is important because other application inside the cluster can use the service name to communicate with it. And if you remember initially when I was giving the example at the time I mentioned that application will not remember the individual IP address of the pod they will only care about the name of the service and this is the importance of metadata and here uh the application will remember the metadata name that is engineic service. All right, let's move forward. And here is the main part under the specification. What exactly is specification? The configuration of the workload, the configuration of the service that we are going to create. And here inside specification, we have the 12:14:04 important concept, important keyword that is selector. And here why exactly it is important because it tells Kubernetes to find the pods that have labels where the value is app equals to enginex. And again, I'll show you the deployment file again. And here we are going to match the labels and selectors from deployment and from services. Now why it is important? Because let's say if there is any mismatch between the labels of selectors and the labels of the deployment then it won't target it. That's simple as it sound. It it is just like if the deployment is the lock then the service is key. Okay. It should match. If it doesn't match then it won't unlock it. It just like you have multiple keys present with you and you have the lock of deployment. You cannot use random keys. you will need that specific key and that key value pair has been defined by the labels and selector that's why I am emphasizing on labels. All right, next thing that we have is ports. Now again in ports we have target port and normal port. Okay, let me just 12:15:04 tell you what exactly it is. We will spend more time on these two fields uh in a moment but for now just remember port will define the server port and the target port is nothing but the port of the application. Right? So now let us move further and let me just implement the uh service file. So let me just clear the screen and what I will do I will run cubectl apply - apply -f service.l. Okay. And here it says service engineext is created. Now the next thing is let me just verify it. So cubectl get s get svc for service. It is a shortand that we use. Now again here is there is something that you will uh see. Okay. Uh yeah and there is one more thing. If you see the IP address, this might be diff this might differ for you also. Okay. Because uh if this is different from mine to yours, it is expected. Don't worry on that. And same goes for the IP address for the deployment. If it is differing from mine to yours, again that is also expected. But the main concept 12:16:05 over here is just focus on the output that we are getting. So here when you run cube cuttle get service here uh this is the output that we are getting. Now something interesting happened over here. Our service has its own IP and that is called as cluster IP. If you focus over here the type of that IP is cluster IP. Now what is a cluster IP? Okay. So don't worry we are going to have a dedicated video on cluster IP node port load balancer. So don't worry on that. So for now just understand the basic idea or pods have multiple IPs. Let me show you the IP of the pods too. So cubectl get pods iPhone enter and here you can see we have the individual IP address per pod that is 1 uh that is 10.244.1.2 10.244.0.3 10.244.2.2 two and we have the IP address for the cluster two right so basically what exactly is happening is the service IP 12:17:06 is stable for the lifetime for that specific service right so instead of talking directly to one of the pods IP address we can directly talk to the IP address of the service that has been provided so then what exactly will happen the service will send the traffic to the appropriate backend pod so it will be like your engineic service will be at top and at the bottom you will have individual engineix deployment part that you have created. This is the fundamental idea behind the cluster IP service. Right? So uh what exactly uh is the next thing that I want to discuss is the service will not have your application. Your application will still run on your pod. Right? So I might see something called engineic service. So here we have not defined any application details. The only thing that we define is the selector and based on those selector it will target these three pods. That is something that I want you to remember because service itself is not running enginex. The enginex 12:18:06 application is running inside your pods which are mentioned over here. The service will provide a networking abstraction in front of those pods. So think service it will route the traffic to the pods and the pod uh is the place where the application is running and the pod is the place where engineix container has been run. So if someone ask where is my application running the answer will be very much straightforward. It runs inside your pod. But if they ask how can I reliably reach to those part the answer is it should be through a service. Now earlier I mentioned about port and target port. Let me just run a cat on deployment because there is one thing I wanted to tell you that is the key and value pair that is here the one that we are using is app colon engineext and the labels we made use of is app engineext and when I run a cat on services here we are using the same level that is app engineext so that mapping is done the key and lock example which I gave is actually working 12:19:06 now let us put or focus on the port and target port right so now let's understand what exactly is the meaning of port colon 80 and what exactly is the meaning of target port colon 80. All right. So this is one of the most confusing part for many of the people who are beginning their journey with uh cubernetes networking. Let us reuse the example that I gave you earlier. So let us imagine that you are in a company and you need to reach out to someone from person who is in a backend team. So basically let's say you have a phone number. You will call that person. Let's say uh let's say the number let's say they have a phone book directory and let's say if you dial phone number 80 right so it will give a call directly to the back end team so what will happen the let's say the receptionist will receive your call and receptionist need to connect you to the internal department that is nothing but the back end service so conceptually what exactly is happening me as an user I will call to that phone number 80 and then someone 12:20:08 from the receptionist or maybe an HR will receive that call and what I will say okay I want to connect to someone who is working in a backend team then what it will do it will check the backend tip and whosoever will be available from the backend team it will connect my call to that specific member so here we can come to a conclusion that port is equals to the service port and target port is equals to the application port where the back end port is running so they can be the same they can be different now it is just like docker if you remember we did port mapping exactly the thing replic applicates over here and that's the reason it said in order to learn Kubernetes in depth in order to understand Kubernetes the fundamental thing that you should be clear about is nothing but docker so I hope you are able to connect the dots now if not we have a docker in one short video please go through it I have created it in such a way that you can get all the concepts that are actually required for you to get started with kubernetes and I believe that maximum of the people who are following this video have already covered docker so yes these things will 12:21:09 actually make sense. Now this distinction is uh really very important. Why? Because whenever you are working in real world application, these things will actually make sense. You should have a clear idea of ports and target port. Now uh next thing is does target port need to match the container port? So this is kind of a common question. So suppose the container specification says that uh the container port will run on port number 880 and the service port says that the target port is 880. So what exactly is the difference? So that is a common clear configuration. So don't confuse on those field because the container port describes that a port associated with that container and the target pool tells the service that where we are supposed to send the traffic right on the selected node. So the service uh target port should correspond to the actual port when the application is listening. So the K relationship is like uh service port will talk to the target port and the target port will send the uh traffic to the application 12:22:11 listening to that specific port. Now let us go back to Visual Studio Code where we would be covering the remaining aspect. Okay. Now I think you are already clear about U engineX deployment file that we have created. So let us scroll down and here we already covered about labels and selectors. Now let's talk about one of the important yet fundamental question. Uh let me scroll down. We have created the services. We did a highle understanding of the pods and we understood about port versus target port. All right, we are good with that. Let's scroll downward. And now let's talk about one of the fundamental thing like before even we move with the endpoints and endpoint slices that does the service know the pods ids. Right? So here is the important concept because we know that service selects the pods using the selector and here in our case we have defined the selector as app engineext but kubernetes need to keep a track of which actual pods IP currently match that 12:23:11 selector. This is the exact point where endpoint and endpoint slices come into the picture. Now if you want to visualize this I will just explain you this diagram which you see over the screen. So uh basically here we have the service right and in the service we have defined selector uh where the label app engine x is mentioned then we have the endpoint information where all the ips will be present. Now you can inspect this endpoint using couple get endpoints name of the service. So now let me just rerun the same command. Let me switch back to my i terminal. So yes here we are. So what exactly we will do? We will just run the endpoint command. So yep cube cuttle. Let me clear the screen. cube CDL get endpoints. Get endpoint for the service that we have created that is engineix - service. Enter. And here you can see the endpoint is listed over here. Now what exactly is this endpoint? You can see all the IP 12:24:12 address from our pod are actually mentioned over here. So depending upon the cubernetes version and the environment endpoint slices are also important representation. And how do you list the endpoint slices? It is very much easier as it sounds. So cube cl get end point endpoint slices. Enter. And this is the endpoint slices which is present over here. So you don't need to memorize uh each and everything because it is it is an internal implementation. So just remember the services uses its selector to identify the pods and the cubernetes maintains the endpoint information representing the current back end. So what does happens when a port dies the existence of service now. So let us see uh right now clearing the screen and here in the endpoints of engineic service we have these IP address panaran cube cuttle get pods - wide here we can see the exact IP address which are mentioned 12:25:14 over here are present in the endpoint slices now here if you see col it's the port number that we have mentioned now let's say out of these pods either one of the pod get dies so let me just delete any pod so cubectl delete pod followed by either one of the pod part. Let me delete this part. Now based on the design of deployment, what exactly it is supposed to do? Now see the thing is we have mentioned the replica count as three. Right? Now I just deleted one part. So exactly the count over here is two. Now based on the design of deployment, it is supposed to match the desired state with the existing state. Right? So what exactly will it will happen? It will create another part and the count will go back to three. But what will happen if I rerun the command once again. Here you can see there is a change in IP address. We already had 10 2441.2 which is already present. Then we already have 102442.2 which is already present but we deleted the pod. This is this is the pod where the change in IP address has been seen. So here earlier we deleted the pod with the IP IP address 10.244.0.3 12:26:16 and now the new pod which is created is 10.244.0.4. This is by by design for the deployment. Now let us see whether the end points for the services are updated or not. So now let me rerun the command cube ctl get endpoint service. Enter. Now here just note the new part the new IP which is present over here is actually updated over here and this proves the existence of services. I hope now things are making sense right because we are using a deployment Kubernetes notices that we have fewer replications that are actually supposed to be present so it will create another replacement and at the back end what it will do it will update the endpoint with the new IP address for that specific new pod is exactly what's happens behind the scene so the services continues to select the parts with the label app equals to enginex right and that is exactly what happened right now let's 12:27:18 Say if I scale the application what will happen? Right now you can say that okay Shubhham you mentioned that the current replicas are three. What will happen if I scale it up to replica with five. Let us demonstrate the same at that time will these service sets will still work. Now again see here in the service if you remember I didn't mention that you should only target two three pods or four pods that has been done by the deployment itself. But in service I only mentioned that target all the pods which have the labels app engineext. Clearing the screen and now what I will do I will just scale up the application. So cubectl cubectl scale deployment and the name of the deployment is engineext. Let me just check the deployment name. Uh I'll go to control a. So let me run the command and check the deployment name. So cubectl get deploy. So let me check the name of the deployment. So cubectl get deploy. Enter. And this is the name of the 12:28:19 deployment. All right. So let me just scale the deployment again. So cubectl scale deployment name of the deployment that is engineix. And now we will need to define uh through what number we need to update the deployment with. So here I will define the replica count. So replicas and it should be five. Enter. Now here the deployment is scaled from 3 to 5. Now in the manifest we defined the deployment count to be three. The number of replicas that we need is three. Now I'm saying through command line that it should get updated with. Now when I run Ctl get pods ovite here you can see the engineix pod these are five in number. All right. Now the main checkpoint that we need to check over here is does the endpoint for the service is also up todated or not. Basically here we didn't updated the service file and this is the exact demonstration that I wanted to say is like service has nothing to do with the uh count of the replicas because here we 12:29:21 have specified the selectors right based on that thing it will update the endpoints from the back end. So cubectl get endpoint endpoint slice and we are going to get the endpoint for engineix service. Now here just count the number here it says 10.244.0.4. Okay this is already present. Then next is 10.244.1.2. Okay that is again present. Then we have 10.244.1.3 plus two more. And these are those two additional new pod that we have created. Right? So the basic context the main conclusion from this is basically whenever you scale up or scale down your application whenever you scale up your pods all those things will be reflected in the back end and your service with the help of selector will keep a count of it. Clearing the screen and now let us discuss further. Now what will happen if I scale this thing back down right now the desired number the actual scale that we defined into the deployment here you can see is three. Now what if if I 12:30:22 scale it down to two at that time what will happen? Okay let us do the same. So cubectl uh cube okay one second cubectl scale deployment name of the deployment is engineext - replicas and this time I will make sure that the replica count is reduced to two now when I do cube cl get pods enter here you can see only two pods are running okay and when I run hyphen oide here you can See we have only two ips which are present associated to those pod that is 10.244.1.2 10.244.0.4. All right. Now let us check whether in the service endpoint these two IPs are updated or not. And what will happen to the existing IPs. So now let me run cubectl get endpoints for the engineic service. And here you can see ladies and gentlemen only the two IPs from those associated ports are present. Now the question is why? Because consider it 12:31:24 like whenever you are deleting whenever you are scaling up or scaling down the application at that point those entries are removed from the endpoint and that is how it is tracking the application ports. So I believe now it will make sense for you to eventually understand and visualize that engineic service sits at the top which monitors all your ports based on the selectors where the labels has been defined. Right now when we scale it down to replica count 2 the number of the selected backend ports changes the service uh remains the stable access point and this is very important Kubernetes pattern that we have to uh understand because service will keep a track of the changing number of pods based on the selector that we have mentioned in the manifest file. So the client doesn't need to care how many pods are currently running behind the service. It will be taken care behind the scenes and you don't even have to worry about. Now based on that there is one question that might have popped up in your mind and that is is service a load balancer. Now you only answer me is 12:32:25 service a load balancer or not? But before even that this is something that we have performed right now. What happens when we delete a pod? What happens when we scale it up? What happens when we scale it down? Right? And this is the mental model that I was saying earlier. Service sits at the top and be and just below it we have the pod which are been monitored based on the label that we defined. Right now let us discuss about load balancer. Is service a load balancer? Now you might ask if service sends the traffic to multiple part is it a load balancer? So the mental model over here would be like just think about the client who sends the uh request to the service. Now service is someone who can actually send that traffic to pod 1 2 3. Now the traffic can be distributed among the available backend ports which we are going to do a deep dive in the uh later video because there actually we will be discussing about the behavior of the ports. Now let us discuss about the service discovery using DNS. Now what exactly is DNS domain name system? Now let's make our application even easier 12:33:27 to use. Suppose uh the service is engine service the name of the service that we have created. So inside that cluster application can generally communicate with the service using this DNS name. For example, whenever you want to connect with the uh service called engineic service, what exactly you will use? You will make use of http//enenix service. Here the main point here the main point is uh we don't have to remember the IP address. Now think if I ask you to remember the IP address as in order to access my service you just have to remember 192.168.0 0.0 will you be able to remember it? No. If you want to if you want to uh navigate to Google, what if if I ask you to uh remember the IP address for it 8.8.8.8 or maybe if I ask you to remember the IP address for Instagram, will you be able to remember those IP address manually? No. Why? because our mind will not be able to capture those much of details because there are hundreds of website which we navigate on a daily basis and 12:34:29 for us as an end user it becomes very much difficult to remember all those IP address that's where DNS comes into the picture so what will happen is our front end will conceptually say that hey I need to call a service called engineic service now kubernetes DNS will help us over here it helps us to resolve that service name and the important part over here is the application will call the DNS and DNS will uh call the service and the service will call the ports that exactly will happen over here. So if you don't understand what DNS is just remember that there is a label that we are giving on top of IP address so that whenever we need to call we are not calling that IP address specifically we are referring to that we are referring to that name. So yes now let's discuss about name spaces and services. Now one thing you'll encounter when you're working with large clusters in a name space. Suppose that I have two name space. One is from development, one is from production. But the service name here is common that is service from back 12:35:29 end and service uh from back end in the production. So both can have the same ner service name because they exist in different name spaces. Now again what exactly is a namespace? It is just like having two bottles, right? Each individual bottle we have individual quantity of water, right? Likewise we have environments that we have created. We have name space for back end. We have namespace for dev. We have name space for production. So both are different entities. So a service name is normally resolved within the appropriate namespace context which we defined. So a fully qualified DNS name will look like this. And gen service name of the service default svc for service cluster local. And this is exactly what I want to say for now. If you don't understand what exactly is this, don't memorize it because this is something that we will cover. Namespace is basically a part of identity which is used for Kubernetes DNS-based service discovery. Right? Now here we talked about namespaces its 12:36:31 relation with services. Now why? Because there might be a question here we are using service but again what will happen if I use service with different namespaces. Can it work? The answer is yes. Okay. So that was the main purpose. Now let's us let us talk about the most important thing that I have seen that is the selector label mismatch. Now if you remember from the starting of this video we have been uh emphasizing a lot on the name of the selectors right. So now let's intentionally uh create one of the mistake uh that will help us to understand why labels and selectors plays a very important role when it comes to services. So now what I will do I'll switch to my terminal and here it goes. Okay. Now, right now I'm in my terminal. What I will do, I will open my manifest file vim deployment. Mml and here what I will do instead of using this label, I will just update the label to genuin. 12:37:31 And now let me just delete the existing deployment that we have created. So cubectl get deploy deploy and cubectl delete deployment and the name of the deployment is engineix. Okay. So we have deleted the uh deployment and now when I do cubectl get svc for the service it is still up and running because we haven't uh deleted it. Now when I want to get the endpoints for it let me just list the endpoints also. the endpoint for this engine service. Here you can see there is no endpoint which are present. Now everything looks fine. The next thing that I will do is I will just apply the manifest file. So cubectl apply -f deployment. Mamel. Now see here we are getting one error because here it says engineext invalid the spec template method spec.mplate template dot metadata label have an invalid value where we have mentioned the app colon uh app value as engineix temp where the 12:38:31 selector does not match the label right so basically here what exactly it is saying that okay you have defined the log but your key is not matching that specific log so make sure your lock and key are of same so I'll again edit my deployment file and here I will just match the labels and instead of putting this as engineix I will mark it as engineix m escape wq Now let me apply the file once again. And here the deployment is created. Now cubectl get ports hyphen white. Okay. Here are the three engine port that we have created. But but but what if if I run the endpoint over here. This time you can see the endpoint is not reflected over here. This is the importance of adding labels into your deployments because see here the service discovery didn't happen. Why? Because there is a mismatch in label. Now what will happen if I just update the manifest file and rerun this command. So let us do the same. So vim 12:39:34 deployment and here let me just make change it back to square one. I'll delete the extra temp over here. And likewise I'll update it over here. Escape WQ. Let me delete uh the deployment which is currently present. So cubectl delete deploy uh deployment name is engine x ngx engine x engine x. Okay. Now let me apply the manifest file. So cubectl apply - f uh followed by the deployment file. And now let me just search for the endpoint. And now this time the IP address reflected into the end point. This is the practical demonstration that I wanted to show you that what will happen if the selector is wrong. So this is the intentional thing that I want to tell because what happened over here is uh the service asked gave me the pod where the app is equals to engineix but there weren't any because the labels that we used over here was app equals to genix. Uh because here we made use of app equals to engineix hypen there was a mismatch and 12:40:35 that's the reason it didn't discovered it and that's the reason the endpoints were not getting updated. So this is the first thing that you should uh check whenever you are facing an issue where the service is not working. Check the labels of the pod. How do you check the labels of the pod? So it is again very much easy. Let me go back to my terminal. Clearing the screen. Cubectl get pods hyphen show hyphen labels labels. Enter. And here we can see app equals to engineix is present over here. And that will actually help us to understand uh whether the service is working or not. So the first troubleshoot method that you should do uh whenever you're dealing with services first check the labels of the pod. Second you should inspect the service. So how do you inspect the service? So cubectl describe describe service for svc and the name of the service engine service. Enter. Now here the next thing is here you need to keep a focus of selector. Here this selector should match with the labels 12:41:36 for that specific part that we actually try to create. And the third that you should check is if the service is not working is you need to check the endpoint. So cubectl get endpoints for the service name service. Enter. And here you can see the IP address are present. So what are the three things that you will check whenever service is not working? First check the labels. Second, check the uh labels from uh check the selector from uh the service. It should match the labels. And third, check the IP address are populated into the endpoints or not. These are the three troubleshooting step that you should check whenever a service is not working. Right? So uh again what are the most common uh troubleshooting step that you should follow? First you need to check whether the pods are running. How do you check whether the pods are running or not? Uh you can check it by running cube cuttle get pods. And here you can see all the parts are running. Then you can check whether those uh those part whether they 12:42:36 have the exact expected labels or not. Yes, you can check it by running cube cuttle get port show label. Third thing you can check whether if the service is not working. First check whether the service exist or not. So cube cuttle get service will help you with the answer. So cube cl get svc enter and here you can see engineix service is present over here. Now next is uh when you want to do a deep diver uh deep dive on your service just inspect your service and describe it. Here you need to check the selector and this should exactly match the labels of the part then it will be mapping that it will be just like mapping your services with your ports. Next is you can check the endpoint so that you can validate whether the IP address populated over here or not. Right? And next is check the connectivity from another port. So basically you can just run a temporary curl pod from where you can curl to your uh remaining ports and that will help you to understand the connectivity from one port to another. So yes I think that exactly uh is the thing that I wanted to tell because uh right now we can discuss 12:43:39 what does a service actually gives us. Basically without a service uh the life will be we have to remember all the IP address but when service comes into the picture the client will directly contact the service right and the service will flow the traffic to the most eligible parts so client don't have to worry about the pods the client knows the service the service knows the back end part that separation is extremely very powerful client doesn't know uh doesn't need to know how many pods are running which node they are running on what are their current IP address and which pod will replace them next and what would be the IP address for that next pod. Service provides a stable abstraction for all of these and that's the reason we are considering service in the very first place. So now we understood about service. We understood uh what value does it provide. Now let us discuss one of the aspect of service that is what is the difference between service and deployment. So let me just switch the screen to Yep. All right. So let us talk about service versus deployment. All 12:44:41 right. So what exactly is the difference between service and deployment? Now if I put into simpler words uh a deployment actually answers how many ports I should have and how should I manage them and service answers how can I reliably reach to those ports. This is the exact difference between a service and a deployment. Now since we are talking about deployment and service, let us discuss the difference between pod and a service. because the pod is actually the one who runs your application and service is someone who is navigating the traffic over there. Now let us put it into simpler words. Now what exactly pod does? It runs your application and what service does it provides a stable network access. Now think of it as pod is the worker the label who is actually doing the work and service is the stable uh front desk uh for the workers right. So the workers can change but the front desk remains the entry point. Right? Now let us discuss about ingress and service. Now if you're coming from the previous video you are already aware 12:45:41 what exactly ingress is and here we are doing the distinctions between services and ingress. So uh this is one of the most important thing that you should have a clarity on because a service provides a stable access to the pod. However, the ingress provides uh and handles the HTTP and HTTPS routing traffic. So, uh when I talk about ingress, just imagine that green lock with the HTTP and HTTPS web address. So, here we are talking about inter internet where the person from outside is trying to access to your service your application. So, how does the traffic flow from internet the traffic will go to ingress from ingress it will go to service from service it will go to ports. So, don't confuse between them. The typical uh architecture will be like your ingress uh your internet will be present at the top which will be reflect which will be sending the traffic to the ingress and the ingress will sending the traffic to the front end service and the back end service and based on that it will forward the traffic to the pods. We'll go we'll do a deep dive into ingress 12:46:42 later. So don't worry about that. So now since we are working uh with ingress there are few questions that you should ask to yourself. There are three important questions whenever you are dealing with uh services. First is uh what exactly is a service right you can check it with the name itself. So and second thing is uh you need to check what ports does it select. Basically whenever you're dealing with service these are the three question you should keep in mind what port does it select what port does the service is exposed to and where does it send the traffic to right and all the things can be mentioned with if we are talking about what port does it select we are talking about selector what port does the service expose basically here we are talking about the port and third where does the uh traffic has been sent. So here we are talking about the target port. These three question explains the larger part of service and it actually tells how the services actually works. Right now there are few important input interview questions that I have added. So which I want you to check uh after this video. Feel free to check out this readme.md file. I'll just p I'll just uh 12:47:46 push it right away so that it is available to you whenever you are doing the hands-on. Again all the exercise questions are pre all the exercise manifest file are present over here along with the commands feel free to check out the same. So this will be literally helping you to understand what exactly services I deliberately have added all the pictures the mind map that will help you to understand services in a deep type. So yes let me just push it once again. So get status. All right. So get add all the files from subdirectory number 15. So get com. 12:48:34 All right. And now let me just validate whether the changes are reflected into the browser because here we need to check whether it got upd up updated or not. So yes that is Kubernetes service for us. We started with a simple question that pods have IP address, pods are disposable and the IPs get changes. Then we introduced services. Now what services does? We learned that services gives us a stable way to access the group of pods. And we learned that services uh uses labels and selectors to identify those pods. We looked up with cluster IP as the default internal service model. And we understand the difference between port and target port. And that is how we came with endpoints and endpoint slices which represent the current back end uh for the services. And most important we understood what happens when a service is deleted. It is replaced. It is scaled up. It is scaled down. And this is a most important thing that you should understand whenever you're starting your journey with Kubernetes networking. So yes, that was all and just remember one sentence whenever you are working 12:49:36 with uh services and Kubernetes. the pods runs the application service will provide a stable way to re to reach that pod right so once that concept is clear the rest of kubernetes networking will become much much easier so yes that was all in this video and I will see you in the next one until the next time uh keep learning and thank you very much everyone welcome back so in the previous video we talked about services in detail we now know that pods are ephemeral in nature whenever you delete the port a new IP is assigned and in order to resolve that issue in Kubernetes networking we came across with the concept called services. So what exactly is service? So basically service is a stable way uh where it is helping us to communicate with the ports. But there is one real important question that if I have a cubernetes application how do I actually expose those application? So basically I can have multiple requirement. Maybe I want uh that 12:50:36 application to be accessible from pod to pod or maybe I want to access that application from my laptop or maybe I have a real application running in the cloud and I want all the users from the internet to access that application. So these are the three different requirements that we have. So Kubernetes helps us with different sort of service type uh in this specific scenario and that is exactly what we are going to discuss in this video. So yes uh the three service type that we are going to discuss today is cluster IP, note port and load balancer. So I'm not just going to explain you the differences. We are going to write everything from the scratch. We would be doing things hands-on. We would be creating the YAML so that things will eventually make sense for you and uh you will be going to understand how does the traffic flows and this will be a very good understanding that you would be learning today and yes so before further ado let's get started. So let's first start with the cluster IP and before even we start creating the service for cluster IP let us first create a deployment that 12:51:37 will help us throughout this video. So I will be creating only one deployment file that will be helping us to learn cluster IP note port and load balancer. All right. So we are already aware what exactly is deployment. So let us directly create the manifest file for deployment. Right. So uh we will be creating the deployment manifest file for engineext. Why? because it makes things very much easier, simpler to understand. So yes, let us create the deployment file. So I am here on my terminal. Let me create my deployment file. So deployment. All right. So uh right now I'm insert mode. So whenever you are creating any sort of manifest file in Kubernetes, what are the four keywords that you have to keep in mind? Till now you have been following the video. So I think you already are aware of it. API version kind metadata inspec. API version kind metadata and spec. So let's go with that. So API version kind metadata 12:52:37 and spec. All right. Now again where do we get the value for API version? Where do we get the value for kind? Again we have multiple sources but the one that we usually use is API resources. So cubectl API - resources and we would do a grab for deployment enter and here uh the API version is app/v1 and the kind is deployment. All right so let's go to the deployment file and here I'll update my API version to app/v1 and the kind would be deployment here. All right now let's move forward with the next section uh that is metadata. So in the metadata we would define the name of the deployment. So I'll just give a name over here and the name of this deployment would be nothing but enginex. Now comes the next section. Now what is specification does? Spec is nothing but the configuration of that deployment. So here we would be defining the configuration for the deployment. Now again when you are dealing with deployment you are dealing with the 12:53:38 replicas right? So we need to define the replicas. So here I'll define replicas and here let's say I want replica count as four. All right. So we want this deployment should create four replicas for us. But again for what we will need to define the selector right now you are already aware of labels and selector. And yes please pay a close notice. Please put your focus into labels and selector whenever you are dealing with networking in Kubernetes. Right? So since here we would be dealing with services I want you to pay attention into labels and selector. So yes let me define the selector here. So selector. So here in the selector we will define the match labels and don't worry I'm going to explain it to explain to you it once again so that things will eventually make sense for you. So in the selector we would define the match labels match labels okay and inside match labels here we would define the important segment that is the label of that application. So here I'll just write app colon engineext. So this is 12:54:40 the label uh that we would be referring throughout the video for all the services. Let it be cluster IP, node port or load balancer. Right? So yes, we have created the uh selector. Now let us define the template for the specification. So here let me define template and I believe we are correct on the indentation. So yes template and this template is for B. This template is for creating the BS right and again in that template we'll need some sort of metadata. So this metadata will be for the parts that would be created. So metadata and inside that metadata we need to provide the information such as the labels labels and again we are going to use the same labels which we defined earlier in the uh selectors. So here we defined the uh labels as well. Now the next part that is uh that is nothing but the specification. Specification this will fall just below in the range of metadata which is already inside the template. So here I'll write the specification but again this specification is for what 12:55:41 this specification we are writing for the containers. So I'll just write containers containers containers all right and here in the containers what exactly we are trying to create? We are trying to create a pod right? So here let me give the name of the pod. The name of the pod is nothing but engineix. Okay you can give any random name that you want. Feel free to do the experiment on the same. And here I'll provide the name of the image. So here it would be engineix colon latest. You can again use any version of your will. Okay. And then we would define the ports. So engineix runs on which port? Engineix runs on port number 80. So here I will define the container port container and the container port is nothing but 80. All right. Escape colon wq. Let me just apply the manifest file. And how do we apply the manifest file? cubectl apply. We'll pass the deployment. ML enter. And here it says that our 12:56:42 deployment file is created. Now let me explain you each and everything whatever we have written in the manifest file so far. So the first thing that we did is we defined the API version that is app/v1. This tells kubernetes that which API version we are using for deployment. Next we have is kind. Now what exactly is kind? This tells kubernetes that the resource uh that we are creating is nothing but deployment. Now then we have metadata and here in the metadata we have defined the name engineext. So this gives deployment the name as engineix. Now we'll come to spec. Spec is nothing but the configuration for that deployment. Right? So spec is where we describe what we want from this deployment and what it should actually do. And next is uh we have defined replicas. So here we have defined the replica count as four. So we are asking Kubernetes to maintain these number of set ports. So here the number of part that deployment will take care is four. Next we we are asking uh Kubernetes uh that is here we have defined the selector. Now what exactly tells this 12:57:44 tells the deployment which pods it belongs to right the deployment is looking for the pods with the label app is equals to engineix which we defined over here now let's move forward and here we have defined the template now for what this template is for this template uh tells kubernetes like what pods it should create and then inside that pod we have the labels now this is extremely very important because this is the exact key that we are looking for So for all the pods which have been created from this template it will give the label as app is equals to engineext right and later our service will utilize this exact label for discovering this parts right then we have spec now this spec is for basically uh for the pod that we have created and then we have containers. Now here we have defined the specification for the container. Here we are defining containers that should run inside that pod. And then finally we are telling the name of the container, the image that it 12:58:44 should use and finally we define the ports. The ports that is uh that we are using is container port 80. So this tells uh that engineix container is expected to use port number 80. And one more important thing that you have to keep in mind over here that container port does not expose the application outside the port. It will be still inside the port. Here the actual stable network will come definitely from the service which we are about to create. Right. So now since the deployment file we already have applied it. Let us see the changes in action. So cubectl get deploy deploy enter. And here you can see it is up and running. Let me just verify the pods. So cube ctl get pods ovide. And here are our all the pods which are currently up and running. All right. So, so far so good. Uh we are done with this. So if this pod gets deleted, what Kubernetes will do? So based on the uh deployment behavior, 12:59:46 the nature of deployment is if let's say either one of the pod is deleted, what it will do? It will create another pod. But the change over here would be the IP address. Okay, the change would be the IP address and that is again we are going to tackle with the help of service. But again, let me just show you without even just sounding it theoretically. Let me delete either one of the pod. So, let me delete the last one. Uh uh the one with uh this one. So, let me delete this one. So, the current pod IP is 10.244.0.10. Okay. So, let me delete it. So, cube ctl delete pod and the pod name. Enter. Okay. Uh let me just correct the pod. I just entered the IP. So, this is the pod which we want to delete. So, yes. ubectl delete port followed by the port name. Now what it did? It deleted the port from the existing name space. Right? Now again we didn't define the name space. So it is deleting it from the default name space. Right? We are already know what namespace is used for. Namespace is used for the isolation of the resources. 13:00:46 Right? Now since we are learning the things we are creating everything on default but the standard practice is we should never create resources into the default name space. Right? This we are going to see later in depth when we are going to do the projects at that time things will eventually make sense but right now put your focus on services and that is something that we are going to learn today. So yes now since we have deleted the part let us first check the IP address. I'll again rerun the get ports command to check whether a new pod is created first and what is the change in the IP address. So let me just run cube cuttle get pod wide. So earlier we have this pod 10.244.0.9 0.9 we already have that. Okay. 10.244.0.8. Okay. We have it again. Then we had the third one 10.244.0.7. Okay. We have that too. But the one that we deleted was 10.244.0.10. It got deleted. This is the port that I am referring to. Okay. And on on that place we created a new pod. Basically 13:01:48 the deployment created a new pod with the IP address 10.244.0.11. Now I believe that you have a complete understanding of deployment. So let's move forward with the services. Now let us create the first default service and that is nothing but cluster IP. So cluster IP is actually the default service type in Kubernetes. That means if I create a service and I don't specify the type, Kubernetes creates a cluster IP service which we saw in the previous video and now here we are actually going to make the things. So let's create one explicitly uh explicit cluster IP service because I want you to clearly see what exactly we are doing. So let me create a new file. So web cluster ipamel. So what I'm going to do is uh like since I want to share all these files with you all. I'll create three service file. One for cluster IP, one for node and one for load balancer. So that when we are comparing all the three files, you can see all the all three of them parallelly 13:02:49 in one uh video window. All right. So yes, again whenever you are dealing with any sort of manifest file in Kubernetes, what are the four keywords that you have to keep in mind? API version, kind, metadata and spec. Let's do it. So API version, kind metadata and spec. Now again where will I get the value for API version and kind? Okay, I'll get it from API resources. Let me run the command. So cube cl API - resources and here I want to do a grap on svc or services. Okay, I'll just do a little bit of zoom out clearing the screen and I'm rerunning it again. Okay, so here the API version here is v1 and the kind that we would be using is service. Okay, so let me just go back to my manifest file and here let me update the API 13:03:50 version. It is nothing but v1. All right, now next is nothing but the kind. Now what is the kind? As we saw in API resources, it's nothing but services. So here we have defined the service. Now again in the metadata, what would be the name of the service? So I'll just name it as engineext and since we are doing a hands-on for uh cluster IP I'll just write cluster IP over here. So cluster IP and then let me give the specification for this specific uh service. So since we are dealing with services let me explicitly write cluster IP even if I don't write type uh so the by default uh type of service that has been taken is nothing but cluster IP. But since we are doing things from scratch, I want to show everything uh to you so that when we are comparing all the types of service, it would be easier for you to understand. So yes, let me just define the type. So the type of service is cluster IP. Make sure here in cluster IP the C is in upper case and 13:04:51 the IP is also in upper case. All right. Once the type is defined, the next thing is we will define the selector. And again this is something that I want you to put a focus on because in the previous manifest that we created we defined we focused on that uh labels and selector right we would be utilizing the same labels over here. So here in the selector I will define the uh key and value. So app engineext. So this is the selector that we have defined. And the next is we will define the ports. So here let me define the ports. ports and inside the ports we will define the port number on which it runs. So port number 80 and here we will define the target port. So target port. Now again if you uh think that this is something new so let me just tell you each and everything line by line so things will eventually make sense for you. Cat on cluster IP. So let us go one by one. All right. First thing that we have is API version. So what exactly it does? It actually tells services belong to the core 13:05:53 cubernetes API. So we are running API version v1. And where did we get the value from? We get the value from cube cuttle API resources. Right. Next we have is the kind. So what kind does this tells Kubernetes that we are creating a service uh we are going to we are creating a workload service. Right. Next is uh we have defined metadata and here in the metadata we have given it a name that is nothing but enginex cluster IP. So we are giving the service the name as enginex - cluster IP. Now we have spec. Now what exactly spec does over here? This contains the configuration of a service. Then we have type cluster IP. Okay, this is important part. So please uh focus over here. So uh here we are explicitly telling Kubernetes that we are creating the service as a cluster IP service. Now what exactly is a cluster IP service? A cluster IP service provides a stable internal endpoint for the application uh inside the Kubernetes 13:06:53 cluster. Right now next uh we have the selector and inside selector we have defined app engineext. This is how service finds all the backend uh ports all the backend APIs. Remember the deployment that we created with the pods had the same label which we are referring over here right and that was nothing but app equals to engineix. So the selector says that find me all the pods where the label is where the label app is equals to engineext. Right? Then the next we have is ports. Now again this is again an interesting part where I want you to put your focus on. So this defines the port for our service. And here is the confusing part which I want to clear. So first is we have port 80. So this is the port exposed by the service. And then we have target port. Then what is the meaning of target port? So this is the port where the backend port where the traffic should go. Right? So in this example the service port is uh port number 80. And secondly is the 13:07:55 pod port that is nothing but the target port which is again port number 80. So they happen to be on uh they happen to be the same but uh they can they can be different to at the same time. So now let us apply the manifest file and see what exactly are the results. So let me just apply the file. So cubectl apply - f followed by cluster ipl. All right here it says service engineenix cluster IP is created. All right clearing the screen. Let us verify the same. So cubectl get svc enter and here you can see engineix cluster IP is present over here right and here you can see the important part that we need to check over here is nothing but the type and the type is nothing but cluster IP right so uh here you can see one more thing that the IP is belonging to the service this IP is actually belongs to the service right so this IP is not of our pods uh this is not the IP for one of the pods that we 13:08:56 have created. The pods can come and go which we actually saw. These are the pods are actually effimilar in nature. Even if a pod is deleted, it will create another pod. But yes, there will be another IP that will be getting that will get associated with it. So service will provide us with a stable endpoint. So now since we have this IP, let us do a test and let us verify whether we are able to maintain that connectivity or not. So now let us actually test it and uh basically since we are using cluster IP we know that it will be allowing us to do the communication within that cluster. So what we are going to do is we are going to create a temporary pod that will act as our client where we would be trying to uh connect with this uh IP. So let me just create a temporary pod. So cubectl cubectl run and if you remember this is the same command we executed earlier. Now what exactly curl does basically it's act as an client that will help us with the communication and here I will uh here I will define the curl image 13:09:58 curl image and here it will be like curl so it would be hyphen image equals to c image and then here we will run it into interactive mode and then we want to take an uh sh session so hyphen - space sh enter so here it I create a temporary client for us which will be helping us to test service cluster type. All right. Once it is done, what we'll do? We'll just try to communicate with the service that we have created. So basically there are two methods. You can either do it with the cluster IP that has been provided to you or you can even go with the service name. We'll first try with the service name and then we'll go forward. We'll move forward with the cluster IP. So both things works the fine and that is exactly what we are going to see. Okay, it is taking time. So let us wait. Maybe my internet is slow. 13:10:59 All right, it says port deleted from default name space error timed out. Waiting for the connection. Uh let's do it once again. I think it is not image. It should be images. Yes, now I think it should work. What it says? Error from server already exist. Okay. So I think uh we have this pod already from the previous uh session. So that's the reason we are getting this error. So let me just remove it. So cubectl delete pod curl. And once it is deleted, let us create a new session. Now this time it should work fine. All right. So the curl pod is up. Our client is ready. Now let us do the testing. So here what we'll do, we'll just do a curl on http col/ slash. We'll just copy the service name. Okay. And now what we are going to say is when we press enter, here is the 13:12:00 magic. We are able to connect internally within our cluster to the ports that we have created. So that is the output that we have seen, right? I hope that made sense. So now let me just make an exit from here. So what we did we actually ran a curl to that service and that service send the traffic to the pods. Now uh we got the response from engineix. So our traffic was basically going from this temporary client to the pod to the cluster IP service and then one of the engineext pod was listening and then it was going to one of the engineext pod. So another thing is why can't we normally use the cluster IP from the internet. Now let's say if I am here and I'm sitting uh on my laptop and that is outside the Kubernetes cluster and I simply want to access it. So can I do it with my uh normal setup with the cluster IP. So basically let us test that too. Let me switch to my Chrome browser. Okay. Now here what I'll do I'll just copy the same uh let me just 13:13:00 copy my IP address. Okay. and I'll go to my browser and here what I'll do I'll just type http col / sl/ and this is the IP address colon port number enter now when I press enter you have to just notice one thing it won't show us the result now why exactly the same because cluster IP provides the communication inside the cluster right and that's the thing it is uh it is not showing us any output right so here what exactly happened let Let me explain you once again. Let me come back to my terminal. And yeah, so what I did, I went to my address bar. I type http/ followed by the IP address, the cluster IP address that we got from the service. And then when I hit enter, uh I didn't got anything. So uh that's because the cluster IP is designed for the internal cluster access. And this uh distinction is extremely very important because uh if my requirement is my front- end pod 13:14:02 needs to communicate with my back end pod then cluster IP is usually the exact thing is what I need. But if my requirement is user from the internet should access my application then cluster IP is not enough alone you will need something called note port and that is exactly what we are going to see now. So now again we are dealing with another sort of service type that is note port. So let us create one more manifest file for note itself. So now let me clear the screen and here I'll just create a new file. So node port dot camel enter. Now again since we are creating a manifest file. Four keywords that we need to write is API version metadata and spec. Now again uh if you want to know the API version where we can get it from we can get it from cube cuttle API resources. But again since we created the services earlier also we are very much well aware that the API version for 13:15:03 service is nothing but v1. Then second is the kind what exactly we are trying to create. We are trying to create a service. So I'll just write service over here. Now let me just create the manifest file quickly and then I'll explain it to you line by line. So engineext and this time the name of this specific uh service that we are going to create is a note port. So I'll just write note port over here for easy distinction which we are going to see later in this video. Now in this specification let me just define the type of service. So here the type of service is nothing but node port. Make sure the n is in upper case and p is in upper case when you are defining the service of type node port. And when it comes to cluster IP, you have to make sure the C and IP are in uppercase in cluster IP. All right. So now let us define the selector. Selector and here in the selector we'll define the labels. So app colon NGX and after that we'll define the ports. So inside the port we'll define port 13:16:05 port. It uh it actually uses port number 80. we will define the target port and again I'll define port number 80 over here and there is one more port which I wanted to share you that is nothing but a node port and here in the note port I'll just write 3 30,00080 and yes that's it escape col wq and now let us go through each and everything line by line because there are one more there is one more new entity that I added over here so yes let's understand each and every line over here. So again the first thing that we have over here is nothing but API version. This is the core Kubernetes API. Second we have uh the kind which is nothing but service. Here we are telling Kubernetes that we are creating a service. And then third we have the metadata where we defined the name as engine note port. This gives service the name and the name that we have given over here is nothing but enginex note port. Now next comes the 13:17:06 spec. specs are nothing but the configuration. This contains the service configuration and then we have the type as node port which we are actually looking up to. So this is the important change. We are telling Kubernetes to expose this service through a port on the Kubernetes node. So next what we have we have a selector and in the selector we have defined app and engineext. Again we are selecting uh the pods that have the labels where the key is equals to app and the value is equals to engineix and our notes service is still using the same engine port that we have created with the help of deployment. So now let's move forward and do a deep dive into this section because here you can see there is there are few new guests that have arrived. So here we have ports. So inside port we define what ports we would be working with. So the first one we have is nothing but port. So as I mentioned earlier this port defines nothing but the service port. Then we have target 13:18:06 port. And this target port is nothing but it is the port on the pod. And finally we have node port. Now here in the node port we have the value 300080. So this is the port exposed on the kubernetes node. So now we have three concepts. node port which is 300080. We have service port which is running on port number 80 and then we have pod which is currently running on 80. So uh the request can conceptually will like the requ the the client will um go to the node IP where uh the port would be 3080 then the traffic will be forwarded to the node and from it will go to service on port number 80 and from service it will go to the pod on the eligible port it will hit port number 80 and we'll be able to see the result. So now let us run let us create this service. So cubectl apply -f the name of the file is note port. So note portl and again you can give any name to the manifest file. So again here 13:19:08 we faced one issue. Let us troubleshoot the same. So error from the server it says a bad request error when creating notebook.l service in version v1 cannot be handled as a service cannot unmarshall object into gostruct. Then here it says the issue is with service spec and spec ports of type v1. So let me just check what exactly is the issue and it's mostly somewhere nearby over here. Okay. So under the spec we have defined the note port that we actually did correctly and note port with ncaps and pcaps. Okay. Then we have ports uh with s. Okay. That is also correct. Here we were supposed to provide Got it. This is the issue. Here we need to provide a space and an indentation. Now it should work fine. Escape colon WQ. And that is how you troubleshoot the issue. So here the 13:20:08 issue was he said unmarshall object and then he also specified where exactly we're facing the issue in this specification inside the port. So the issue was somewhere around this area. We didn't provide one dash and that's the reason it put that error. Let me just apply the file once again and this time you can see service engineext note port is created and that is how we do the troubleshooting. We didn't even outside the terminal. We tried to figure it out. If things wouldn't have worked out, we would have gone to internet. we would have referred the Kubernetes documentation and again if even if we still don't get the help from Kubernetes docs then finally we would have used Gemini or chat so now since our work is done let us verify the results so let me run cubectl get service svc enter now here you have to keep few things in mind and here you will see the result something like this let me just clear the screen and yes 13:21:08 here This is the uh service that we have created. The first thing that you have to see over here is the type of the service that we have created and it is nothing but note port. Right? So this is the result. And second thing that you have to observe over here is it says the port number is 80 col 300080. This is again most important thing that you have to see. Right? So what it exactly tells us that the service port is 80 and the node code where uh the client will be listening is 300080. Right? So let us navigate and see whether we are able to see the output into the browser or not. But again since I am using mini cube I will need to expose it because it is running on my Mac. So on my Mac I have installed Docker and then on top of it I'm using mini cube. So in order to see the result for uh notebook I will need to run one command that is nothing but mini cube mini cube service - URL 13:22:11 for the service name note port. So note port engine x ngx note port. All right. So here what we are doing we are defining a mini cube to share the URL for the service name of the service that is engineix note port and then we are we want that URL. So pressing enter here I have that URL present with me. So I'll just copy it from here and now let me go back to my Chrome browser and here let me validate the changes. So here I'll go and paste it directly here. Enter. And here you can see the output is reflected over here and it says welcome to EngineX. This is what we wanted to validate. Now coming back to my terminal. Now let me just kill this process by pressing Ctrl C. So now why do we need a node port? Now imagine our Kubernetes uh node has an IP address 13:23:11 called 192.168.1.10 and the node port is 3080. So we can conceptually uh uh access the application using the IP address colon followed by the uh port number. So usually when we are learning AWS whenever we are hosting any sort of application we are enabling the security groups and finally we are accessing the application from the browser exactly the same thing we did over here. So the important thing is that we are not connecting uh to the pod directly. we are connecting it through the nodes IP and the node port. So, Kubernetes handles the service routing to the backend ports and that is something that we demonstrated right now. This is useful for simple external access or it can be useful for testing and this can be uh fruitful for the environments uh where we need a routing to the traffic to the nodes. So yes, but again there is one more problem in note that is uh we 13:24:13 don't want the user to remember the IP address. See if I ask you to if I ask you to remember the IP address for Google, if I ask you to remember the IP address and the port number for Instagram, will you be able to do it? So exactly not. And for production application, we usually want something very much cleaner and uh the IP address colon the port number doesn't look clean, right? For testing purpose definitely we can use it but for production we need something called https/myapp.example.com. We may want an external load balancer in front of our kubernetes application. And yes that is where the third type of service called load balancers comes into the picture. So now let us create the third service type. So I'll just do vim load balancer. So again I'm creating the manifest file once again. So API version meta data and here is the spec. There is 13:25:16 one more case that I want to tell you but yes once load balancer is done then I'll tell you. Okay. So yes since we are aware of the API version for services we'll write v1. And where do I come with the conclusion from? So I'll just try cube cl uh api- resources and we'll run a grap on svc svc not svx and here you can see the API version that it is using is nothing but v1 and yes the name of the kind is nothing but service. So let me edit the load balancer yl file once again and here I'll update the kind. The kind is nothing but service and now let me just give a name to this uh service that we are creating. Now since we are creating the service for load balancer the name that I will give to this specific service would be nothing but engine load balancer balancer. Now again uh here we will define the specification for the service and here the first thing that I will be defining is nothing but load balancer. The type 13:26:17 of the service that is nothing but load balancer load balancer and enter. Now let me define the uh selector selector and here we will be targeting all the ports with the key as app and the value as engineix. And the next thing is nothing but the uh port. 13:26:44 So here uh I'll define the port. ports and inside the port I'll define the h I will provide the uh dash which we didn't provided earlier and here I'll define the target port target port and target port is nothing but again it so this port is for the service and this port is for the back end that we have created escape colon wq and now let me explain uh this to you one by one cat on load balancer okay now again api version v1 again I'm telling it and I'm repeating it again and again so that things are intact in your mind. So here we have defined the core API version. Then we defined the kind as the services which tells Kubernetes what sort of service we are creating. Then we defined the metadata and the name of this specific service. The name of the service is nothing called as u it is known as engineix load balancer. Then next we have the spec. This is the configuration for the kind service and inside that 13:27:46 specification we define the type as load balancer. Now what it does it tells Kubernetes that we want to create the service and this uh this service to be externally exposed to a load balancer is basically tells Kubernetes to create a service that should be externally exposed through a load balancer and Kubernetes environment should support it. Then we have something called selector which is the important part whenever you're dealing in networking in Kubernetes because this tells which port which ports we are targeting to and here we are selecting our engineix port which we created from the deployment file and finally here we have defined the ports that is port 80 and target port 80. So here the service ports listens on port number 80 which is nothing but this one. And secondly it forwards the traffic later to the target port and that is nothing but 80. When it forwards the target port by that specific statement I mean the back end ports that we have created. Uh notice something we didn't specified the note over here we are 13:28:48 letting Kubernetes and the environment to handle it uh by the external exposure. So now let us directly apply the change. So here there is one finding that I want to share because uh this is really interesting and this actually you should try and see yourself. So cubectl apply -f load balancer enter. Here it says engineix uh service/engine load balancer is created. All right. So cubectl get svc enter. It is svc enter. All right. So here the service name engine load balancer is actually created. So uh depending on where you are running Kubernetes the result will be different. So in a cloud environment uh with the load balancer integration uh you may see an external IP or a host name over here which we see pending over here. Even if I rerun it once again so see there is no problem over here. The pending that you are getting over here is expected. Now since 13:29:49 I'm running it in local in my Mac so I'm getting that pending. So the important part is Kubernetes is requesting external load balancing infrastructure for this specific service. Now uh there is uh one thing that I wanted to clarify that is uh if you create the type as load balancer it does not mean that every Kubernetes installation will automatically give you a public IP. Uh the behavior exactly depends upon the environment. For example, if it is a managed Kubernetes environment, Kubernetes can integrate with the cloud provider and it can provision a load balancer for you. So, conceptually, it will be like you will be accessing your application on the internet. The request will be sent to the cloud load balancer, then it will go to Kubernetes service and finally it will go to the pods. Right? So if you are running uh the uh if you're running this service locally on a Kubernetes cluster uh on your laptop just like me so there may not be any cloud load balancer associated and 13:30:50 that is the reason we are getting this pending over here right so I hope uh you are getting the reason you are getting the uh you are getting the answer why we are getting that pending over here and again this is a very common thing that you will see Now since it would have been a manage cloud environment we would have seen the host name of the IP. So yes now let us go to visual studio code and compare all the three manifest file that we have created which will help us in understanding all the three files all the three services in depth that we have created. So now let me switch to my visual studio code and here what I'll do I'll just open all the files side by side. So here goes my cluster IP. Here goes my load balancer. I'll open all the things side by side. So just allow me a moment. So cluster IP, load balancer and note port. 13:32:04 All right. And I'll delete it from here. So now I think everything is visible for you. Okay. So now uh just focus over here. So uh I'm keeping all the services side by side because I want you all to focus on nothing but the line number four here here and here. What exactly is the thing that I wanted to tell? So here uh in the first one you can see for cluster IP everything remains the same. All the three manifest file the one thing that is common is the structure. Second is the selector because all the three services are targeting the same enginex pod right and in the target port you can also see the target port as 80 because engineix listens on port number 80 right the main difference is how services are export. Now in the first one if you see the cluster IP gives us the internal access and second is in the node port it give us the access at node level and third 13:33:06 you can see in the load balancer which is in the mid you can see the load balances are for the external load balancing integration right so now let us understand the three parts uh clearly so before we move on I want to spend some time because uh on ports because uh this is where a lot of confusion might happen. So let's take the note port configuration over here. So here I will be focusing on this specific section. So put your focus over here now. So here what I want to say is we have three different terms. First we have the port. Now this is nothing but the service port the line number 10. Then on line number 11 you have target port which is uh nothing but your the port of your back end the port that is running. And the third is nothing but the node port. this port is exposed to the node. So if I requ So if I received a request on the node IP colon the port number of the node that is 300080 uh the service can receive the traffic 13:34:07 and it can send it toward the backend ports to the target node. I hope that made sense. So the traffic will initially receive to the node port then it will forward the traffic to the target port and the port. That's it. So now uh let's make the ports different. So it becomes uh even clear and imagining our application will be very much easy right. So here our service could be listening on port number 80 and the target port could be 88. So let me just change it for now. So let me just mark it as 8080. Now when I will give you the example it will eventually make sense because here we are using different number right. So here based on the uh references that we are using here the node port is uh running on port number 300080. The service is running on port number 80 which I defined on line number 10. And the third is the pod the pod runs on port number 80. So whenever the client is requesting on the node port colon 300080 the ser the request will go to 13:35:07 the node and it will uh forward it to the service. The service runs on port number 80 that is the line number 10. Then finally the service will forward the traffic to the eligible ports which runs on port number 80 which we have defined on the target port that is line number 11. Now that's uh now I think you have a complete understanding and the difference between port target port and the note port. That's why you should never assume that these three values should be the same or this should value should be identical. Now next is does not mean uh that the pod must be on that same node. So this is another uh question that we might come across with. Suppose let's say I have three nodes and my pods are running on node number two and node number three. But a client connects on the first node with the pod number with the uh port 300080. So does that mean that uh there must be an engine port on node one? So the answer is straight away 13:36:09 no. The note port is an entry point for a node right. So the service what it will do it will navigate the traffic to the appropriate backend ports and according to the service and cluster behavior it will just find the eligible port and it will uh route the traffic. So the part doesn't have to be running on the same node where the request has been received. Right? So now there is one more question that you might have that why not expose everything when we are dealing load balancer. Now in the first place why did load balancer came into the picture? It came into the picture because we wanted to access the application outside the internet outside from the cluster. That is the reason we made use of load balancer. So now let us take an example that uh let us say that you have three components front end, back end and database. So uh the front end needs to be accessed by the user that is you and me. Second is we have the back end and this needs to be accessed by the front end service. And third we have the database. This needs to be accessed by the back end. That's it. So, uh for this specific case, will 13:37:10 I expose the entire services? No. Basically, it won't make any sense. This will be unnecessary exposing the internal components and basically this will be a threat to the security too. So, basically a much more sensible setup would be since uh the front end is been accessed by all the people in the internet, we would be making use of load balancer. And here since the back end and database want to do the internal connectivity we will make use of cluster IP. So the external users can reach out the front end. The front end can communicate with the back end internally. The back end can communicate with the database internally. And this is a very important production principle that expose only the things that need external access. Do not make internal service public just because Kubernetes give you that option. Right? I hope this made sense. Now in order to uh strengthen this uh fundamental I will give you another example. Now let's say you are uh you are shopping on Amazon 13:38:11 and you are typing https colon amazon.com you are in this website. So you made this request and what will happen then once this request is been accessed from the internet it will go to external load balancer. From this external load balancer it will go to the front- end service. From the front end service, this request will go to backend service. From backend service, this will go to eligible backend ports and from the back end port, it will go to the database service and from the database service, it will go to the eligible database ports. So what will happen? The front end may explicitly be exposed but the back end can simply use the backend service and the database can use the database service. So internally what is happening uh the internal components that is back end and the database uh they are actually using the internal service. This is where the understanding for services becomes very much useful because we are not just memorizing cluster IP, node port or load balancer. We are choosing the right exposure based on the requirement. Right? So now comes 13:39:13 the part how do I know when should I select cluster IP? When should I select note? When should I select the uh load balancer? So I'll give you few examples that will help you to understand when we should consider cluster IP, node balancer and node port. Right? So let us discuss for the first one that is when should I use cluster IP. Let me switch to my MD file so that it would be easier for you to explain. One second and here is the MD file. And again uh like for reference uh material these things will be already pushed so that you don't have to worry where do I get the answer from. Right? Everything is documented over here. So you don't have to worry about that. And whatever things that we are performing like these manifest file, this will be again pushed to the GitHub repository. But one thing that I wanted to share you for certain that please please please write the manifest file by yourself. If you face the issue, try to debug it yourself and then even if after that you are not getting the answer that 13:40:14 you are looking for or the answer that is expected or desired, then refer the files. Now why I am saying this so because this will strengthen your knowledge and this will give you the confidence that usually people don't get right. So once you are good with the hands-on then things will eventually make sense and that is the actual reason why we are learning things together right. So now let me scroll down and here we are done with the comparison. We com uh we completed this. Now let me scroll down and here we saw the example. Now yes, we were discussing about when should we consider cluster IP. Okay. So uh let's make a decision very simple that we use cluster IP when the service only needs to be reachable inside the Kubernetes cluster. So the examples can be you may use backend API, you can use database, you can use internal microservices, it can be internal application components. So here what exactly happens? If you see that diagram over there, there is no reason to expose 13:41:15 the back end directly to the internet. If your application need the internal access right now, whenever you require internal access, whenever you need internal communication, the only thing that should hit in your mind is nothing but cluster IP. Now, moving forward and here we are discussing about nothing but note port. Now, when should we consider note port? So basically uh we can use node port when you need to expose the service through a port on a kubernetes node. So particularly it is mostly useful for learning for development for testing and for simple integration and mostly I have seen this sort of configuration into the dev and testing environment. So what will happen the client the users the testers the developers they will just enter the IP address followed by the uh port number and they will be able to access the service. So uh note port isn't usually the endpoint that the user want to interact directly. So that's the reason uh this is kept for internal testing 13:42:16 purpose because these are all people who will not judge judge us just for the IP address right and now let's come uh and talk about load balancer because this is the actual thing that will be seen by the people that will be seen by the public and that is uh where we are getting the business from. So we make use of load balancer when your kubernetes environment supports the external load balancer integrations such as the manage cloud environments and you want uh an external reachable services. So for example it will be just like someone reaching out from internet to access the services. This is useful for the application that need external access. But again remember one thing load balancer doesn't mean to make everything public. It means provide external load balancing integration for this service. Right? Now there is one more thing that I wanted to discuss is that is uh what is the different between node port and load balancing. Right? Because uh we did mention about node but what is the 13:43:18 difference between node port and load balancer. So let us compare the node with load balancer because it is probably one of the most uh important thing. Uh so yes with node port uh you are exposing the service through a port on kubernetes node and with load balancer you are asking kubernetes environment to provide an integration with load balancing mechanism. Right? The only difference over here is in load balancer it will be a managed one. You will be getting an external URL with node port you will be managing the access through a specific node I provided to you. In this current specific setup with mini cube, we did a access with mini cube URL and that actually helps right. So yes, I think that was all in this video and I want you all to go with the manifest file, the MD file that I have created. I also have added the troubleshooting steps. Yes, I also have added few interview questions which I want you to check. I just added I just have added oneliner answers but I want you to do the 13:44:20 describe do the descriptives answer for the same because again this will give you completely complete understanding of the service type of uh services that we have learned. In this video we did a deep dive into services. We covered three types of services that is node port cluster IP and load balancer. And yes before we close let me just do a summarize once again. So we have an application running inside the Kubernetes. So if you want to expose it how we would do it. The only thing that should come in our mind is nothing but cluster IP. Then again if you need a simple external access through a Kubernetes node then what we what you will be use will be using uh node port. Then third is if your environment provides an external load balancing capability uh that uh integration then the thing that should hit in your mind is nothing but load balancer. I hope uh this point made sense. And one final point I really want you to remember is don't think that load balancer is better 13:45:21 than node port and note port is better than cluster IP. That is really a very wrong way to think. Everything is created for a specific reason. So instead of uh comparing each of the services in Kubernetes just ask who need the access to the application right? If the answer is only applications inside the cubernetes then cluster IP is enough and if the answer is I need the access to a note then answer is noteboard and third is if I need the access uh if the people externally from the internet need the access to the service then your answer is nothing but load balancer. So once you start thinking about who is the person who will be consuming my services then choosing the correct service in Kubernetes will really help you out right. So I hope uh that was lot more of learning in today's video and don't worry all the manifest file I'll be pushing it right now right away. So let me just open my terminal uh get add 13:46:22 cluster IP deployment load balancer and node port. Okay. Get commit- m add cluster IP cluster ID node port and load balancer get push and changes should be reflected into a GitHub account. Let me just verify the same into the browser as well. And yes, let me just switch to my browser. So yes. All right. So the changes are pushed now and we are good. So yes, that was all in this video and I will see you in the next one. Until the next time, keep learning and thank you very much. All right. So we now understand what exactly service what is the difference between cluster IP node port and load balancer. We now understand that what 13:47:24 service is capable of like basically service helps us to provide a stable way to connect our ports right. But let's consider a situation where I am giving you a real application and uh now let's say we have an application where front end back end backend API products and payment gateway fees are involved. Now imagine all of these needs to be accessed from the internet. So one simple approach would be to create separate individual load balances for every application. So like at the end what I will be end up with I will be end up with like there will be separate uh load balancer for uh payment separate load balancer for front end separate load balancer for the back end API and separate load balancer for the payment gateway. And this will become difficult to manage. And also like for the HTTP application, I may want to do the routing based on things like let's say your website, let's say website.com. Let's say if I give my name, let's say 13:48:24 if I'm hosting my own website, let's say shubgod.com. If I want to navigate to the back end and I want it to navigate to api.shubgod.com shubgod.com or let's say if I want to pathbased routing like shubgod.com/roucts/play uh/payment. So this is where ingress comes into the picture because ingress helps us in defining the HTTP routes. Yeah. So ingress helps us with uh defining the HTTP and HTTPS routing. And basically what these are these are nothing but the rules that uh sends incoming requests to different Kubernetes services. So in this specific video uh this this is going to be a hands-on demonstration by the way. So here we are going to learn about what exactly is ingress and why do we need it? What is the difference between ingress controller and ingress? Why do we need both of them? Right? And we are going to uh install the ingress also the ingress controller from the scratch. And like we are going to see how ingress is very different from the services because 13:49:24 right now we have a clarity on services. We actually have performed the hands-on. So we know what exactly services are capable of. But we need to see what is the difference between ingress and services. We are going to discuss about the routing behavior. We are going to understand how do we configure the ingress and most importantly we are going to build everything from the scratch. So you don't need to worry here and there. Uh you just have to focus on one place, one screen and everything will be solved. Because here we won't be like jumping here and there referring multiple docs. We would be uh referring to a single screen and maximum we would be referring is the cubernetes docs because that's something that we are targeting to because we don't want to learn with the pre-created pre-mplated uh yaml here we write everything from the scratch. So on that note let's first understand uh what is the problem that we are facing with services. So let's start with a very simple problem that imagine I have two applications running in cubern uh kubernetes say that application consist of front end and 13:50:26 back end and both applications have their own pod. So both application will obviously will have their own services. Now imagine that a user is coming from the internet and we want a way uh that a user should not remember the IP address. he should go with the domain that we are providing right for example let's say let's take um my name throughout the video so that we'll get we'll get a complete context what we are referring to so instead of Amazon let's say you have created your own website your own product and you want the user to navigate to http shabbangod.com so this would be the website that we would be referring so uh like whenever the user goes to the address bars and type shabbangod.com uh they should be navigated to the front end page and let's say If I want them to go to the back end now, let's say if I type http.com/ API, so they should go to the back end. Now the question is where do we define this routing behavior, these routing logic. So uh this was one of the problem that has been solved by ingress. So now 13:51:26 let us discuss what exactly is ingress. Okay, let's discuss what exactly is ingress. So ingress is nothing but uh it is a Kubernetes API resource. I'll repeat again. Ingress is nothing but a Kubernetes API resource. Now we'll get a clarity on this when you will create the manifest for ingress. Uh so uh you can hold this thing for now and when we'll create the YAML at the time you'll get a clarity why we are referring the term API resource. Right. So yeah let's understand what is ingress. Ingress is nothing but uh it is a Kubernetes API resource that define the rules for the route for the routing of HTTP and HTTPS to the service. uh the important word here is basically it defines the rule. So ingress is a Kubernetes resource that defines the rules for uh the routing for HTTP and HTTPS traffic to the services. Right? So ingress will not uh run your application. Ingress will not uh run your front end. It will not run your back end. It will not uh run your uh 13:52:29 service to everything will be executed inside your pod. So your application still will run in the pod and the services will still provide the stable access to this pod. But here what exactly ingress does? So ingress sits in front of those service and defines how does the HTTP and HTTPS traffic should request and they should be routed. So if you want to see a simpler flow. So here you can see the request flow would be usually like the user he will be uh requesting the URL from the internet and that will go to the ingress controller and from the ingress controller it will go to the front end service then from the front end service it will go to the front end ports and the another request could be like let's say if you have a backend application then it will go to the from the internet it will go to ingress controller from the ingress controller it will go to backend service and from backend service it will go to backend ports. So uh the responsibility is split over here. So the pods will run the application. The service will provide the stable access to those pod. Ingress will define the HTTP and HTTPS 13:53:31 routing rules uh to the service and the ingress controller uh will be the component that will actually implement those rules. So before even we move forward with that let us first understand like uh ingress is not basically a load balancer. Both are different. So this is the important distinction that we should uh discuss about because ingress is a Kubernetes API object. So creating an ingress object doesn't automatically mean that Kubernetes has created a working HTTP server somewhere. We need something that can actually implement this uh routing rules this ingress rules and that's something what we call as ingress controller. So basically here in this video there are two concept that we would be targeting to first is the ingress and second is the ingress controller. So what ingress is capable of? So ingress is uh something that contains the rule. Uh when I say rule it contains the routing rule and ingress controller watches those rule and actually helps in in handling those 13:54:31 traffic. This uh distinctions this difference should be very much clear when we are working with ingress. So there are two components that are involved here ingress and ingress controller. So if I create an ingress resource but I don't have appropriate controller running. So the resource can exist but nothing will actually process. So what will happen in this case? Basically like the service will be existing but when it comes to implementation nothing would work right. So let us first understand the difference between ingress and ingress controller. Right? So now we already are aware uh that ingress and ingress controller both are different entities but they both work together. So suppose I create a manifest name ingress.yamel that YAML is basically saying that here is the HTTP routing rules but someone has actually but someone has to actually read those rules and they have to process those incoming requests and that is nothing but the job of ingress controller. So think of it like ingress defines the routing rules and ingress 13:55:32 controller actually uh helps in uh implementing the HTTP and HTTPS trafficing rule. So and again after uh they handle the traffic it will go to services and from your services it will go to pod. So without an appropriate ingress controller and ingress resource may exist but it is of no use. Uh it will be just an existing entity for you. So both are required when you want to work with ingress. So now I think you will have a great clarity on what exactly is ingress and why ingress controller is equally important. So now before even we start with the uh ingress and all uh let's make two simple application. So in this specific demonstration entirely I will be making use of engineix because engineix is very easy to understand the ingress and it will help us to visualize to what exactly we are up to. So here what we are going to do we are going to create two engineix deployment and one will represent our front- end application 13:56:33 another will represent our back end application. We could use real application over here but engineix makes the networking easier to see and because we are doing this for the very first time. So we are going to build every pieces our own self. We won't be uh using any sort of template that is already present somewhere. We would be creating everything from the scratch. And yes, as discussed earlier also, we would be looking into each and every line of the manifest file so that we will actually know what exactly we are dealing with. And also I'm going to uh make use of mini cube over here for this practical demonstration because I want you to actually open your browser and see the application live uh by entering the host name into your browser. So that is something that we are planning. So let me just jump directly to my terminal and I hope it is visible to you. All right. So right now my mini cube is up and running. Let me just Yeah. All right. So let me just clear the screen. And the first thing that we would be doing over here is let us create the front end deployment file. Right. So 13:57:35 whim front end deployment doyamel. Enter. All right. Now again comes the same question. What are the four keywords uh whenever we are dealing with any sort of manifest file in Kubernetes. So yeah that is nothing but API version kind metadata inspect right. So I'll define the same API version API version kind metadata and spec escape colon wq. Now where will I get the value for API version kind. So basically here we can get the detail from API resources and also there is another alternative that is nothing but cubernetes documentation but again I will be referring uh and I will be sticking to the command line. So I will be making use of cubectl get API - resources enter I need to remove get from here. 13:58:35 All right cubectl API resources and here we are searching for deployment. So deploy and here it will be nothing but app/v1. Let me copy this and I'll edit my uh deployment file once again. So I'll just do a vim on front end deployment. And now after going to insert mode I'll define the kind. So here the kind is nothing but deployment deployment. And here let me define the metadata. Now what should I call this specific deployment that we are creating. Now again we are creating two sort of deployment file. One is for front- end application and other is for back end. So let me just give a very straightforward name for this deployment. I will just call it as front end. And now here comes the specification the configuration. So yeah whenever we are dealing with deployment we need to define the replicas because that is something replica set will take care of. So replicas and now since here we are dealing with two services for two application uh I'll just take two replicas for now again like it depends upon you whether how 13:59:35 much replicas you actually want to take right so now let's create the selector selector and inside selector we would be defining the labels so match labels so here we are telling that which are the labels that we are actually targeting now since this is front- end application I'll just add a front end uh uh label over here. And now it's time to define the template. So now this will fall under replicas at the level of replicas. So yeah, template and let me just correct it. Okay, hopefully yes, now it's correct. So inside the template basically here we are defining the template for the parts. But before even that we need to define the metadata for that part. And here I'll be defining the labels that will be intact with those pod when it is actually created. So labels and again the label would be app colon front end front end enter. And now here we would 14:00:37 be defining the specification for the pods. So here spec and in the spec we are defining the specification for creating the container. to containers and here I will define the name of the container the image of the container. So here the name of the container will be nothing but front end and the image that it should use for creating the container is nothing but engineix. Uh also you can define the tag as per your need but I will be using engineix latest. And now the last thing that I would be defining over here is nothing but ports and the port that I will be using over here is nothing but the container port. So container port and the container port for EngineX is nothing but port number 80. Escape col WQ. Let me just clear the screen and here I'll explain you everything line by line. So front end deployment. All right. So now uh let's understand each and every line importantly because this is something that is the foundation of our understanding right. So here the 14:01:38 first thing is API version. What exactly API version is? Here we are telling Kubernetes that we are creating uh a deployment uh which is using app/v1 API version for the deployment. Then second what we are telling we are telling Kubernetes that the resource type that we are creating is nothing but a deployment. Next here in the metadata section we are defining the name of the service that we are creating. So here we are uh we are naming the deployment as front end. Then under specification these are nothing but the configuration for that deployment. Right. So basically here we are defining what are the different settings uh that we want for the deployment that is something that we have created. Now here comes the main part for deployment and I think nothing and that is nothing but replicas. So here in the replicas we are seeing that we want two front end ports and then here we have defined the selector match labels and then we have defined app colon front end. So the deployment will manage the pod with the label where it says app is equals to front end. Then we define the port 14:02:38 template which is defined over here. So here uh we are defined the defining the port template. This gives every front end pawn the label as abs app equals to front end. And then here we have the specification. Now this specification is again for that uh container for that pod that we are defining. So we are defining the container inside the pod. Then again for that uh we are naming that container as front end. The image that should be utilized for creating that port should be engineix and the port that the container should use is nothing but port number 80. Now here engineix use port number 80. That's why we have mentioned the container port as 80. Now let us apply the changes and see the changes in action. So cubectl let me clear the screen first. So cubectl apply - f frontend deployment. Mameml enter. And here it says deployment.apps front end is created. So cubectl get deploy and here you can see front end deployment is created. Now let me 14:03:40 verify the ports too. So cubeectl get ports and here you can see two front end ports are up and running. Now likewise similarly we are going to create another manifest file for back end too. So let me just copy the existing one because that would be easier. So CP front end deployment and here I'll create another one that is backend deployment doyamel enter ll and here you can see the back end deployment file is created for us. Now when I do a vim here we would be only doing few cosmetic changes. So in the metadata name instead of front end I will mark it as back end back end. And here if I go down the second thing here is in the uh label section I'll again change this to back end. And the third change would be in the template itself back end and in the containers let me rename this to back end. All right so the changes that we did over here is 14:04:40 what with the metadata of the deployment. So here the deployment name will be nothing but back end. Second change that we did is with the selectors label. So here we are targeting those pods where the label value would be app equals to back end. Then third in the template we have changed the value for the uh labels for which the pod will be created. So here we have replaced the value from front end to back end for this specific one. And also the container name earlier it was front end. We changed that to back end. So there are no changes over here. except the name of the containers and the labels that we are utilizing along with the deployment name. That's it. Now let me just do escape wq and let us apply this file to. So cubectl apply -f backend deployment.l and here it says deployment.s back end is created. Now again we will verify whether the resources are created or not. So cubectl get deploy for deployment and when I 14:05:41 press enter here it says that the backend deployment is created and now let me verify the ports too. So cubectl get ports and here you can see two ports for backends are created. Now the base thing is ready basically like we wanted two front end ports to be running and we wanted two back end ports that should run with the labels app equals to front end and app equals to back end. So both things are ready. Now in order to learn ingress the initial thing that you need is a deployment and then we will need one service that will route the traffic uh that will make sure that the uh traffic has been splitted perfectly or not. Right? So now let us create the uh front-end service. Now remember something important ingress does not normally send traffic directly to the ports. It routes the traffic from service. So it needs a medium and that medium is nothing but service. So let's create our front-end service first. So whim front end service doyamel enter. And now again whenever we are dealing with any sort of 14:06:41 manifest file in kubernetes remember those four golden keywords API version kind metadata inspect. Let us write the same. So API version kind metadata and spec escape colon wq. And now let us find the value for API version and kind. So cubectl API resources and we'll do a grap on service svc enter and here the API version is v1 and the kind is nothing but service with scaps. So yes let me go back again so front end service.l and here I'll update the value for API version as v1 and the kind will be nothing but service. Right now here comes the next part that is the metadata. So what would be the name of the front- end service? So we'll give a generic name. Now since this service is dedicated and specifically for front- end deployment, we will name this as 14:07:43 front- end service. So name equals to front end front end service. Okay. Now again here comes the specification the configuration for these services. Now again if you remember when we were learning services for the very first time I emphasized more on labels and selector because that is how services will know which target uh which port to target to right. So here we will define the selector. So selector and here in this selector I'll define the labels and for front- end service the label would be nothing but front end right and the next thing is nothing but the port. So here I'll define the ports. Enter. And now here I'll define the ports for this one. So port here would be engineext runs on port number 80. And secondly we are defining the target port. So target port and target port is nothing but 80 again. So escape colon wq. And now let me 14:08:43 explain you each and everything once again line by line. So let me just yeah once again clearing the screen. And now yep now I think it is visible for you. I think I made a mistake over here. So let me just do a vim on front end service. So front end service.ml this is not vi this is v1 insert mode. This is v1 escape colon wq clearing the screen and now hopefully it should be visible to you. All right so let me explain you each and everything line by line once again. So here the first thing that we have is nothing but API version. So here uh we are telling that services are using the core kubernetes API. Then we have the kind. So here we are telling Kubernetes that uh we are creating a resource uh for the kind as service. So Kubernetes will be well aware that the service that we are trying to create from this manifest file is nothing but services. And then we have the metadata for the service. So basically what will you call this service after creation? So 14:09:44 the name that we have given for this service is nothing but front end service. Then we have the selector in the specification. Now what is specification? This specification defines the configurations, the settings that we should uh that we want to get out of this service. So here we are defining the specification and under specification the major thing that plays a great role over here is nothing but selector. This tells service uh send the traffic to the pods where the labels are matching to app equals to front end. So it will just monitor all the ports and wherever he finds that okay this port contains the label where the key is equals to app and the value is equals to front end and it will actually route the traffic. Then we are talking about ports. So here we have three ports over here. So basically here we are defining the port. The first one that defines is port col. It is nothing but the service port and second port that we have is nothing but target port that is the port of the front end port. Right. So now let us apply the change and see things in 14:10:44 action. So cubectl apply - f front end service.l and here it says service/frontendy services created. Clearing the screen listing the service. So cubectl get svc for services. And here you can see front- end services up and running. And again uh there is one more thing that you have to uh notice over here. Since I didn't mention the type of service it created cluster I by default. Now if you remember in the previous video specifically we learned that the default service for any sort of service that we create in Kubernetes. The default value for it is nothing but cluster IP. Right? We learned about cluster IP, note port and load balancer. Load balancer. If you want to get a clarity, I would highly recommend you to go to the previous video, get understanding, get the foundation correct and then you will come to this video right because understanding services in depth is very much mandate in order to do good work in order to understand ingress uh properly. 14:11:46 Right? So here we have created the front- end service and now let us create the same for the backend service. Again there won't be any difference over here. uh what I will do I'll again do a list and I will copy the front end service and I'll do the similar thing that we did with the back end uh with the back end deployment. So cp front end service and here I will mark this as back end. So this will be our backend service. Mamel. Now when I do a vim on backend service.ml the first thing that I need to change and I think the only thing that I need to change is the name of the service. So here instead of front I'll just mark it as back end service. And here I will tell u uh the service file to target only those uh pods where the label is app back end. So I'll again go to insert mode and this will go as back end. Escape escape colon wq enter. And now let me clear the screen. I'll do a cat on back end just 14:12:48 to validate all the things are proper or not. Okay. Now again if we break it down we have API version we have kind where we are telling that we are trying to create a service in the metadata we are defining that okay we want a backend service that should be created and the name of that service should be backend service. Here in the uh configuration in the settings we are telling that for the service we want to target only those application those pods where the key value pair is app and the value for that uh key is nothing but back end then we have defined the port. The first port defines uh that it is the service port. The second port defines the application port. Now let me just clear the screen and here I'll apply the file. So cubectl apply -f backend service. Mamel. And by doing so we have created the backend service to let me just run a cube cuttle get svc to list the services that we have created. And here you can see again the type of this service is nothing but cluster IP which we have already uh discussed earlier. So now we have the 14:13:51 front end service we have the back end service both are cluster IP services because we didn't specify the service type meaning uh they are internal services by default right so here we have these thing ready and now let me just list the deployments too. So cube scuttle get deploy and enter and cubectl get pods. All right. So we have all the things in place. So currently our architecture is like we have front end port, we have front end service, we have back end port, we have backend service. Now what if uh the user on the internet want to access both? We could expose the board with the help of load balancer. So these services we can expose with the help of load balancer which is again a type that we have seen in the previous video. But that will again look like we have a load balancer dedicated to front- end service. Then we will have a load balancer dedicated to the back end service. But now here we are creating multiple external entry points. For example, for an HTTP application, we 14:14:52 often want one entry point that can route the request based on the host name or URL part. Let's take the example. Let's take my name. Let's say it's my website shubongod.com. So whenever someone enters that URL into the address bar, the front end screen should be visible. And whenever someone enters shubgod.com/appi into the URL bar, they should be getting the backend service listed over there. So this is where ingress becomes very much useful and that's the reason why we are considering ingress in the very first place. Right? Before we create the ingress resource, this is one important piece uh that uh we need to think about. And again uh before even we begin with ingress, there is one more thing. There is one more component that is actually missing over here. And yes, that is nothing but ingress controller. Now if you have been hearing it uh with focus completely you might already have the clarity what ingress controller plays an important role over here. We will have ingress. We will have ingress controller. So ingress controller is the 14:15:54 main person who is doing the routing and all right in ingress we are defining the rules that we actually want right. So now we are going to install actual ingress controller for this demonstration I am going to make use of a community ingress controller and one thing I want to make clear over here ingress itself is not the same thing as kubernetes ingress resource. So for this uh we are going to make use of helm. So what exactly is helm? Hang is nothing but a package manager. So we are going to use helm for the installation. And before uh even we start with the installation, let us first verify whether you have helm installed or not. So for me uh in order to verify in in order to verify the same what I will do, I'll just run helm version. And for me I think it is already been installed. So for someone who want to install helm. So what I will recommend you to do is go to the web browser and search for helm installed. And here on the screen you might be seeing like this is the actual page where you will find the actual instruction for installing helm right I 14:16:54 am on my Mac OS system and on top of it I'm running docker and inside docker we have a mini cube cluster there we are doing this operation for you the setup might be different you might be doing it on kind you might be doing it on cubeddm right but again in order to understand this you will need helm for sure because helm is something that will help us in installing ingress controller right now again uh coming back if it's installed you'll get the version information like this. Uh we are also going to make sure that the cubernetes cluster is reachable. So how do we verify that? So for that just run cubectl cluster - info. Enter. And here you can see the cluster kubernetes control plane is running. Here you can see the core DNS is also running. That is something that we actually wanted to confirm. Now the next thing is let us list down the nodes into these cubernetes cluster. So cube cuttle cube ctl get nodes. So how many nodes do we have? So basically here since we are using mini cube we are having a single 14:17:56 node present over here. Earlier for demon sets we have created multiple nodes but now since uh we are going to understand we are focusing on ingress we have we are working on a single node cluster right but again if you have multiple nodes that's not an issue you can perform the operations over here. Now uh so that's it. Let's actually start with installation of Helm over here. So if you go to the documentation uh I'll switch to Visual Studio Code. Here I have provided the command for installation of Helm and also the manifest file that we are using is also present over here. So feel free to check out the documentation. This has already been pushed to the GitHub repository and link is already present in the description. So yeah, feel free to check out the same into the resourc resources section. So let me just scroll down and here yeah this is the command that we are looking for here we are making use of hel uh I'll explain you all the command I'll break it down everything for you so that things are easier for you to understand meantime I have just 14:18:57 executed the command and here what exactly it is doing it is installing ingress controller for us so meantime it is executing the command let us understand what exactly it is doing okay so it actually installed it but again let me just tell you what exactly has happened so if I go upwards here. What exactly we are doing? Just focus on this command. So what we are doing over here is we are uh upgrading we are telling Helm to install something. So basically the command that we are using is helm upgrade- install. This tells that uh if this release doesn't exist, install it. If it is already existing, then upgrade it. Right? That's the meaning of that line. Then we have defined the resource that we want to install that is ingress engineix. So this is the chart that we are actually trying to install. Third is we have defined the repo URL tells Helm where to get the chart from. Then we have defined the name space which you can see and the name space that we want uh to create for this uh ingress 14:19:57 controller is ingress engineext. So we are installing the controller into the ingress engineext nameace. And then finally we are asking him to create a namespace meaning to create the nameace if it doesn't exist and wait for him to complete before moving forward. So let us see what got created. So since we have created a new nameace let us verify whether it created the nameace or not because that is the place where ingress resources will be present. So cubectl let me clear the screen first. So cubectl get namespace and here you can see ingress engineix the namespace is created for us. Second thing that we need to do is let us list down all the resources which are created inside this uh name space. So cubectl get all in the name space in the name space engine ingress ingress engine. All right. So here there are three resources that it created. 14:20:58 Right. Let me just scroll down. Yep. So here you can see it list down all the resources that it has created. First thing it says that the engineext ingress controller the first thing that we wanted is already present. Second is it created the services that is engineix uh ingress controller and second is engine ingress controller admission which is of type load balancer. Third it created an engineix ingress controller deployment and finally it created the replica set by the name engineix ingress controller clear clearing the screen. So this is exactly what we wanted and this is exactly what we get by running the helm command. Again I want you to refer the documentation which is present into the readme.md because that will actually give you the complete idea what exactly we are dealing with and what exactly that command is actually doing right and post creation post execution of that command verify whether you get the name space whether uh verify whether you are getting the pods verify whether you are 14:21:58 getting the deployments and verify whether you are getting the service or not but again if you do not wish to uh list it uh individually you can just run cube cuttle get all hyphen n followed by the engine uh ingress - engineix the name space that is created but again it is a good practice to check each and every component individually because that is actually will give you a complete idea what exactly things are been installed now let us go back to the terminal and yes we are back over here so this service is particularly important now let me just list the service so cubectl get service in the name space ingress engineext. So yes here we here you can see we have two services present over here that is uh ingress engineext controller and second is ingress engineext controller admission. So this is particularly very important because in our mini cube setup the controller uh service is nothing but a load balancer service. The important thing here is that load balancer service 14:23:01 in a mini cube cluster doesn't automatically mean that we have a real cloud load balancer. I'll repeat it once again. Load balances service in local mini cube cluster doesn't mean that automatically we have a real cloud load balancer. So we'll deal we'll deal with that in few minutes when we are going to work with mini cube tunnel. Now what is mini cube tunnel? Again it is a utility by mini cube that will help us to do this demonstration which is an important segment of this video. Right now understand uh what exactly we created. Before moving forward let us take a pause and understand what all things we have created. We created the front-end parts. We have created the deployments. We have created the services and now we have added the ingress controller. So conceptually the architecture is like we have ingress, we have ingress controller, we have services, we have deployments and we have the ports. So uh we are still missing something that uh is something that we call ingress and ingress what it is responsible for it is responsible for defining the rules 14:24:03 because we have the controller handy right now. So we have everything in place. We have told that the ingress controller routes the request and that's where ingress resource will come into the picture. Ingress resource will contain the rule and ingress controller will implement those rule. So let us check uh the ingress class before even we define the ingress rules. So before creating the ingress let us check the available ingress class. Now this is actually needed. This is one of the value that we will be needing when we are defining the ingress rule. So in order to get the ingress class just type cube cuttle get ingress class enter. And here you can see the class name is nothing but engineix right and this is the class name that we have to verify. Uh don't blindly copy the value because it changes for every cubernetes cluster. The better way to do is just check cube cuttle get ingress and use the class that it belongs to because here we are going to tell the 14:25:03 controller that this is the class that we are referring to. Right? This is important because ingress class tells the kubernetes which controller should handle the ingress. Right now uh let's get started because eventually the significance of ingress class will be defined inside the ingress file that we are going to create. So let us create our first ingress file. So whim ingress doyamel. Now again ingress again is nothing but a manifest file. So what are the four key components that we need to keep in mind whenever we are dealing with any sort of manifest file in Kubernetes? API version, kind, metadata and spec. I'll define the same over here. Here the things will be slightly different from all sort of resources and the works that we have created so far. So please pay a close attention over here. So API version kind metadata and spec. Now again where do I get the 14:26:03 value from? So clearing the screen again I will run cubectl and I will run API resources resources resources and I'll do a grip on ingress enter and here you can see the API version is slightly different now here comes the main part because uh that is something that I was emphasizing a lot from the starting of the video itself you uh ingress is nothing but a networking object right so that's the reason I was using that statement. So let me just go back to ingress.l and here I will update the API version to networking.katest.io/v1. Right? Second is the kind. Now here it will tell cubernetes what sort of resource we are trying to create. Here we are trying to create ingress. Now again in the metadata like here we'll uh type the name of the ingress. So since here we are dealing with front end and back end. But what exactly is front end and back end? It is nothing but an application. So application. So here the 14:27:04 name of this ingress will be application application - ingress. All right. Now again what are the settings for this specific application ingress. So here uh if you remember earlier we ran one command cube cuttle get ingress class. So that ingress class name will actually come into handy. So here in the specification the first thing that is expected from us is ingress class. So ingress ingress class class name. So this is the class name that I was saying you to check every time and here in our case it is nothing but engineext. Let us verify the same escape colq and here if I run cubectl get ingress class and here you can see the ingress class name is nothing but engineix. This is exactly what we have picking up from there. So now let me go back to my manifest file and here we have defined the ingress class name in this specification. The next thing that we need to define over here is nothing but rules because that is the actual 14:28:06 crux that is the actual thing that we want ingress to target to. So here the next thing that we would be defining is nothing but rules. So rules. Now here uh there are two sort of rules that we would be talking about but for now just focus on the hostbased rule. So here uh we will define the rules for what we we want a rule such as that whenever the user comes to my website it should be navigated to the services and eventually to my pod. So here uh you can just write the name of the host that we are talking about. Now again uh feel free to experiment over here. I will be using my own name here. You can make use of your name or you can even make use of any domain name that you want. For now I will write shamgore.com. This will be the host that I will be referring to. But again feel free to check out it with your own name. Feel free to check out with any do name because that is actually we are going to uh focus over here because here we are interested in uh knowing ingress in depth and yeah that's the experiment 14:29:07 that you can do. Now here we want to define the rule for the HTTP. So again like I'll explain you each and everything line by line. So here let me define the HTTP rule and here in the HTTP rule we would be defining the rule for the path. So here inside just HTT HTTP I'll define the path and inside path I will define the path and here it will be at root level and here I will define the path type inside the path. So here it will be path type and part type would be nothing but prefix. These value you will get from the documentation. I will again show it into the screen. Now here is the place where you can see the actual documentation listed for the path type. Right? So here I'll write prefix. Now the next thing is we will define the backend service that it should target to. So whenever the users hits on slash this is the place where it should it will be uh navigating the traffic to. So 14:30:07 back end and here we will define the service name. So in the back end we will define the service service service and inside the service we will have something called the service name and the service that we are talking about over here is nothing but front end service. Let me just verify the name of the service. So cube cl get svc and okay and here the name of the service is nothing but front end service. Let me go back to ingress again and here yes we have written this service name correct. I'll go to the insert mode once again and the last thing that we would be defining inside the service is the port number where it would be running. So port and the port number uh for that specific service. Now here uh engineix runs on port number 80. So here I'll write the port number uh so basically here the port number is nothing but uh 80. So number is nothing but 80. Escape colon wq. Let me clear 14:31:07 the screen and let me just run a cat on English. ML it's a big but yeah let's understand each and everything because this will give us a clarity what we are dealing with. Let's go with the first line API version. So ingress belongs to Kubernetes networking API. This is the line that I have been I have actually started this conversation from. So here exactly it is coming from. Now where do you get this value from? We get this value from API resources. You need to run a grab and then you will be able to find the value of API version. Second that we have is the kind. So here we are telling Kubernetes that we are creating an ingress resource. Third we have defined the metadata and in the metadata we are giving or ingress the name as application ingress. Now inside uh this uh manifest you will find one spec. This spec defines the specification the configuration for the resource type ingress that we are going to create. The first thing that we have defined over here is ingress class name. This tells 14:32:09 Kubernetes which ingress class should it handle. Right? And here we are saying that use the ingress controller associated with the engineix ingress class. And again uh the exact class name depends upon the controller which is installed in your cluster. Now here we have defined the rule and here comes the main part which is very important. So this is where we defined our routing rules. So then the first thing that we have defined is nothing but the host. So here we are saying that when an incoming HTTP request uses the host shubot.com apply the below rules and then here we have defined HTTP colon. So here we are defining the HTTP routing and then apart from that here we have defined the path right. So here we are defining uh the path. This allows us to define the routing based on the URL path. Then the first thing that we have defined is path colon/forward slash. So here we are matching the requests that are starting from slash and then here we have defined the path type prefix. So what exactly it 14:33:11 means? It means that the path is treated as a prefix. So uh that it can matches path such as / products/ payment slash front end slash literally anything. Then we have defined back end. Now what exactly back end states over here this defining where matching traffic should go and then here we have defined the backing the uh backend traffic should actually go to a service. Here we saying that the back end destination is nothing but a kubernated service and then we have defined the name of the service where it should actually go. So the request should go to the service named front- end service and then finally we have defined the port number over here. Right? So we are sending the request to port number 80 on that service. So it's in plain English. Let me put everything into simple plain word. So uh it is just like if an HTTP request comes to the host called shubango.com and if it goes to the uh path that is / route the traffic to front- end service on the port number 80 14:34:12 that is the entire crux of this ingress file that we have created. So now let us apply the ingress file. So cubectl apply f ingress.ml enter and here we are getting an error. So let us validate the same. So here what it says error from server it says a bad request error when creating ingress.l ingress in version v1 cannot be handled as ingress. Okay and then uh unmarial object there is an issue with the structure. So http ingress rule values spec rules dot ingress value http path type v p1 ingress path. So there is an issue with the yl file itself. Let me run the cat to ingress.yamel and let us validate what exactly it is trying to say. So here it says http ingress rule value. Okay spec dot rules. So here spec dot rules here it says ingress value 14:35:15 http path. Okay. So there is an issue somewhere near the path that is exactly it is trying to say. So inside rule we have defined the host and just be we have just below the host we have defined the http inside that we have defined the paths. Okay I think the issue is again with a dash. Now again here we face the issue and here it says that cannot u unmarshall object into the structure and here it defined the uh rule path like where exactly is the issue here inside rules inside host we have defined the path but again that path is missing something that is something that we are going to correct now so ingress yl here I will just need to add one dash insert mode and here I will add one dash over here insert mode and I will add one hyphen and parallelly I'll just put everything as per the uh indentation one space for 14:36:17 everything and I think paths will fall under here so I will just put everything under here this back end will go okay correcting the indentation and yes basically like if you are into VS code then uh the uh studio editor already have highlighted this issue so I think there the things will be correct let Let me apply the file once again. And here it says there is an issue with uh decoding error. Again it says an unknown field spec. rules uh running a cat on ingress. Okay. Now let's see where the issue is. Now we have defined the paths and inside that we have provided one dash. The roots has been provided. Part type prefix backend also provided. And then we have defined the services. Inside service there is a service name. Uh there is a port and okay again indentation issue with ingress file. This port number will fall inside port. So insert mode escape colon wq enter. 14:37:17 Clearing the screen and applying it once again. So cube scuttle apply - f ingress. Mamel. And now finally after so much of trouble the ingress file is created. So basically we have done two mistakes over here. First is we didn't added hyphen and second is there was an spacing issue in the port number. That is exactly what we fixed right now. So now after applying all the changes let us check the ingress. So let us type cubectl get ingress enter. And here you can see application ingress is created. And we can also inspect this ingress by running the descript command. So cubectl describe the ingress by the name nothing but application ingress enter and here you can see application uh ingress is described and here you can see the name space since we didn't define any name space it is taking the default one the ingress class name is nothing but engineext that is the information that we are getting second is the host second is the path and the 14:38:18 service that has been utilized along with the port number that is actually we are seeing over here and also So there is one more thing that we can see here is the pod IP address along with the port is also mentioned over here and lastly the events you can see the ingress controller is scheduled for the sync meaning things are ready for us this is useful because it shows us the configured rules and the back end and at this point ingress resource exist but don't try to open the URL that is this host name uh yeah do not try to open this on browser yet because there is one more important piece our local computer needs to know where this URL shubot.com should go right if you open it right now you won't get any result right so uh let us understand the complete uh complete request flow so here what will happen is whenever a user sends a request to http shubgod.com the request will first need 14:39:20 to reach to the ingress controller which we defined Then the ingress controller will look for the ingress rule. Uh it will look to the request. What it sees? It will see okay the host name is shubhangod.com. The path that we are trying to uh view is slash. Then it checks the ingress rule and check whether there are any rules present for it. And one rule says that shubangot shubangod.com plus/ should navigate to the front-end service. And here I am talking about this one. And once uh it figures out that okay someone is trying to visit shbangot.com/ then here what it will do it will navigate the traffic to the front- end service then the service will find the front- end ports but on what basis it will find the ports based on the labels that we have defined and that's the reason labels and selector plays a huge important role over here and then what will happen what will actually happen we will be able to see the application so from the browser there will be an HTTP request that will be reached to the 14:40:21 ingress controller. The ingress controller will match the host and path and based on the rule that is defined by ingress itself, it will forward that uh request to the front end service. That front end service will forward that uh request to the pod and finally we would be able to see the application. This is the entire idea behind ingress. But there is important thing over here. the browser still needs to know way to reach the ingress controller and that is where uh mini cube tunnel will come into the picture. So now there is one thing we need to understand before we start testing. Uh creating ingress doesn't magically uh make u chamom.com visible into the cluster. There are two separate problems that we need to look out. So let me just switch to my visual studio code and let me just tell you what exactly we are referring to. So here let me scroll all the way to the bottom and here two uh separate problems that we are trying to uh discuss over here. Problem number one is how do we reach 14:41:23 the ingress controller and problem problem number two is how does the uh how does will it do the routing of the request right so ingress rule basically solves this second problem. The first problem depends on how the ingress controller is exposed. Uh so in a cloud uh environment we have something called a load balancer service that will uh so in a cloud environment we have something called load balancer service that may receive an external load balancer but uh when it comes to local mini cube environment we don't have a cloud load balancer that is why we are going to make use of mini cube tunnel. So this tunnel gives our local load balancer uh way through which the service will be reachable and the distinction uh and basically uh we would be able to reach out uh to the service with the help of browser. So now uh once the uh service is exposed we would be exploding the mini cube tunnel. So let us check how our ingress controller is exposed. So let me just go back to terminal once 14:42:24 again. And now yeah let me what I'll do let me just clear the screen let me clear the screen and I'll run cubectl get service in the name space uh ingress engine x ingress enter it is svc enter okay so here we have two services present that is ingress engineext controller and ingress engineext controller admission ingress engineext controller is of type load balancer right so here one thing that you are seeing is the external IP but again if you are in a cloud-based environment you will see a IP over there but uh when it comes to mini cube uh this thing is normal why because kubernetes is asking for a load balancer but mini cube isn't a cloud provider that automatically gives us an external load balancer so that is why mini cube tunnels comes into the picture we are going to run a tunnel and by doing So it 14:43:25 will give us an external IP and that is something which is very much helpful for us to demonstrate this uh specific one. So now we are going to expose one load balancer service locally and let me open another terminal over here and I hope it is visible to you. Yes. So let me just uh do a little bit of zoom over here. All right. And the first thing that I would do over here is uh the first thing that you have to do is uh run mini cube tunnel command. Again note you have to keep this terminal open throughout the session when you are uh whenever you are experimenting with ingress because doing so it will start the tunnel and it will make sure that their external IP is visible for us and also uh when you are running this mini cube tunnel command at that time it might ask you for admin permission so you may also see a message like um it's sort of privilege port for port number 80 or 443 it requires a pseudo permission. So that is exactly 14:44:26 why because we are trying to make an HTTP and HTTPS available through the standard post. If uh MacBook ask if your Mac ask you for the password just uh enter it and make sure you are not closing your terminal. So yes, let's get started. So I'll just write mini cube tunnel enter. Now here it is asking me for the password. But firstly what exactly it is saying tunnel started successfully. Then please do not load this terminal as this process must stay alive for the tunnel to be accessible. The service ingress that is the name of service that we have created ingress engineext controller requires a privilege port to be exposed. Now what are those ports? It is port number 80 and 443. Sudo permission will be asked for it and then that is something that we have to provide. So let me just enter my pseudo credits over here and press enter. Now here the tunnel started successfully. Let me go back to my uh previous terminal. And now here we are here we are going to perform 14:45:27 the next further operation. Let me clear the screen. And after the tunnel is on uh you have to make sure that you are keeping the terminal alive. Think of tunnel as the connection to make our local load balancer uh reachable from our Mac. Now let us verify the tunnel. So after leaving that terminal, you can come to the second terminal and run the service command once again. So cube cuttle uh get service in the name space ingress - engineix and when I press enter this time you can see there is an external IP present and that is exactly uh why we used of mini cube tunnel. So uh basically here uh what is that IP address that it is signifying? Uh it's it's saying that we want a local setup and this is actually very important because our mini cube node IP might be something different right if you run mini cube IP mini cube IP this is something very different but exactly 14:46:27 what we are targeting to is nothing but a local host IP right uh or load balancer service is actually being exposed locally through this specific IP address and that's all because of mini cube tunnel so for this setup our browser and host host name should point to the address where the load balancer is actually exposed and that's why we are going to map shubhham.com the website with the IP address the external IP address that we have got over here this is the important step because here we won't be pinging the mini cube IP here we would be pinging the load balancer IP for uh the ingress controller that we have created right and make sure that mini cube tunnel is turned on so that you won't miss out with the demonstration that we are doing right now comes the part uh which makes fill the website a real a little bit real. So here what we are going to do is when you type http/ your computer DNS it will ask like uh what IP address does shubangod.com belong to. But again right now in the 14:47:29 current ways if you try to open it you won't you won't get anything why because we haven't defined the entry into the host that is something that we need to do. So for this machine shubgod.com should resolve to our local ingress endpoint which we can do by putting an entry into /c/host. So now let me run sudo/c. So basically this is the place where we want to make an entry and I will type sudh /host enter. I will provide my admin grid enter. And here this is the place where we will be defining that the mapping of shubhang.com with 127.0.0.1 right keep everything as it is. Your computer will ask you for the password but inside this file you will find these sort of entries. There is one entry by local hosts itself 127.0.0.1 you have to go all the way to the bottom and you have to define the rule for it. Right? So what I will type 1 uh let me go to insert mode 127.0.0.1 14:48:32 and here I will define my URL. So shubhamore.com escape colon wq and things are done. Okay. Now once it is done what will happen? Uh your computer will map your local host IP with the domain that you have provided and that uh that is all exactly been possible by mini cube tunnel. And what exactly it will do whenever someone reaches us to shamgot.com it will forward the traffic uh to ingress controller then ingress controller will uh read the rule book from ingress and then it will forward the traffic to the services and the services will forward the traffic to the eligible pods based on the uh labels that we have defined. So this is an important distinction because actually host file is only handling the host name resolution. It is not configuring kubernetes. It is not creating ingress. is not creating the services. It simply tells our local computer where shubamgore.com should resolve where your website should resolve. So now let us first verify the host name that we have done. So let me 14:49:33 just run a cat on /host to verify the entry that we have entered. So yes one thing after the verification is done let us uh test the host name resolution. So what I will do I will just copy the uh host name clearing the screen and what I'll do I'll just run a ping utility. I'll just uh type pingshong.com and here you can see the packets has been received. That is exactly uh what we want to see. The important thing here is not whether ICMP ping receives the replies. The important thing here is shub.com is actually resolving to 127.0.0.1 which actually happened. Why? Because we did an entry into host. We can also test actual HTTP endpoint which is much more useful for an ingress. So for that what we need to do is we will need to run a curl. So curl-env on http/shubhangore.com. And this is the place uh where we want to actually test whether the uh ingress controller and ingress rules are 14:50:34 actually working or not. When you press enter this exactly is the page that engine reflects when you open the page. And that is exactly what we what we tested. So again if the tunnel and ingress controller are ready call should connect to the HTTP endpoint and remember for an ingress HTTP or HTTPS connectivity these two test are most that we actually care about not the ICMP ping right because ICMP ping will just tell you about the packets been received but HTTP and HTTPS connectivity can be verified with the call because that will actually tell you the output of your page right now let us verify all the components because before even uh opening the browser we should verify all the layers. So just in case if you don't get this sort of similar output then there is something missing into the services. So let us verify all the things. So the first thing that you should verify is nothing but the ports. So cube cuttle get ports and here you will find all the ports which are related to the services that we have 14:51:34 created. Second thing that you should check is the service and the service that we have created is the front end service and the back end service. So cube cuttle get svc and here you'll see all the services which are listed over here. Then you should verify the ingress. So cubectl get ingress enter. And here you can see the application ingress the one that we created is present over here. Then we'll verify the controller. So I'll clear the screen. So cubectl get pods in the name space ingress engine. So here we are verifying that ingress controller is present or not. And then uh we want ingress controller port should be up and running. That is exactly what we saw. And the final thing that you should check is the service. So cubectl get svc in the name space ingress engineix. This is the service that we need to verify. Again after that thing also you need to check whether the external IP is populated or not because that is been done by the mini cube 14:52:35 tunnel, right? We want to check that the controller service is exist or not. And finally uh the last thing that we should check is nothing but and the most important thing is nothing but the ingress class. So cubectl get ingress class enter because this is the class through which we have defined the rules. So these are the all basic checkpoints the checklist that you should check before even uh doing the further troubleshooting because these are the important components when it come to ingress. So uh the basic checklist would be to check the application is running by checking the pods by checking the services are running by checking the controller is running or not by checking the ingress resources are created or not by checking whether the load balancer is reachable by checking the host name is resolving or not only after these pieces are ready we should be ready to test the changes from our browser now I will switch to my chrome browser and we are going to check whether when we type shubangod.com whether we are able to reach to the um page or not. So, let me 14:53:38 open my Chrome browser over here. All right. So, in my Chrome browser, what I'm going to do, I'm going to type http colon// shubhang.com. And here you can see welcome to engineix page which we actually wanted to test and this is something that we wanted to check, right? So, the browser is doing something very different uh from uh what we used to do earlier. Uh earlier we saw an IP address but instead of entering the IP address here we are entering the uh domain name. So here what exactly has been done? Uh the browser will resolve the domain name that is shubongod.com and from HChost file what exactly it says it says shubang shubangod.com is actually mapped with 127.0.1 0.1 uh and then what browser actually does it connects your domain with that specific service and here mini cube tunnel makes or load balancer service reachable there the request reaches the ingress controller the browser sends the 14:54:39 HTTP host header and that's basically what exactly has been happening and then the ingress controller it will check with the ingress rule it finds shubham.com with a slash and then it points it to the front end service that we have created. So the service then routes the request to one of our front-end pods and that is exactly what exactly happened. Let me switch to my visual studio code so that I can show you what exactly has happened. So here you can see what exactly happened. The browser actually navigated uh to httpubangod.com which actually verified the ent.0.0.1 0.1 is actually mapped with uh uh zubongo.com and then it forwarded the traffic to the tunnel. Then the tunnel forwarded the traffic to ingress controller. What ingress controller did did it actually matched the pattern and based on the routing rules set by ingress it actually forwarded the traffic to front- end service and based on the selectors that 14:55:41 we have defined into front- end service it forwarded the traffic to the front end pod and that is how we were able to see the application and now you see the engineix welcome page in our uh browser and this is something very important for us right because we are not just looking to YAML we are actually navigating getting to a host name from a browser and watching the Kubernetes route the request and that is why uh this section was very much important and now there might be one question like why uh the host name should match the ingress so let's connect the browser back to the YAML uh the ingress file that we have created in the ingress file we have mentioned a specific keyword that was nothing but rules in the rules we mentioned the host as shabbang com and in our HC host consist of a mapping for 127.0.0.1 which was the website that we wanted to host. So these are actually solving two 14:56:41 problem. First the HC host entry specifies and it says that where should my computer sends the request for shabbangod.com and second the ingress rule says that once the request reaches the ingress controller what should happen to the request for the website shubangod.com. So now we need both. The first uh is to get the request to Kubernetes. The second tells the Kubernetes where to uh where to send this request. So yes there is another important detail that I want you to see. So that is the host header itself. So now uh let me just switch to my terminal. So here there is one important observation that is whenever we visit the website at that time the browser sends an http request containing the host header similar to host colubanga.com. So if I just run a command get ingress.l I'm referring to this right let me just bring it over here. Yep. Okay. So what 14:57:42 exactly is happening that uh when we visit to the website.com the browser sends an HTTP uh request containing the host header similar to the host that we have mentioned over here. Then uh the controller exactly know that Shoubamore is actually pointing to the front- end service and that is exactly what hostbased routing means right the host name determines where the request should go and because we are using the host name in the URL need to manually specify the host header when we are using the browser now we are going to append the same ingress file for the backend service to to check what exactly happens when two services are actually working in a single ingress file. So what I will do uh we are going to make this a sort of interesting because right now we are navigating to shubod.com but what if if I want to visit and check my backend service too. So let's say if I want to go to api.shubgod.com so this should actually show my backend 14:58:43 page. So our ingress uh file should list both front end and backend service. So what I will do I will just do a vim on ingress yl dot uh ingress ingress.l and here what I will do just make sure of the indentation because here we are going to repeat the same operation but for a different host. So now if you're using visual studio code then it will make uh things very much easier for you. So what I will do I'll just switch to my visual studio code so that it will make sense for you and yes uh let me just go and open the ingress file and I hope things are visible for you. I'll open the ingress file over here. Okay and here we are targeting this section. So what I'll do I'll just copy this context entirely and this is something that we would be using for the second backend service that I was referring to. So here instead of the host shupamgod.com I will make use of api.supamgod.com. Second we are going to make use of http 14:59:44 routing and here instead of instead of this service front end service we would be using it as back end service and yes rest everything remains the same. Let me just recheck once again. So HTTP then we have path we define the slash part type prefix the services back end and we define the name of the service and it runs on port number 80. Now uh let's understand the two rules here. Uh the first one says that shubangod.com points to front- end service and API shubgod.com will point to backend service. These are the two things that we have to be clear from starting. And now we also want our computer to resolve the second host name because the first entry is already been done. Let me go back to my terminal. And now here is the place uh where we would be defining escape colon skip q not. Okay, let me clear the screen and verify whether the changes are reflected. Um I think yes it is. So clearing the screen once again. 15:00:45 escape colon q not clearing the screen now I will what I will do basically I will define the routing rules for uh api shubangod.com which is the back end so again sudo vim uh /hc/host enter and I will write my password enter and here in the file itself what I will do I will define the routing rules for uh API that is the backend file so it will be again same so 127.0.0.1 0.1 let me go into insert mode 127.0.0.1 0.1 and here uh we are defining the routing rule for API right for the back end so that is something that I will define so API dot shupangor.com escape colq done now we have uh saved this file and now what we will do we will apply the manifest file because we have made the changes in the ingress file but it was not a life change right we made the change in the manifest file but we are 15:01:46 yet to apply it so now what I will do I will just run cq cube cuttle apply - f ingress and here it says application ingress is configured meaning the changes has been applied now what I will do uh what is the end expectation uh basically when I whenever I am uh typing shubangod.com it should navigate me to the front end page whenever I am going to api.shubangod.com shubangod.com it should navigate me to the back end page right so both requests are entered through the same uh local ingress endpoint the host name will define the services received the request or not right so here there is one more thing you might noticed one thing that uh both the front end and back end are using the same enginex image so what will happen when you open both of them so let us see the things in action so now I'll go to my chrome browser here you can see the output for uh http colon//ubongod.com/ And now what will happen if I just type 15:02:46 http colon//api.shubangod.com shubang.com. Okay, here we are getting the page. Here we are also getting the same page. You may see the same engineext welcome page over here but that is completely fine because that is expected because here we are not trying to build two visual uh different application. Here we are just trying to demonstrate whether the Kubernetes is able to route the traffic or not. So basically what we did when we hit on shoubam.com the traffic has been forwarded to front-end service when we are hitting to api.shubang.com shub.com it is forwarding the traffic to backend service. To make uh the difference even more obvious in a real application your front end and back end would normally uh will uh will show different result but for this demonstration uh the service and routing rules are what exactly matters to us right now. Let me switch back to Visual Studio Code. Okay, let me go back to the readme.mp 15:03:50 file. 15:04:02 Okay. So here let's go all the way to the bottom because there's something that we have already performed. So right now we have done uh the thing that we have done is something what we call as hostbased routing. Meaning when someone goes to shubod.com it should show this page. If someone goes to api.shubangod.com chubong.com it should show that page but let's talk about a real life scenario where uh basically we want to do path based routing let's talk about path-based routing so this is a very common pattern that we can see right now if someone want to visit my website they have to go to shubangod.com for seeing the front end for navigating to the back end they have to go to api.shubangod.com shubangod.com. But what if if I want to change this a slightly different way so what if if I want to show the front end page in shubangod.com which we are already doing. But what if instead of typing api.shubhangod.com I want them to go to a pathbased routing meaning shub.com/appi. So if someone goes to that specific uh 15:05:03 URL they should see the back end. So this is something that we call as pathbased routing. So for that we will need to make some changes into the manifest file and that is exactly what we are going to see next. So let me go back to my uh terminal now and here we are going to make the live changes and we are going to understand how does pathbased routing actually works. So here uh what I will do I'll open my terminal and inside uh this file I'll just copy another ingress file. So in copy ingress dotyl to uh path ingress dot camel enter and when I do a list uh I have a path ingress file present so whim path ingress dot camel okay so here we have the exact copy of the earlier ingress that we have created here we want to make few changes over here right so the first thing is we will uh just directly go to the host so now the first thing that I will be doing is I will First remove the second host because that is not needed in this 15:06:04 case. And second I will delete the path. And here inside the path, yep, this is something that we are looking for. And make sure that this path falls under the same roof. Right now the first thing that we want to do is we will define the path for the back end because / APIs specifically tells that it is navigating the traffic to the backend pod. So here I'll go to path and here when someone goes to / API uh the path type should be again prefix it should go to the backend service and then it should forward the traffic on the port number 80. Then here if someone hits into shubhang.com/ then the part type will be again prefix but here this time it will go to front end and the port number is 80 escape colq let me clear the screen and see it once again path ingress.ml here we have a single host shubamgot.com when someone hits 15:07:06 slash it will go to the front- end service when someone hits a go to the backend service that is something that we have changed and it is very much simple to understand So now the routering rule will become something like this. And this is what exactly we call as pathway routing. But why does slash API comes before slash? This is something that you might have question because I can write the slash API afterwards also. Why specifically I wrote / API at first, right? So that is because slash has a very broad context. Uh Kubernetes path matching has a precedence value. So including uh choosing the longest matching path whenever multiple paths are available. So slash API is more specific than entering slash. So keeping more specific route uh to the first to the top and basically when we do that the configuration becomes easier for us humans to read. So when you are reading the path based ingress rule always pay attention to the paths that you are trying to mesh. Now let's actually test 15:08:08 this. uh so before even we go forward let us first apply this manifest file so I'll just apply it so cubectl apply -f pathbased ingress filel and here it says ingress networking ingress networking ksio application ingress is configured so it actually rewrote the previous one but again we are using another file just because I want to share you this file that's the reason we made the changes and do the same Now let us open u the web browser and see the changes live. Let me go back to my browser and this is the place that I want to show you. Okay. So now what I will do I will hit to the first result that is uh http colum.com/ here we are able to see welcome to engineix page. Now what will happen if I navigate to / API because that is something that we are demonstrating over here and that is nothing what we call as pathway based routing. So the 15:09:09 shubangor.com/api enter okay I'll share one finding that I just observed. So earlier when we were trying to hit to shabbhham.com/appi we just got site can't be reached. Why? because accidentally I stopped my mini cube tunnel and that's the reason I was not getting that output but again when I started the same I was able to see both the result that is shubangod shubhangod.com/ when you do that you'll get a welcome to engineext page and then secondly when you type shubangod.com/api it will show you the page 404 not found but again that is from engineext but is this output expected well yes this is expected there is something there is nothing wrong with your output page uh sometimes when your curl doesn't work don't immediately start changing the yl first uh troubleshoot each layer one by one so what exactly happened because I was aware that we made the changes inc host we were uh like that resolution 15:10:10 thing is done so what I did the next operation was I tried to do a curl and when I tried to do a curl since the uh mini cube tunnel was not turned on we were not able to do the ping and all right that's the reason uh I turned the tunnel on and I was able to figure out the issue and And that as soon as I turn the tunnel on the output was visible live into my screen. So now let me just go back to terminal and I'll show you what exactly I did. So yes I'll go over here. So yes what exactly happened. So I just tried to curl into the API and here it says it was unable to connect. It was getting connection refused and then second time I did the same with the front end service too. It says that failed unable to connect. Then I realized something is wrong with the tunnel. The tunnel got stopped. I started it again and I was able to view the result and that is how I did the troubleshooting for this specific error. So again uh what I didn't do exactly over here is I didn't started to make the changes in the YL. Yes, definitely 15:11:12 the first thing that you should check is the structure whether it is proper or not. If the rules are defined correctly or not. Second thing that you need to check is the entry in the host point. Third you need to check the most important thing is the tunnel and that is something that I missed and that is how you do the troubleshooting. Now so this is very important mini cube uh node whenever you are running things on Mac OS system. So first thing you need to check uh that uh your mini cube is running. Second the tunnel should be on and that is exactly what uh will put you away from the trouble right. So yes we saw host p host based routing we saw pass based routing. Now let us see uh what is the difference between them. So let us compare host based routing versus uh pastbased routing. So uh basically when we say hostbased routing we are talking about website.com for the front end. For the back end we will go to api.ebsite.com but when it comes to pathbased routing things slightly change. Your front end will be still listening on website.com but when 15:12:12 it comes to back end it will beite.com/appi. So these are the few things that you see in hostbased routing and pathbased routing. This is the actual difference. The difference is what we are using to decide the destination. So the hostbased routing use the host name for routing. Pathbased routing use the URL path. So in real application we use both it consist of both host based and path based. So ingress basically gives us a centralized place to define both the routing rules. So again uh let's come back to one step. Uh does ingress replaces services? Uh basically probably not. So far if you are following the tutorial you will actually get to know that service is actually needed. Uh this is probably one of the most confusion that you should avoid. That is ingress will not replace the service. The architecture itself makes it clear that the client will talk to the ingress controller. Ingress controller will check the rules from the ingress where we defined the rules and then based on that it will forward the traffic to 15:13:14 service and what service will do it will forward the traffic to the eligible parts which in which the application is running. So ingress routes the HTTP and HTTPS request to the correct service. The service will then provide this stable access to the backend port. So don't think like ingress or should I use service both plays a very different role. Both serve different purpose but again both are equally important. Now again let now since we are talking about services uh let's talk about the differences between uh ingress versus load balancer because uh this is a very important comparison that we should do because a load balancer exposes a service externally through a load balancing infrastructure. Ingress what exactly it gives uh what exactly it gives us? ingress gives us HTTP and HTTP based routing based on the capability based on the rules that we define into the ingress. So for example, if I have a front end, back end and a payment gateway uh with separate load balancer, 15:14:15 I will have a individual load balancer for front end, individual load balancer for back end, individual load balancer for the payments. with ingress architecture I can potentially have an ingress controller uh with front- end service, backend service, payment gateway all together based on the pathbased routing and the hostbased routing. So this is something that helps us with keeping everything centralized for HTTP and HTTPS routing. But remember something important, ingress still needs ingress controller and that controller still needs uh services, right? So when should you use ingress? Uh let me switch to my visual studio code and yes I am referring to this section. I'll go to the bottom. 15:15:09 Yes. So when should you consider ingress? So when you actually want to when you should actually use ingress. ingress is useful when uh you have HTTP or HTTPS application and you need things like hostname routing, path based routing, you need a centralized external HTTP and HTTPS entry and uh you want uh to do the routing for the traffic to the multiple service. For example, here you can see.com was forwarding to uh was rout been was been routed to front-end service. API shub.com was routed to backend service. Then again if you see if you talk from pathbased routing context then shubang.com/ payments will navigate to the pathbased service. Instead of exposing every service separately we centralize and we centralize the HTTP routing through ingress controller. But remember again ingress isn't a replacement for service. Both work together. 15:16:10 So yes that comes to the conclusion. In this video we literally covered a lot. Here you will find few interview questions uh which I want you to check uh manually by yourself and that comes us that takes us to the conclusion and yes let us talk about what all things we have covered today. We literally have seen a lot more lot more of things today. So we literally covered a lot today. So if I summarize basically we talked about ingress uh we created front end and back end deployments we created services we c in we created ingress controller we defined the ingress rules and uh that is exactly what we did and the best part was we were able to see the application live from our browser that was the main agenda of this video and we also saw path based routing host based routing the differences between them whether to consider service or not we also compared ingress with services and load balancer that actually gave us the clarity what exactly ingress is and what is the power of ingress. I believe 15:17:10 uh this uh video literally helped you in Kubernetes uh networking because ingress is one of the important uh networking concept that you should be aware of whenever you are learning networking in Kubernetes. Uh the important thing uh that we came across was that each component plays a specific role. uh basically the pod will run your application services will provide you a stable connection. your ingress will provide the rules for HTTP and HTTPS uh based on uh the routing uh the controller will actually implement this routing rules and then uh we also understood that when you are working on a Macbased system uh on a controlled environment uh specifically on mini cube uh what HC/hodes uh does basically it provides a resolution for browser so that whenever someone reaches to shuhham.com any website.com it will route the traffic to 127.0 0.0.1 and why that thing was possible it was possible with the help of mini cube tunnel right what mini cube tunnel does it makes your 15:18:11 local load balancer uh load balancer reachable and once you understand all these responsibilities ingress will eventually become very easy for you so yes that was all in this video and yeah you can also find the mental model for all the things that we have learned so yes that was all in this video and I will see you in the next one until the next and keep learning and thank you very much. All right, so let's continue our Kubernetes networking journey. In the previous videos, we have talked about services, different sort of services, cluster IP, node port, load balancer. We are also not aware about ingress, how does it navigates the traffic to services and how does we define the rule for HTTP and HTTPBS traffic, right? And there is one basic question that we haven't answered yet and that is exactly that we are going to answer in this video. So uh when we are learning Kubernetes networking the very first time uh we are very much curious and like that question should be there in 15:19:12 your mind. Uh what actually happens when one pod wants to communicate to another pod. Let me break it down in a very simpler terms. Let's say you have a front- end pod and you have a back end port right? Then the question should be how does front end pod is actually able to reach out to the back end pod right and before even getting into podto pod communication there is another interesting question over here is what if one pod contains two container because if you remember when we started our journey with pods at the time I said usually the standard is we create one container in one pod but what will happen if a pod consist of two container right so uh can those two containers communicate with each other since they are uh in a same pod right they can then what would be the IP address they would be using will it be different or not and then we have another set of question that what will happen when pods are on different Kubernetes nodes for example in node one you have front end pod in node two you have a backend pod so will the traffic from pod A from node one 15:20:14 will be able to go to pod B in node two and finally uh who actually creates this pod network so uh this is where we would be introducing CNI. Now what is CNI? CNI is nothing but container network interface. So in this session uh this would be a complete hands-on. So we are going to build everything from the scratch. Basically we are going to focus on four major points that is container to container communication inside the same pod. Then we are going to look into podto pod communication. Then we are going to see the podto pod communication across different nodes. And then we are going to understand what exactly CNI, what role does it plays in Kubernetes networking and finally we are going to connect everything. So this will be a powerp packed video because here we won't be just learning about networking. Here we are going to implement all the things that we have learned so far. Here we are also going to cover demon sets too. So like enough theory and let's directly jump to the practical. But there is one fundamental question that 15:21:14 we should be aware with that is what is a pod network. Right? So that is exactly what we are going to discuss now. So before creating anything let us first understand one important statement from Kubernetes and that is nothing but every pod gets its own IP right and all container inside that pod will share the same network name space. Now I will repeat it once again. Please write it down somewhere. Every pod will get its own IP address and all the containers inside that pod will share the same pod network's name space. What exactly it means? So basically the container inside the same pod will share the same network. They will share the same pod IP. They will share the same port space. And this is why containers in the same pod can communicate using local host. So if you have a pod and inside that pod you have two containers. Let's say container A and container B. Both containers are effectively using the 15:22:16 same pod network. This is very different from two containers running as two independent pods. Uh Kubernetes explicitly documents that each pods has its own network name space. So container within a pod can share the same network name space and the same IP address and those containers can communicate with the help of local host. Let's see the things practically ourself. So here I'll switch to my terminal and yes my mini cube is up and running. So now what exactly we are going to do? So I am going to create one pod and inside that pod we will have two containers. So the first container uh here we will be making use of engineix because engineix gives us the visibility where we can actually see the networking and secondly we would be creating a container for curl. Now this client will help us to do the ping uh that will actually help us in verifying whether the communication is happening or not and that's the reason we are considering the second pod as so now let us create 15:23:19 the second container and with this second container we would be calling the first container through local host. So let us create the first file for this specific demonstration. Right now my mini cube cluster is up and running. So let's get started. So here we are going to create the first manifest file that we have created when we started our Kubernetes journey and that is nothing but pod. So yes let us do the same. Let me first navigate to my directory. So here I'll just go to Kubernetes and here I'll go to 18 Kubernetes networking resource. By the way all the files will be uh present into the GitHub repository. So by the time you are seeing this video it will be already present. So don't worry on that. And also I have already prepared a readme.md file that will actually help you to understand what exactly is happening. So after you are done with the theory the video that you are actually looking after you are done with everything this readme.md will act as a revision material for you so that you can revisit revisite and you can actually recollect all the things that we are discussing. 15:24:20 So yes let's get started. So the first thing that we are going to create over here is uh we are going to create pods and basically inside that pod we want two container. So let me vaguely give it any name. So I'll just write two hyphen containers and dot yaml would be the extension. Now again whenever you are creating any sort of resource in Kubernetes what are the four golden keywords that you have to keep in mind? API version metadata inspect. So I'll write the same API version metadata and spec. Let me just do a little bit of zoom so it is visible for you. Escape colon wq. Now why how will I verify the value that I need to put into API version? Do I need to remember it? Do I need to memorize it? No need. we have something called API resources that will actually help us to do our job right. So what I will do I'll first clear my 15:25:20 screen so that it is visible to you and the second thing that I will run is cube cuttle API resources. So cubectl API - resource and we'll do a grab on pod. I hope it is visible to you. And yes here you can see for pod resource the API version that we are using is nothing but v1. All right. And this is something that we would be using in kind. So I'll again go and I'll update my two containers. And here I'll just define the manifest. So here in the API version I'll define the API version as v1 which we recollected from API resources. Then again I'll define the kind. Now here it will tell cubernetes what sort of resource what sort of workload we are trying to create. Now again in the metadata. So here we are going to give the name to the uh pod basically what exactly would be the name of that pod. Now since here we are trying to create a pod that consists to container. I'll just give a vague name. 15:26:22 So here I'll just give it a name as to container containers pod. So this will be the name of the uh pod that we are going to create and then here I will define the specification. Now again in this pod we want to run containers right. So here I'll just write containers. Containers and here basically how many containers you do you wish to run. So as per our requirement we want two containers to run in this specific board. So here I will pass two name. So here the first uh pod that we want to create is a engineix pod which we will call as web and second is the name of the second pod which we will call as client client. So which will be responsible to run the curl image. Right now here for the web uh for the uh web container the image that we would be using is nothing but enginex. So engineix colon latest and 15:27:23 again for the client we would be making use of the image called curl images. So here I'll just write curl images / curl. Right now again uh when you are dealing with this client image this curl image there is a specific command that you need to pass and that is nothing but you can pass it by running command and here you need to pass two flags over here. So the first thing that you need to send over here is sleep and again there is one more uh set of command that you need to pass that is 360 0. Now what exactly is this? Let me just explain it to you. Clearing the screen let me run a cat on two containers. Let me explain you everything line by line. So the first thing that we have defined over here is nothing but API version v1. We are creating a core cubernetes resource. Second what we are doing? We are creating uh we have defined kind. So basically here we are telling Kubernetes that we are creating a pod directly. Then in the metadata we have defined the 15:28:24 name of the pod right and the name of the pod is nothing but two containers pod that that is exactly what we have given. And then we are coming to the next thing that is nothing but the specification. Now in the entire Kubernetes topics that we have learned so far whenever specs comes you can actually say that this is the configuration for that resource type. So here in this case whatever settings whatever configuration that we want for this specific pod are actually mentioned just below it. Right? So inside that pod we want to create two containers and that is exactly been mentioned over here. So what are those two containers? First container that we want to create is web and second container that we want to create in this pod is nothing but client. Now that web container will utilize engineix image and the second client uh container will make use of curl image. Right? Now the last thing that I want to tell you is about this command. So here I made use of command sleep 360 0. Now what exactly is this? So here we are telling container to stay alive for 360 seconds. Now the first 15:29:26 question that should come in your mind is why do we do that? Later we want to manually enter the commands and we want to execute the curl commands inside it. So let's create the pod and let's see whether the changes are reflecting or not. So clearing the screen and in order to apply this manifest file we are going to use that standard command that is nothing but cubectl apply-f followed by the name of the file that we have created that is nothing but two - containers. ML and if your syntax is correct you will get the output like pod/2 - containers pod created. Now when I run cubectl get pods here you can see it is saying as container getting created. Okay let us wait for some time once the containers are created we should be able to see uh ready 2 /2. So what exactly that 2/2 tells us? This tells us that both the containers are ready and they are running right. So let me just run the command once again. And here we are getting the ready status that is 2x2. 15:30:28 Earlier since the container didn't got created and the status was under under container creating we were getting the earlier output right. So please put a focus over here and here. So that exactly gives us a hint that the container the uh container are actually running inside that pot. Clearing the screen. Now let us do one more thing. Let us inspect the container section. So what we'll do? Let us run the command cubectl get pods. Enter. And here we have two container pods. Let me just inspect it. So cubectl describe pod followed by the pod name. Now here there are two things that we need to check that is let me just do a zoom out over here. Inside container you will see a web container with the image engineix latest and second we have a client container with the image curl images that is exact that we wanted to uh check over here. Now let's enter the 15:31:30 container uh let's enter the client container and let us go inside it and after we are inside that client container we are trying to do a curl on local host. Now the end expectation is since they both belong to a same pod we should be able to see the output of engineext. So let's do the same. So how do we go inside a client container. So basically if you remember docker at that time whenever we wanted to go inside any container we used to make of we used to make use of exact and we used to make use of it right that what does that it mentions interactive terminal exactly the same thing we are going to do in kubernetes but here instead of using docker we will be making use of cubectl so let us do the same so cubectl exact for interactive terminal signal which we actually used. Now again here what we are going to do is we are going to make use of the name of the pod that we have created. So two containers 15:32:32 containers and I think uh I need to check the name of the pod. So cubectl get pods. Yep. So cube cuttle exact it to containers with s - pod and then since we want to go inside the client pod uh client container I will mention hyphen c since we are targeting a specific container. What is the name of that container? The name of the container is nothing but client. So client and then hyphen sh to go inside that container. So let me just remove this hash from here. And now here you can see my terminal got changed and here we are inside the client container. Now the next thing is we are going to call the local host. Now the end expectation is we should see the engineix welcome page. Let us do the same. So curl http col//lohost enter. And here you can see welcome to 15:33:32 engineix. So this is something that we were expecting and this is really important because here I didn't made use of pod ip here I didn't use here I didn't use pod ip here I didn't made use of services here I didn't used ingress here the only thing that I used was simply a local host because both the containers were a part of a pod so what exactly happened when we executed the client container it was already a part of that pod so when we just did a call on loop Drupal host it was able to fetch the enginex for us. Right? Now let us do one more thing. Uh we can also check the enginex version so that we can verify that it is also running. Right? So let me just do exit from here. Clearing the screen. If you want to run a command from outside how will you do that? Basically whenever we used to use docker we used to make use of exact without interactive terminal because this time I want to just run a command externally. Same thing can be done with cube cut. So 15:34:33 cubectl exact and then followed by the pod that we have created. So to containers pod now again which uh container we are targeting to. So hyphen see we are targeting the web container and then I will just pass the command that I want to execute. So engineix - v engineix space v enter. And here you can see we are getting the output as engineix version/1.31.5. This shows that engineix running inside that web container. Now one question that should pop up in your mind is why does the local host work. So let us stop over here and let's just discuss about this concept because uh these are the two containers and since they share the same pod they are on the same network name space. So whenever the client calls localhost col 80 it's just like talking in same network name space where the engineix container is actually 15:35:33 listening. So inside that pod we have a web container which listens on port number 80 and we have a client container that again listens on local host 80. So the client container can reach to engineix because both the containers are in the same pod. And this is one of the biggest difference between two containers running in same pod and two containers running in separate pods. So there is one more important detail over here is because containers are in the same pod they share the same network name space. I will repeat it once again. Because the containers are in same pod they share the same network namespace. they are also the part of same port space. That means you cannot normally have two containers in the same pod because both will try to listen on the same IP and on the same port. So for example, if I put it into simpler words here we have container A which is listening on port number 80. We have container B which is listening again on port number 80 because they are sharing 15:36:34 the same network name space. This is one of the reason why sidecard containers uses a different port number for the main application. What exactly is a sidecard container? Basically any sort of logging tool, any sort of logging tool which is extracting the data from our application that is nothing but a sidecar container which we are going to see later. But for now just imagine that if you want to monitor something and let's say inside a pod your main application is running you will need to fetch some log out of it. And that's where we make use of sidecard container. Right? So when we are designing a multicontainer pod remember always remember this that same pod means sharing same network name space right. So here we saw how we can communicate container to container inside a pod. Now let's move to the next level. Here we are going to see a higher level of thing because here we are going to see the podto pod communication. Here right now what we did in the current name space we created one pod and inside that single 15:37:34 pod we created two containers which were capable to ping each other with the help of local host. Now what we are going to do instead of pinging from container A to container B inside the same pod. Now what we want we want to ping container A from pod A to container B in pod B. So these are the two separate pods that we will be needing. So for this what we are going to create? We are going to create two pods file. First we'll be uh running the engineix container and second we'll be running our curl client. Let us create the backend back end port first. So clearing the screen and let us create the backend file. So back end doml. Now again uh whenever we are creating any sort of resource in Kubernetes what are the four keywords which we need to remember API version kind metadata inspect. Let me write the same API version kind metadata 15:38:36 and spec. All right. Now, where do I get the value for API version? again cubectl API resources do a grip on pod. Now here we have v1. So that is exactly what we are going to use over here. So whim back end. Now here I will define the API version and that is exactly where we get and that is exactly what we get from API resources. Now kind what sort of resource we are trying to create. So here we are trying to create a pod. Now inside a metadata we will define the name of that pod. So here I will write name and this will be nothing but backend pod. And then again now in the metadata there is one more important entity that we have learned so far. Now when we were dealing with services when we were dealing with ingress there was a key role player entity that we learned labels and selector. Let us define the same. So here I'll define labels 15:39:39 and the label for this one would be app back end back end and now let us define the configuration the settings for the same. Now here inside this pod we want to run the container. So container now since this pod will contain a single container I will define the configuration for the same. So here I will just give the name for this container as engineix or here since we would be calling it as a service. uh so here what what I will say this will be nothing but a back end pod and here what I will do I will define the image so what image we would be utilizing for this backend service here we would be making use of engine x escape colq let me explain you everything line by line so that things will make sense for you eventually so again let's quickly understand what is the first thing that we have defined API version v1 this is the core kubernetes API then second we have defined find pod. So here we are telling Kubernetes that we are creating a resource type called pod and then here 15:40:41 we have defined the metadata. Inside metadata we have defined the name of the pod and the name of the pod in this one would be backend hyphen pod. So the pod will be called as backend pod. Then we have made use of labels. So here we are giving the pod a label. This will become very useful when we will be uh when we will be using services right. And then here we have defined the container. So inside this pod we we wish to run a container and the name of that container would be nothing but back end. And again uh in that container named backend we want to run engineix. So here we have defined the engineix image. So here exactly what we are doing we are running a backend pod with the engineix image. That's it. Now let us apply the manifest file. So clearing the screen cubectl apply -f backend. Mamel and if things go good which actually it should you will get a message port/backend port created. Now 15:41:41 let us verify the same. So cubectl get ports enter. And here you can see backend pod is up and running. Right now let us get more detail out of it. Uh now when I say more detail what we are referring to here I am very much interested in knowing the IP address because here we are talking about the communication the networking and for networking what we need the first thing is nothing but the IP address. Now what is an IP address? IP address is nothing but your unique identity over the internet. Just like in India we have our Aadhaar card which consist of 12digit unique character. in internet or identity is been referred by IP address and that is exactly what we are referring over here. So let me just run the command cube cuttle get pods - wide that will give me the identity for this pod. So cube cuttle get pods - wide enter and this is something that I'm interested is that I'm interested in that is nothing but 10.244.0.5 0.5 15:42:41 right so here in your case since you will be running the same command in your Kubernetes cluster or maybe on different environment your IP address might change and that is completely normal that is accepted now let us create a client port so for that again we will need to create one manifest file so let us create the uh manifest file for the client port 2 so vim client client-enpodkl and don't worry all these file I will be pushing into my GitHub repository so that by the time you are looking this video you will have all the files handy. But one thing I would recommend is uh you should type your manifest file by your own hand because that will give you the confidence what exactly you're dealing with and that's the main purpose that I'm writing the entire file live in front of you so that just in case any issue that I am facing you might get in future so you know exactly how do you troubleshoot it. So let's get started on the same. Now whenever you are dealing with any sort of resource in Kubernetes, 15:43:42 what are the four golden keywords you need to remember? API version, kind, metadata and spec. So API version, kind, metadata and spec. Now again uh right now we just created a pod. So we are already aware that the API version for pod is nothing but v1 and the kind is nothing but pod. Now here let us give the name the metadata. So what exactly we would call this part? So I will give this the name as client port client hyphen pod. Now moving forward in the specification what exactly is the specification. Now again we are aware that specification is nothing but this setting. Let me just do a little bit of zoom. All right. Now inside this pod we wish to run a container. So I'll just write containers. Containers. Now again here I will define the name of that container. Now what should be the name that I should give uh to this specific client pod. So inside that client pod I want to run a container named client. So I'll just define the 15:44:44 name as client. And now which image should it utilize. So again if you remember earlier we made use of curl images/curl that is the exact image that we would be utilizing over here. So curl images/curl and here inside that we would be running the commands. Now what are the set of commands that we wish to run? First is sleep and secondly is we want to run 3 6 0 that is exactly 1 minute clearing the screen. Let me just read the entire file. Okay. Now let me just break things up for you. So here we have API version which we which is actually telling the core Kubernetes object. Second we are telling Kubernetes that we are trying to create a resource which is of type pod. Then here we have defined a metadata and here uh this metadata is for the pod. Now here we are telling that we are trying to create a pod whose name is client pod. Now under that we have specification. Now this specification is for what? This specification is for the 15:45:44 resource type that we are creating and that is nothing but for the pod. Now inside that pod what do we wish to run? We wish to run the containers. So in order to run any sort of container inside a pod we will need few details. what should be the name of that container and which image uh it should use for running the container. Right? So the name of the container is nothing but client and the image that it should utilize is nothing but curl images/curl. Now in order to keep that client alive up and running here there is few set of commands that we need to run that is nothing but sleep 360. So that whenever we take SSH into that we would be able to ping to the other containers other pod right. Let me clear the screen and let me just verify whether the resources are created created or not. But before even that let me just apply the manifest file. So cube cuttle apply -f client port.l the resources created. So cubectl get pods - o wide because this will give me the IP address to enter. 15:46:46 All right. So here you can see we have a backend pod and here we have a client pod and that is exactly what we were actually targeting to. Now again the first thing that we would be needing over here is the IP address for the backend pod. Right now what we are going to do is earlier in a single pod we had two container and inside one of the container we took the SSH and we actually pinged the local host but this time we are changing the scenario. Instead of pinging to the local host, we would be pinging to the backend pod from the client pod. Right? So here we have two individual pod and this would be the demonstration for pod to pod networking. So let us uh go inside the client pod and here we will be pinging the backend pod. So how do we go inside a backend port? Just like docker docker exac- it/bin/batch. Same thing we would be doing with cube cutter. So cubectl exact id since we want an interactive terminal and here I will pass the name of the pod and hyphen 15:47:47 sh because we want to go inside that pod. Now here you can see the terminal got changed and here we are inside the client port. Now the next thing that we want to do is we will run a curl on the backend IP over here. So let me run curl http col// followed by the back end IP. When I press enter here you can see we have welcome to engineix that is the default page provided by engineix itself. This is a very important experiment and what we just proved we just proved that one pod can directly communicate to another pod using the pod IP address. So here Kubernetes networking model is designed in such a way that the pods can communicate to other parts including the nodes without requiring any sort of uh proxy or net between the pods. Right? So uh think about what we actually did here. What we did we took a client port and we had a backend pod. The client port sent the 15:48:48 traffic to the backend port. And here the most interesting part is we we didn't even create a service. We didn't even create the ingrance. We only made use of the pod IP. So if you see things at networking level, there was a pod A, there was a pod B and from pod A, we just pinged the IP of pod B and we were able to communicate. This is what we call podtood communication model. Right now you might ask Shubam if things are working really that good why do we uh why don't we use pod ip directly. So I will just tell you why usually we don't make use of pod ip in application. So now if uh your port-to-part communication works directly uh you might you might ask you might have a doubt why do we even need services but again if you are someone who have already watched the services section you are already aware why do we need services. So uh let me give you an example because this is something that will literally help you to understand 15:49:48 why services come and what are the offerings by services. So uh let's consider that the uh backend pod is deleted somehow and then you have created the deployment. Now based on the nature of deployment what it will do it will create a replacement. Now that replacement will receive a new IP address. Now what will happen? If your application has the hard-coded IP address then it will try to ping to that IP address but again that pod is not yet present then where will where will the data will go right? And that is the exact reason why we don't hardcode IPs into the uh application and that is exactly service came into the picture. So instead of using hardcoded IP addresses, we make use of services. So what service does basically it provides a stable connection while pods are actually doing the work at the back end. Right? Now again uh let me just prove that the statement that I provided when you delete a pod the IP address will get changed. Right? Let me just actually 15:50:48 show you so that you will be able to get what exactly that I just told. Let me clear the screen now. I'm I'll just type exit so that I'm out from that container from that pod. Clearing the screen. Cubectl get pods o. So here just put a focus on the backend pod. What I will do? I will just delete this pod. Now here we haven't created deployment yet because here we just we are just dealing with the pod file right we are going to create a deployment file later but for now just focus on the IP address for the backend pod let me just delete the file so cubectl delete pod followed by the pod name that is backend hyphen pod enter and here it says pod backend hyphen pod deleted from the default name space now again default name space why because we haven't specified the nameace what is the namespace namespace provide us with a logical separation and isolation so that the application runs in an individual isolation environment. So now 15:51:51 what we'll do I'll just rerun the command once again. Here you can see since we are not uh relying on deployment we just created the pods manually by our own self. Uh the backend pod didn't got respawned. But again the main focus over here is what will happen if I again create a backend pod. Let me just create the same cubectl apply - f and here we would be applying the backend yl. Now here it says back end port is created. Now please focus over here earlier when the back end pod was up and running at that time the IP address was 10.244.0.5. Now when I just check it again here we have the backend pod again up and running. But the thing which got changed over here is earlier the IP address was 10.2 244.0.5 this time the IP address got changed 10.244.0.7 0.7 and that is exactly what I was saying earlier that whenever you delete a pod the IP address that identity gets 15:52:52 changed and that is the reason why service came into the picture right so if you are creating the pod directly kubernetes is not going to recreate it automatically we are manually going to create it so that's the reason deployment came into the picture that was actually taking care of all the recreation stuff and again deployment is relying on replica set and replica set is actually doing the job. So everything is connected it is interlin. So here we verified that uh why it is getting a new IP address and uh why uh using pod IP address is not a permanent or not a good approach to hardcode the IP into the application. So in real application a deployment would normally manage the pod and recreate them automatically but actually the thing is here we won't be using the hard-coded IP address we would be making use of services now since we have uh we are talking about deployments about the 15:53:53 recreation let us actually create one so that it will make even more sense let me just delete this pod once again so cubectl delete pod and the pod that I want to delete is the back end pod Why? Because here we would be creating that backend port again but with the help of deployment because that will help us to visualize what will happen what will be the nature of the backend part when it is getting deleted in the presence of deployment. So whim backend backend deployment dokml enter I now again this time instead of creating a pod we are creating a new resource type that is nothing but deployment. Now again what are the four key words that we need to remember? API version, kind, metadata and spec. So API version, kind metadata and spec WQ. Now why we want to know what is the API version for deployment and where do 15:54:54 we get it from? Cube cutle API resources. So cubectl API - resources and here we'll do a grap on deployment or you can also write deploy enterti okay resources let me just correct reso or cs resources okay here we have the API version for deployment that is nothing but app/v1 let me just reedit the file again so Here I'll just define the value for API version that is nothing but app/v1. Here I am trying to define the type of object the resource that I want to create. So here I'll just define deployment deployment. Enter. Now here comes the metadata the important section. So here I am I will call this deployment as back end just like uh the way we created for the earlier one. Now here we'll define the settings for the backend deployment that we are creating. Now whenever you 15:55:56 are dealing with deployment you need to define one thing and that is nothing but the replica count. So how much replica should it maintain. So here we are defining the expected the desire number that we want the number of the part that we want. So here I'll just write replicas replicas and I wish to have three ports that should be up and running whenever uh we are on this specific cluster whenever we are on this node. So now again on what basis uh it should be creating. So here comes the most important section that is nothing but selector. So here in the selector I will define the uh label. So it should match the labels and here I'll define the label as app colon back end. Now once the label is created at the level of selector I'll define the template and what exactly this template is for? Basically here we are telling the deployment these are the part that you want to create. But how will the deployment know the configuration the 15:56:56 settings for the pod right that is exactly what we are mentioning over here. So inside the template I will define the metadata and this metadata will consist the label that will be present on the parts that will be created through the deployment. So here the label will be again app colon back end and here you can see here it is exactly matching to the selector that we have defined earlier. Now just below the labels here we will define the specification that will just follow that that will just fall below the metadata level. So spec now again if you are working on visual studio code things will be very much easier for you but since we are on item or on terminal uh we have to make sure that the indentation has been followed. Why? Because YAML is strict with the indentation. Okay. So here we will define the specs for the containers. Now again what should be the name of this container? So here I would like to give the name as back end. So back end now again which image it will use it will use the image called engineix. So image 15:57:57 engineix colon latest escape colq. Let me clear the screen. I'll do a cat on backend deployment. Mml. Let me explain to you everything line by line once again. Okay. So here we have API version app/v1. Here we are trying to tell Kubernetes that here we are trying to create an object type application/v1. Here the object that we are going to create is nothing but a deployment. The work type that we want to create is nothing but deployment. But uh what would be the name of that deployment that is nothing but back end for that specific deployment name back end. What would be the setting the configuration that is something that we have defined over here. What our end expectation is that it should run three pod. So that's the reason here we have defined the three replicas over here. But on what basis here we have defined the uh labels as apps/back end. So it will completely monitor and it will check wherever it finds the pod name app equals to back end it will actually target them. Now again what sort of pod it should create basically it should create all the pods which have the labels app colon back end 15:58:59 and what would be the specification what would be the value for that pod. So basically inside that pod it should run the container where the container name is nothing but back end and the image that that container is using is nothing but engineix latest. Let me clear the screen and let me just implement and apply this deployment file. So cubectl apply -f backend deployment enter and here it says deployment.app/backend is created. Let us verify the theme. So cubectl get deploy and here you can see ready 3x3 and it is up and running for us. So here we have three backend pods that is actually running and this is really more realistic. So the deployment will try to maintain the desired number of pods right so let me just list the ports that it has created. So cubectl get ports and let me just run hyphen oite so that we can actually look up into the IP address. So here you can just focus on 16:00:00 these three back end port that it has created right. So basically here we have pod number one pod number two pod number three along with the individual IP address. Just note the IP address. For pod number one it has the IP address as 10.244.0.8. For pod number two it has the IP address as 10.244.0.10. Third IP address is 10.244.0.9. So the end conclusion from entire context is nothing but if either one of the pod is deleted it will create another pod but the IP will get changed. So let me just delete one of the pod. So let me just delete this pod the pod with the IP address as 10.244.010. So cubectl delete pod followed by the pod name. Oh let me just clear it. Enter. And here you can see it got deleted from the default name space. But 16:01:00 when I just run cube cut ovide, there is another pod which is up and running over here. Clearing the screen. Let me just show it to you once again. So one second. All right. Okay. Hope it is visible to you. Earlier we deleted the pod with the IP address as 10.244.0.1. And here it created another pod. Here you can see the age as 16 second which just got created with the IP address as 10.244.0.11. And now you understand now I think you have the context why we don't make use of IP into the application the hardcoded IP and that is exactly why services exist. So now let's talk about nodes. Currently we are using normal one node mini cube cluster and both pods were naturally were on the same node. So let us verify the same when I uh actually run cube cuttle get pods - wide you can see all the pods that are created are under the 16:02:02 node named mini cube because mini cube provides us a single node cluster which act as both cluster and worker node. Right now here uh the communication is just like we have a single node where we have client and back and pod. So here we proved that inside a single node two ports can communicate. We verified that inside a port two containers can communicate. Right? That is exactly we proved. But now let's make things interesting. Now uh let's say that we have uh a pod A on node one and we have pod B on node two. So can a pod A still connect to pod B which is present on different node? Answer is yes. So Kubernetes network model is designed so that the pod can communicate with each other regardless of which node they are on. So assuming that the cluster network is functioning fine and no intentional network segmentation is been made. So let's actually prove it. So for this since we have a mini cube cluster 16:03:03 actually act as both master plane and worker node. Here what we are going to do is we are going to create two mini cube cluster. So rather than destroying the current cluster let us uh define the context for the same. So this way we won't be interfering with the existing cluster. So how do we create it? So for that we have a mini cube command that will actually come into handy. Now where you will find that mini command I'll just share my visual studio code and again this readme.md file will be shared with you. So don't worry on that you will find entire thing written over there. So let me just scroll down and we are at this segment. So let me just go down again. Okay. So instead of destroying the mini cube cluster we will make use of this command. Now what exactly this does? Let me first copy it and let me just tell you meantime it is running so that we can save much time and like we can discuss on the same again. So I'll go to my terminal and here what I'll do I'll 16:04:05 just run this command enter. Now what exactly is happening over here? This will create a mini cube cluster with two nodes. So when I say mini cube starts hyphen node that exactly tells to create two nodes for us. So mini cube officially supports multi-node cluster with the help of hyphen nodes option. Now based on your requirement you can change the node count to two you can make it to three you can make it to four depends upon you. So once it gets finishedes we will switch to the new context. Now what is a context? If you remember here we mentioned networking demo that is hyphen p. So that uh exactly is defining the context that we have defined right. So now when I clear the screen let me just do a little bit of zoom. Yeah, when I when I do cube cl get pods here you can see uh we get the results right so before even we run pods I just need to verify the nodes because that is exactly what we are interested in so here you can see uh we have networking demo and we have networking 16:05:05 demo m02 right so for you the names might be slightly different so like don't worry on that it is expected so after hyphen p whatever name you mention that would the name of your machine the name of the nodes right so the names may differ let us get the IP address for the same uh to get the more info on it so cubectl get nodes - white enter and here you can see we can see the IP address for both the nodes that we have created so networking demo one which will act as a control plane and we have networking demo M2 which will which is labeled as none but again here we would be using both for the communication for the networking. Now uh there is one more important concept that we have learned earlier and that is nothing but demon set. Now the requirement is I want to run a pod on both of these nodes. Right? Now again if you remember demon set is something that runs on all the eligible nodes. Right? 16:06:06 That's the exact job of demon set. So a demon set is a perfect over here because it ensure that one pod runs on each node and we have already covered this thing endapped in one of the videos earlier. So this is going to be a nice revision nice example. So uh yes let's start with demon sets over here. So what I will do I'll just create another file and let me just name it as network test because that exactly is what we are going to do now. Now again four golden keywords for creating demon set API version kind metadata and we have spec escape colon wq. Now how we will I remember the API version for demon set. Well you don't have to remember we will have we will make use of cubernetes documentation. If not we will make use of wonderful API resources. So cubectl API - resources 16:07:07 and we'll run a grap on demon enter. And here you can see a demon falls under app/v1 API version. So I'll just again go back to my API version. And here I'll update the values app/v1. And here what exactly we are trying to create? We are trying to create a demon set. So demon set demon set. And now here I will provide the metadata for demon set. Now this demon set will be called as network test because that is exactly what we are doing. So network test network test. Now after defining the metadata let's go to the settings the configuration for this demon set. Now here we would be defining the selector because that is most important segment in demon set. Now again I'm saying this one more time. Labels and selector are the important concept in Kubernetes. So if you are aware of that concept, it will make your life really very easy. So I'll define the selectors over here. So selector will search for 16:08:08 the match labels and here we will define the labels. Please pay a close attention into this label because this is something that we would be referencing later also. So network network test this will be the label that we would be targeting to and then here we will define the template. So just below the selector level we will define the template enter. Now that template will again have the metadata. So meta data and here I will define the labels label enter. And here the label would be again network- test enter. Now after defining the labels we will define this specification that will again fall inside the metadata section. Yes. And if you are on Visual Studio Code you will already get emits. It will help you in writing the manifest file. So again inside the specs I will define the containers and here I'll define the name of the container that we want to run and 16:09:08 the name of the container that we uh are creating over here is nothing but the web web application. And here the image that we would be using is nothing but enginex. So engineix colon latest scape wq. Let me just verify the file. So cubectl apply -f uh the name of the file. Let me just check. I just forgot. Uh yeah the name of the file is network test. So cubectl apply apply f network test.l. Okay we got an error. Let us let us validate the same. The request is invalid patch invalid value under the map metadata map. There is an annotation issue meaning we have written something wrong into the manifest file. Okay. Strict decoding strict map and here it says unknown field. Here we are searching for this thing. Okay. Here it says spec dot selector dot match label and here spec.mplate dot metadata.l. Okay. So 16:10:11 there is an issue with labels and selector. That is exactly what this error is trying to say. Let me just do a vim inside my network test file. Let me just check again. API version correct kind done metadata and the issue was with selector. Let me just verify the same. So here we have selector with match label with this should be with s escape colon wq. Let me just reapply the file. It again says the issue and again there is an issue but yes this time we got red with the earlier issue that was with the selector this time we don't have that same error yes selector issue is gone now here it says the issue is with label so I'll just again go to network test okay so instead of label this is nothing but labels labels with escape colon wq clearing the screen once again applying the file Again we have the issue and this time again the issue is with the manifest file whim network 16:11:12 test. Let us validate the same and here we have containers spelling wrong containers containers escape colon wq. Let me just verify it once again. Q not and let me just apply the file. And this time finally the deployment dot uh deployment file is created. So here what exactly was the issue? The issue was with the indentation. Uh the issue was with the naming and that exactly we fixed. Okay. And that is how you do the troubleshooting. So let us quickly understand what was exactly written into the network test file. Here we have defined API version app/v1. What exactly it tells? It tells basically we are trying to create a kubernetes object app/v1 def. And secondly here we are defining kind. So here we are telling Kubernetes that we are going to create an resource of type demon set. And then uh what would be the name of the demon set that is nothing but network test. Now here we have we 16:12:13 are defining the settings the specification for demon set right and for that demon set what are the labels that we are targeting to. So here we are targeting to the label named network test and then we are giving the template of the pods that it should target to. Now again that pod uh that it should create is nothing but uh by the name web and that container should create uh should be created with the image enginex latest and the labels that should be applied on those container would be uh network hyphen test right now what exactly demon set does demon set basically what it does it will make sure that all it will make sure that at least one container one pod is running on the nodes so that is exactly why we have created we have considered demon set in the very first place. So now what we'll do we'll just uh check whether we are able to see the parts inside the nodes or not. So for that what I'll do I'll just run cube cuttle get pods o wide 16:13:14 because this will give us the name of the nodes along with the pod which are running over here. But again here I will pass one more flag that is hyphen l. Now what is hyphen l here I will pass explicitly for the tags that we are looking for here we are interested for the tag network test enter when I run the same here you can see we have network test running over here and when I do a cat on network test this is exactly what we wanted the app name the labels and selector if you remember this is exactly what we were actually looking for Right? So, uh the actual name and IP address might differ for you. But just notice one thing here. In node number one, we have one port running. In the node number two, we have another part which is running. That is exactly what you need to verify uh verify over here. P IP and the node name may differ in your case. But again, you will get a result similarly like this. Now, let us 16:14:14 actually test the communication across the nodes. So for that again here this time we will make use of curl that will be a client for us through which we would be actually checking the communication for the same. So let me just clear the screen. Now if you remember one thing when we were learning docker at that time we have executed the docker run command. So at that time uh instead of pulling the image from local we will we were actually pulling the image from docker up right. Same thing we have a cube cuttle command uh cube cube cuttle run command. So here I will call curl over here. So cubectl run curl right now again here we will need to define the image. So hyphen image equals to curl images/cull. Make sure you are making no uh spelling mistakes over here. Right? And here I will pass one more flag that is restart and this should be never. Then here we will pass one more command. Now if you remember when we were creating the 16:15:15 manifest file for curl client at that time we were passing two command that was sleep 360 right so hyphen command and the command is equals to hyphen sleep 36 0 enter here it says hyphen command is invalid so let me just verify the name. So cube cut run- f image curl images. Then we are saying that restart should be never. Then we are passing hyphen command. Okay, this should be not here. And here it says sleep should be not there. So let me just check once again. Press enter. It says curl already exists. So let me just delete the current one. Cube cuttle get pods 16:16:16 get pods enter cube ctl delete pod curl because I want to show you everything from the scratch and fresh so that you will have no doubts. So now here it says pod cull is created. So we have created another pod. Uh why I deleted the earlier one? Because since we created a new node, I wanted to show you everything from the start. So now what I will do, I will just run cubectl cube ctl get pods - o wide. And when I say hyphen ovide, you can see there are three pods which are up and running. If I do a little bit of zoom out, it will be easier for us to read. All right. So here you can see we have a client which is running over here. Here we have two demon sets which is actually running two ports into the nodes. In one of the node it is running network test with the IP 10.244.1.3 and in another node that is named as networking hyphen demo. It is running 16:17:17 the pod with the IP address 10.244.0.4. Right now what we are going to use is uh we are going to make use of this IP that is 10.244.0.4. Let me just copy it. And now what I will do from the curl client I will try to ping it right. So I will just run cubectl exact here I want to run curl and hyphen sh enter. Now I am inside curl. Now what I will do I will just run a curl into the this pod right. So curl curl http col/ slash followed by the IP address. Again I copied the entire thing. Let me just mark this as a comment. Clear. Okay. Uh, okay. I just went outside. Let me clear the screen. cubectl get pods - o wide. Let me run the curl command once again. Now here I am inside the curl container. Now what I 16:18:18 will do, I will just run a curl on http/ I will first take the first part and I'll just copy the IP address. Enter. Here you can see we got the welcome to engineix page. Now let me just copy the another IP address from the another pod which is running on another node. So clearing the screen girl on http col// the IP address from the second. Now here again you can see we got the response as welcome to engineext. So if your networking is working we will get the engineext response and that's a very important moment. The client is responding to the pod on another node using the pod IP address. So now let me just tell you what exactly is happening over here. Think about what a cluster has to do. Basically inside this cluster we have two nodes, two machine and inside each node there is one part which is actually running. In one of the node there is a client which is running. In another node 16:19:20 there is another enginex part which is running. So what exactly is happening over here is the client is sending the traffic to the destination pod which are not on the same node. So the packet has to leave nodes one local environment to reach to the node two. So the cluster network is responsible for making podto pod communication across the nodes. I will repeat it once again. The cluster is responsible the cluster network is responsible to make the podtood communication across the nodes. So this is one of the core requirement for Kubernetes networking model and that is where networking implementation on the nodes become very much important and now this is the place where CNI comes into the picture. Now let me introduce a new term to you that is CNI. What exactly CNI? CNI stands for container network interchange. Let me just switch to Visual Studio Code and that is where we would be discussing the remaining aspects. So here let me just scroll 16:20:20 down. So let us discuss about CNI. What exactly CNI? CNI is nothing but container networking interface. Now what exactly CNI is? CNI is nothing but a plug-in. So it is responsible for implementing the Kubernetes pod network. So if I put it into simpler word uh it it is something that is uh responsible for few sort of task. So someone has to create uh the pod networking interface. Someone have to assign pod the IP address. Whenever a new pod is created after deletion, it should be responsible to create the new uh pod IP address. And then it should be responsible for connecting pod to the network and someone have to provide the connectivity between the pods. Who will do that? It will be done by CNI. So Kubernetes itself will define the networking model. But the actual network implementation has been provided by clusters networking plug-in. So in different Kubernetes 16:21:20 environment we can use different CNI implementation. For example, you might have heard about this word helico. You have heard about Celium. You you might have heard about kindnet. So uh you don't have to remember these words. You don't have to be expert of all of them right now. for this uh lesson the most important idea is Kubernetes expects a pod network and CNI plug-in actually helps to implement that network. So Kubernetes documents that the network model is implemented by container runtime at the most common runtimes uh uses the CNI plugins to manage the networking and the security capabilities. Now uh one more distinction over here is uh Kubernetes networking is nothing but Calico but here I will defend on one thing that because that is not quite correct because Kubernetes defines the networking model what exactly I want and CNI plug-in is one of the components that implements that model. So that 16:22:21 cannot be just calico it is one of the segment that actually provides the service. So if I put it into simpler word, Kubernetes just says that I want the part should be able to communicate. There should be a networking implementation. So the networking implementation says here is how we are going to make that communication happen within the cluster. And that is why Kubernetes clusters can use different plugins uh and they can literally provide you good results uh when it come to networking behavior. Right? So at this point I want to reinforce uh something that we just communicated from pod to pod uh using the pod IP. There was no service there was no ingress. We were just underlying on the pod network. But for the application if you remember I was emphasizing on the IP address that pod IP communication is usually not what we want because pods are dynamic and that is why services comes into the picture. So uh portto-od networking was 16:23:21 one problem and there was another issue that was stable application access. So this access issue is been solved by services. So let's connect back to the services session. So suppose we have a backend service the client will call now the backend service and what will happen uh instead of tracking the pod IP address individually he will here we will be just referring to this backend service. So here we have the client pod which will be connecting to the backend service and now based on the request received this backend service will navigate the traffic to the eligible pods which are actually running the application. Is service running uh is service running your application? Answer is no. The application is still been executed is been still run by your pod but service is the point who is actually navigating the uh traffic. it will provide this table part which is actually working the work right working on the work. This is why services are most important in Kubernetes. Let us create an actual backend service. 16:24:22 Let me just jump to my visual studio. Uh let me just switch to my terminal now and here what we are going to do is let me just exit the screen and here I'm going to create one backend service. So vim back end service escape colon uh backend service.ml and here I'll just define the four keywords for any sort of manifest file that we have created so far API version kind metadata and here comes the specs specs specs escape colon wq now again where do we find the API version for service again cubectl here I'll run uh api a - resources and we'll do a grap on service enter and here we have the API version v1 for service let us uh write the same on the manifest file and I'll write v1 over here what exactly is the resource type that we are creating we are creating a service so I'll just 16:25:23 write service now what would be the name of the service so since here we are dealing with the back end so I'll just write back and hyphen service as the service name. Now again what would be the specification for this service? Uh so like for the service if you remember there was one important keyword that I was mentioning earlier that is nothing but labels and selectors. So here I will just write selectors and inside the selector I will define the actual uh um I here I will actually define the label that we are targeting to here this is not selectors this is selector and here I'll just define the value escape colon wq let me just check the value that we have given to the earlier one so here I'll just do a cat on maybe on network test here we were using network test as the label so I'll just use the same okay vim backend hyphen service okay and 16:26:23 here I'll use the same label over here insert mode and here I will make use of network test okay so I will be using the earlier deployment label so that the services know which pod it has to target to now here I will define the ports again so the ports now on which port it will be working so here I will define the service ports it is nothing but 80 and now here I will be defining ing the target port. So target port and the target port is nothing but port number 80. SK WQ. Let me just apply the file first. So cubectl apply -f back end service.l enter. And here we have got uh here we just got a very big error. Let us verify the same. So it's a very big error. So calculating patch from open v3 ports and target port does not declare merge key. There is an issue with target port and second is with the manifest file. Let me just run a cat over here. CA 16:27:24 backend hyphen service. Enter. Okay. Here we have defined the API version. Then we have defined the service. Let me just put it over here. Okay. Here we have defined the API version. We have the kind as service. And then we have defined the metadata as backend service. In this specification, we have defined the selector and the selector is having the same uh labels uh same keywords that we were using that is app cooler network test. Then we have defined the ports and inside okay I got it. The issue is over here whim back end services. Okay, I'll go over here. Here we have defined this ports keyword twice. This is port without s es sc wq. Now let me just apply the file once again. This time the service will get created and it got created over here. cube cdl get svc enter svc enter for service. And here the backend service is created for us. Let me just tell you about the service 16:28:24 file that we have created. Let me explain it to you. So q uh get on back end service. Enter. Now again let me just explain it to you line by line. So here the first thing that we are telling is we are creating a Kubernetes object of version v1. Here the type of service that we are creating is nothing uh here the type of service that we want to create a service that is exactly what we are telling Kubernetes. Then we have uh the metadata and in the metadata we have defined the name of service and that is nothing but backend service and here the service is called as backend service and for that service what are the specification? So here we have defined the specification for the service name backend service. So here it should only target those ports where the value is a network test. So this selects the ports created by the demon set that we have defined earlier and that's the reason I opened the manifest file and check the value from there. Then we have port uh here it says ports 80 and there is a target port 80. So let us discuss about the same. Well, 16:29:25 we had a detailed discussion on this. So I'll just tell you it uh tell about to so I'll just tell it to you once again. So here port number 80 defines that the service listens on port 80 and the target port 80 defines that the traffic will go to port 80 on the back end ports. Right. So now the service is created. Now let's see the service actually is connected or not. So for that we will define the endpoint for the same. So clearing the screen let me just copy the service name. So in order to see the endpoint how will you get it? So basically just run cubectl get endpoints endpoints for the service name backend service. Here you can see the endpoints are actually present for us. Now uh we will run endpoint slices too. So cube cutle get endpoint slices. Enter. And here we will get the segregation of the uh IPs that we have that we are actually looking for. So the endpoint slice object actually contains the backend endpoint information for the 16:30:26 service. So you should see the address of the pods which are selected by the backend service. Right? So here the bridge is between the service and the current backend pod. So Kubernetes will use endpoint slices and it will use it as a scaling mechanism for representing the service back end. So let us test service from the client pod. So let me just go inside the curl pod that we have created. So cube cuttle get pods enter. And here we have the curl port which is currently up and running. Let me just go inside it. So cube ctl uh exact id in the n pod name curl and I'll just do n sh over here sh enter. And now I am inside this curl pod. Now here what we are going to do is instead of using any sort of IP address this time we would be making use of the service name. Now what exactly is the service name that we gave. So basically inside the metadata we defined one name and that name was nothing but back end service. So here 16:31:28 what I will do I'll do a curl on curl on http col//backendy service enter. Again here you see we got welcome to engine page. So noticed one thing earlier we made use of pod ip here we are making use of the service name this is much better for the application because service can keep track of the changing ports. So even at the back end if I delete either one of the pod it will target the another pod and basically here we are not counting here we are not hard coding the IP address basically here the things have been taken care by the services itself. So now uh we have one more improvement instead of thinking about service IP. Kubernetes can provide us DNSbased service discovery. That means application now can use backend service as a host name instead of the IP address. This is what we normally want in application configuration. So 16:32:29 Kubernetes provides the DNS records for services and pods and pods are configured in such a way so that they can look up to the services by their name itself. So now let us do a final end to end experiment that we did so far. Let me just go outside this part and I believe this tutorial will literally open up uh all the concept to you because uh literally whatever doubts that you might have with the networking so far that port uh that how does port connect with the another pod uh in the single node how does the port from uh node one connects to the port to the another uh another node. So that is exactly what was the purpose for creating this video right. So let us u use uh the two node cluster that we have created. So let me first run cube ctl get nodes and here I will be listing the two nodes that we have that is networking demo and networking demo m02. Now uh here we have two node. Now let me just list all the pods with the label name network test. So cubectl get pods 16:33:31 get pods hyphen o wide because I want to see the IP address and hyphen l down all the pods with the label name uh app equals to network test enter. Here we have two pods. Uh so one pod is running in uh uh network demo m02. Another pod is running on node uh network demo. Here we are using demon set because we want a pot to run every time on every node and that's the reason we made use of demon concept. So like it is a kind of revision uh for us also right. So now uh we have verified two things. We have two nodes right now with us and secondly we have two pods which are running inside either of the nodes with the label as app equals to uh network hyphen test. Now uh once we have the back one backend pod per node then let us list the service that we have. So cubectl get svc and when I press enter we have 16:34:35 the backend service over here with the cluster IP present as 1000.251.154. Now from the client let me just go inside the cull part that we have created. So cube ctl exact - it and here I'll just write the name of the pod curl - sh. Now I am inside that pod and here we will be testing the uh changes that we have done so far. So now let me just do the test with the first thing that is with the IP. So now let me do a curl on http// let me just take the IP of any one of the pod. So let me just take the IP from networking demo m2 node. And here when I paste it and when I press enter I am getting the output as welcome to engineext. Clearing the screen. This time we proved that okay we are able to connect to the pod. Now the next test that we are going to do is here instead of pinging to the IP address here we 16:35:36 will uh here we will directly ping here we will directly run a curl on the backend service. So curl http col//backendy service enter and again you can see we got the engineix welcome page in front of us. So in the first command it depends upon one specific ID in the second command it depends on the service. Now what we are going to do is we are going to delete one backend pod. So let me just do an exit. So clearing the screen cube cuttle get pod abide with the label app network test. So cubectl delete pod. Uh one second. Let me just delete another pod instead. cubectl get pods. Enter. And let me just delete this network test. cubectl delete pod pod name. Okay. And now let me just go inside uh this thing and 16:36:37 before even that let me just list the IP address for the same cube cut wide with the network L test over here. Earlier uh we did a test on different pod and now I deleted this part which was present 5 JHF. Now instead of that we have this LGC67Q created and it has the IP address as 10.244.1.5. I'll again go to cull pod and here I'll just do a curl on the new pod which is created. So http/10.244.1.5 enter. And again we are getting the output. Exit. And this is what I wanted to demonstrate in front of you. So uh we have deleted the pod and what exactly happened now since demon set were running at the back end it created another pod on that specific node. So demon set is actually doing its job and it actually proved that demon set is working and secondly we pinged on the new IP for the new pod and again we were getting the output and from the client 16:37:39 also we tried to ping the service and we were also getting the output. So this proves that the service is working, the demon set is working and we are able to ping to the uh IP. So here we combined a demon set, we combined the power of pod networking, we combined the power of service abstraction and DNS. So instead of hard hard coding the IP address, we actually are making use of multiple offerings done by Kubernetes. Let me switch to uh my Visual Studio Code. And this is where we come to a conclusion and this was one of the important parts that uh we have come across. So the entire progress that we have done so far was uh we did the container to container communication. We did the pod communication. We did the communication across the pod for the across the node for the pod and then we understood what exactly is CNI container network interface. Then we understood about service. Uh we understood about DNS. And these are the uh pieces that 16:38:40 actually makes Kubernetes networking very much easier and less mysterious. And one final statement that I want you to remember uh before closing this video that container in the same part can communicate through their shared network name space. Pod can communicate through the cluster pod network. Third is service provides a stable access to the changing part and the DNS lets the application find those service by the name. So yes that was all in this video. I hope you have learned a lot about networking. All your doubts about the communication between the ports between the container are now clear. If you have any doubt feel free to write into the discussion section into the comments and I will definitely help you out with this. So yes, that was all in this video and I will see you in the next one. Until the next time, keep learning and thank you very much. Hey everyone, welcome back. So in the previous video uh of Kubernetes networking, we have literally covered 16:39:41 services. We know what exactly cluster IP is, what is node port, what is load balancer. We now have a good understanding what exactly services does, what exactly ingress does. Today we are going to learn about gateway API. So now I'm considering that you don't have any idea about gateway API. So we are going to learn everything from the scratch. So we are not going to make any complicated YAML here. Everything will be very much simpler for you to understand. And also there is one small topic that I didn't cover earlier but it is important for us to learn today that is annotation. So since we are already aware what ingress is we are going to cover annotation right and once we are done with annotation we'll move and we'll start our journey with gateway API. So we'll actually create the resources, we'll test it, we'll see what exactly happens and once we understand the approach of annotation uh we'll understand what exactly are the limitations and then only we'll start a journey with gateway API. So uh on that note let's get started. So let's first 16:40:42 understand what are the problem that we are solving right now. So let's imagine that we have an application consist of front end and backend service and each application is running inside Kubernetes. So uh whenever someone accesses your front- end application so the request will go to the front- end service and it will actually forward it to the eligible ports. Likewise uh if the request goes to the backend application it will send the request to the backend service and backend service will forward the traffic to the eligible backend ports. Now imagine that the users are coming outside from the cluster that is from the internet. So let's say if you have your host names for example here we have shubhhamgod.com so whenever someone type shabbamgod.com it should navigate the traffic to the frontend service and from front-end serve it should go to the front end ports likewise if someone hits to shabbanggod.com/appi it should go to the backend service and backend service should navigate the traffic to the eligible port. So basically in the previous video we 16:41:44 understood that this can be solved with the help of ingress with the help of path based routing and hostbased routing. Now imagine that our back end application doesn't actually understand what exactly slash API is. Maybe it only understand what is slash right. So then here we see a problem and that's the problem that we are going to address. So before even we start our journey let us first create the initial thing that we have created so far that is we would be creating the deployment and services and we are actually going to see what was the actual blocker for us and then we'll move forward with annotation and then we'll start our journey with gateway API. So let us create our application. We'll start with front end first then we'll start with back end. So let me switch to my uh item and yes here we are. Okay, let me just do a list. Okay, so there is a readme.md present where all the things have been documented. All the helm commands, everything is present 16:42:44 over there. Now, where I am taking the helm commands from? So, I'm taking it from the official documentation. So, if you want you can just verify the same from the helm documentation or else you can follow along with the readme.md file. All right, which is something that we are going to refer throughout the video. All right. So, let me first create the front end deployment. So vim front end deployment dotyl enter. All right. Now whenever we are creating any sort of resource in kubernetes what are the four keywords? API version kind metadata and spec. So let me define the same API version kind metadata and spec. All right. Now again uh if we are creating any resource. So here in our case the resources nothing but the deployment. Now if I want to know what exactly is the API version that I need to check where I can check it from basically you can go to Kubernetes documentation that is the place that is the legit place where you can get the information from or if if you don't want to leave your console if you want to 16:43:45 check everything from your console itself you can just run uh cube petal API resources and then you will be able to find the API version and the kind for the same. Let us follow the console approach because I don't really want to leave my console. So cubectl api- resources and when I do a grap on deploy here you can see the API version for deployment is present along with the kind that I should use in the YAML file. So I'll again go to the manifest file. Now again you might be hearing two terms from my end that is I'm referring to YAML and then at the same time I'm saying manifest. So what is the difference? So YAML is a generic word that we usually use. But what is the correct term? What is the correct term that we should use for all the YAML files which are present in Kubernetes? All the YAML files which are used to create any sort of resource are referred to as manifest file. So if you hear this term manifest, they are talking about these YAML file only. So 16:44:46 yep, let me just add the API version. So it's nothing but app/v1. Now here in the metadata let me define the name of this deployment. Now since this is related to the front end serials I'll just write front end over here and yes now let's move forward in the specification. Now here since we are working with deployment let me define the replicas because this is something that it will make sure that these number of count are actually been present over here but on what basis here we need to define the labels so that the deployment know what all pod it has to target right so based on the selector it will try to match the label and the label can be anything so since it is a front- end application we are trying to create So here I'll just define it as app front endent. So whenever any pod with this label has been present then it will make sure that okay uh it will bring it 16:45:47 into the deployment. So whenever the template whatever we are passing it should match the labels from the selector and it should match the labels from the labels also. So now once labels is done let's move forward with creating the template for the parts. So it will just fall below the section of the uh selector. So making sure of the same template and yeah feel free to use Visual Studio Code because that will help us with the indentation. Uh I'll I'll be using Visual Studio Code later in the segment because uh that's where we'll understand why exactly that tool is very much helpful for us. Uh right now I'm comfortable with the terminal. So I'll just create it. whenever we face any issues while creating the AML at that time we'll switch to visual studio board. So yeah let me define the metadata for uh the pod template. So meta data now here in the metadata the first thing that we need to define is nothing but the labels. Now labels for the application. So that's the reason I'll just copy the exact label which are present over here. And here we have 16:46:48 defined the labels. And now just below the metadata here we'll write the specification. Now here uh just note one thing here we have two specification. First specification is actually for the deployment. Second specification is for the template that we are creating for the pod. Right now again in the specification what all things we should create. Now since this is the template for the pod here we need to write all the specification for the pod itself. Now what exactly runs inside the pod? It is nothing but the container. So containers and here I'll define the name of the container. Now here you can give any random name for uh your container. So here I'll call it as front end. And now here I need to pass the image image. All right. So again we would be making use of engineix again because that is something that helps us with the visualization for networking. So that's the reason we are making use of engineix over here. Now lastly the thing that we would be using is nothing but the ports. So here I'll define the ports and let me just define the container port for the same. So here engineix runs on port 16:47:50 number 80. So container port container port is nothing but 80. Escape colon wq escape colon wq. Let me just turn off the gaps lock. Okay let me just apply the manifest file. So cubectl apply f front end. Enter. And here it says the deployment is created. Let me first explain you each and everything uh whatever we have created so far. So let's start with the first one that is uh API version. So what exactly API version signifies? It specifies the QB cubernetes API version. Second, we have nothing called deployment. So it specifies that we are trying to create a deployment. Then here we have metadata. So inside metadata, we have defined the name of the deployment and then we have specification. Now these are the specification for the deployment itself. Now what does it says? So here uh we are defining uh the desired configuration for the deployment and here we are telling that it should create two replicas of the pod that 16:48:50 should be up and running. Then here we have defined uh which pods the deployment should manage. And then finally we have defined the match labels which selects the pods based on the labels. Then we have defined the actual label that it has to target to. So the pods are managed by the label app equals to front end. Now let's define the template. Now what exactly this template uh uh consists of? It consists of the blueprint for the pods that are supposed to be created. And then we have metadata. So it contains the information of the pod. Then we have the labels. Uh so it defines the labels for the pod. And then in the label itself we have mentioned app equals to front end which is exactly matching to the selector what we have mentioned earlier. So it gives pod the label as app equals to front end. Then again we have defined the specification. We define what should run inside each pod. So the first thing that we are defining is inside each pod we want the container to run. So containers basically here this defines that it 16:49:50 should run a container inside the pod. Then uh we have mentioned the name of the container. It is nothing but front end. Then again if it is running a container then from which image? So we are mentioning that it should use engineix image. And then finally we have defined the ports and the container port. Now what exactly it does? It uses uh engineix image and then it defines the ports used by the container. And then what exactly is container port? It indicates that the container listens on port number 80. That's exactly what we have did. So now uh let's understand uh let's actually check uh whether the deployment is created or not. Now since earlier when we applied the file the it it mentioned that the deployment is created. So let me clear the screen and let me just list the deployment. So cube cuttle get deploy enter. And here you can see it says deployment is up up and running. Now when I run cubectl get pods and here you can see there are two front end pods which are actually running for us. Now likewise we would create the 16:50:51 backend pod and here like it will be again the same thing that we would be doing. The only change would be over here is nothing but the label. So what I'll do I'll just list and I'll just copy the front end pod and I'll just make a backend file for us. So backend deployment doml enter. Now when I do a vim on backend deployment the first thing that I will need to change is the metadata and it is nothing but back end. Now here again in the match labels I need to do few modifications. Remember the only change that we are doing is nothing but the name of the label and the metadata. That's it. So here I'll define the backend part and here in the container I'll define this container name as nothing but back end. So here again we have defined the Kubernetes API object. Then here we are defining the uh kind of resource that we are trying to create. So here we are telling Kubernetes that we are trying to create a deployment. Then here we are giving the basic information for the deployment such as the name of the deployment. So here in 16:51:53 our case the name of the deployment is nothing but back end. Then here we are defining the desired configuration that we want for the deployment and here the desired configuration is that the deployment should manage two replicas and basically when I say two replicas it is responsible to make sure that two pods are up and running. Then here we are defining uh which pods it should target to. Uh now again what rule? So the rule is basically it should match the labels where the app is equals to back end. Then here we are defining the blueprint. Now blueprint for what deployment manages the pod. So here we are defining the blueprint for the pods and it should basically consist the label as app equals to back end and make sure that this app equals to back end matches with the selector and then here we are defining the settings the configuration for the pods. Now what exactly is running inside that pod? It is nothing but the containers. Now what is the name of the container? So here in our kit is it is nothing but back end. Then again we have defined the name of the image. Then we have defined the port 16:52:53 and then we have defined the container port where the application is listening. Escape colon wq. And now let me clear the screen and cubectl apply f backend backend deployment. And I believe uh we are not going too fast because this is something that we have been doing so far. And again I'm trying to uh explain each and every line for you so that you can actually grasp maximum out of it. Right? So now let me just list one more thing cubectl get deploy to verify whether the pods are created or not. And here we can confidently say that the backend uh deployment is ready up and running. Now let us verify the same by running cube cuttle get pods. And here you can see we have two front- end application running and here we have two back end application running. Now whenever I am saying application I'm just referring to ports because that is the example that we have taken. Now if you want to see the labels because that's the actual important thing that we have to keep in 16:53:54 mind entirely. So what I'll do I'll just run cube cuttle get pods hyphen show hyphen labels labels enter and here you can see for the back end pods we have app equals to back end and for the front end pod we have the two labels as app equals to front end right I hope till now you are able to follow. If yes then let's move forward by creating the services. Now we need a service for the front end and we will need a service for the back end. So let us create the same. So clearing the screen vim front end service.ml do yiml enter. And now again whenever we are creating any sort of resource in kubernetes what are the four keywords? API version kind metadata inspect. I'll define the same. So API version kind meta data and lastly is the specification. Now what exactly we are trying to create? We are trying to create a service. So the kind is service obviously but what exactly is the API version? Where will I get it from? So escape wq. Now again I have been telling 16:54:55 you from the starting that you can go to either the cubernetes talks and you can check it into the console. I will tell you from both the method this time. So let me first run cubectl API resources and I'll do a grab on svc for service and I forgot to route grab. So here you can see the API version is nothing but v1 and the kind that we are mentioning is nothing but service. All right now let me show you let me switch to my browser and let me just tell you where exactly you can find the API version. Right. So here I'll switch to my chrome and hopefully screen is visible for you. So what you have to type just write service in Kubernetes. So just write it open the first documentation and here when you scroll down here you can find a live example. So here what exactly the kind they are using? The kind that these guys are using is nothing but service and what's exactly is the API version. The API version is nothing but v1. I hope that made sense and now uh you have a clear idea whenever you don't want to 16:55:55 refer terminal and whenever you want to verify the same with the cubernetes documentation you can follow along the same. So now what I'll do I'll just go back to my service file. So vim front end service.ml. And now let me update the API version. Now again from both the Kubernetes documentation and API resources we are confirmed that the API version that we should use is nothing but v1. Now let us define the metadata. Now here I will give the name of the service. Now since this service is for front- end application. Now I will give the name as front end. So front end service and then we are going to define the specification for the same. Now again uh there is one important concept whenever we are dealing with services and that is nothing but the selectors because labels and selectors does play a significant a major role whenever you are defining services or any resource in Kubernetes. So please don't take it lightly. So let us define the selectors. So selectors. 16:56:56 So here it will tell like what are the pods that you should monitor to and target to. So here I'll define the selector where the labels would be app colon front end front end and then again we would be defining the ports for the same. So ports and here let me define the port for the same and here I will expose the service on port number 80. So here I'll write port as 80. And then again there is one more uh uh information that you need to pass that is uh we will need to uh define the target port. Uh basically uh what exactly that port will do? It will forward the traffic to port number 80 for the selected ports and on what basis we are selecting the port. We are selecting the ports based on the labels that we have defined. Right? So yeah let me just write target port and target port is nothing but port number 80 escape wq. Let me just apply the service. So cube cuttle apply -f front end service doml and here it says there is an issue error from server bad 16:57:58 request error when creating front- end service in version v1 cannot be handled as service strict decoding error unnot field spec dot selectors. So there is an issue somewhere around selector. So let us validate the same and here it says the issue is with this specific line. So here it is not selectors it is selector without s es sk escape col wq. Let me just apply the file and here this time the service is created. Let me clear the screen and let us validate the changes that we have created. So in order to verify uh what are the two methods basically first you can get the service and second is you can describe it. So let me just uh try to run cube cl get svc for service svc and here you can see front end service is up and running. Now likewise uh what we should do we should create the back end service too. But before even that we want to see the IP address associated with the service so that we are confirmed that the service is actually targeting the pods which are 16:59:00 having the label app equals to front end. So how do we verify that? So we can verify it with the help of endpoint and endpoint slices. So how do we list it? So just write cubectl get end point and uh here would be the name of the service and here it is not endpoint it is endpoints with s because it will target all the IPs associated to it. Now if you remember there is one interesting thing that you should observe when I run cubectl get pods - showy - labels labels enter here you can see in the front end pod uh we have defined app equals to front end and these are the two pods which are created and now when I run cube cuttle get pods -0 o white okay here just make note of the IP address So for the first front end port the IP address is 10.244.0.83 and here the endpoint is 10.244.0.83 17:00:02 along with the I uh along with the port number that is nothing but 80. Second IP address for the front end port is 10.244.0.84 and here the second IP address which is listed in the endpoint is 10.244.0.84 along with the port number which is 80. Clearing the screen. Now what does it signifies? It signifies that the service is working fine and it has actually located the pods that it has to target to right now. Likewise, let us create the service for the back end file. We are going to follow the same approach. So, let me just copy the front end service front end service and we are going to create a backend service because both the structures are similar. So, vim backend service and here I'll just change the metadata. So this will be nothing but back end and here in the selector it should target to all the pods which contains the label as app colon back end skw wq. Let me just apply the manifest file cube cuttle apply -f 17:01:03 back end service. Mamel backend service is created. So cubectl get svc for service and here it's you can see backend service is created. Let us check whether it is targeting to the actual pods or not. So cubectl get endpoints for the service name back end service enter and here you can see we have two IP address listed in front of us. Now let us verify the same cube cuttle get pods wide and here you can see uh the first backend part consist of IP 10.244.0.86. So here you can see the IP is 10.0 uh 10.244.0.8680 8680 and the second back end ports the IP is 10.244.0.85 here you can see in the endput 10.244.0.85 port number 80. So here we are done with the service part. We have created two service one for back end and one for front ended. Now what exactly service does? Service will actually uh navigate 17:02:04 the traffic to the eligible ports based on the request received. So why service was created? Instead of application remembering the IP address of individual pod, they will just target the service and the service will navigate the traffic to the pods. That was the reason service was created and I hope you are well aware of it. Right now we verified the same with endpoints so that uh we we are actually 100% sure that the service is targeting to the correct pods. Right? So uh now our application looks like the traffic from front end service will uh flow to front end pods and the traffic from backend pods will uh backend service will flow to the back end ports. Right now we are ready to install the ingress controller. So for our annotation demonstration uh we are going to make use of engineix ingress controller. Now there are different ingress controller that comes in market but for this demonstration we are going to make use of engine ingress. So we will need to install ingress controller 17:03:04 because uh with the help of helm because ingress resol itself contains routing configuration. So for that we need to make use of helm. Make sure helm is installed in your system. Now let me clear the screen and where you will find the installation command. Well basically you can find the same from uh the md file and let me just show you where you can find it. So here are all the manifest file that we were working so far and yeah this is the uh helm command that I'm referring to. So let me just explain you each and every line what uh exactly it means right. So first of all let me just uh paste it. Now here what exactly is happening is here uh it says helm install ingress enginex followed by the name of the resource that we want to install. Then here we have defined the repo where the files are present where all the information where all the binaries are present. Then here we are installing it in the name space name ingress engineext. And then finally we are firing the command for creating the namespace. Now here you can see I am 17:04:05 getting one error. Now why? Because uh I already have ingress installed from my previous video. I didn't uninstall it. So in your case if you haven't installed it so far then you will not get this error. But if you have already have if you already have helm installed in your system along with the ingress controller then you might get similar sort of error. So no worries on that. So how do we verify whether this actually exist in those system or not. So here we have a command called cube cuttle weight in the nameace enginex ingress. So basically what it does this command is actually tells whether the pods which uh pods for the engineext controller in the namespace uh ingress engineext is ready or not. So if it is ready then you will get this message as condition met. Basically what it checks it checks whether the condition for the pod is ready or not. Right now once everything is done let us verify the pods inside the ingress engine name space. So cube cuttle get pods 17:05:07 get pods in the name space ingress engineix. And here you can see there is an inject controller which is up and running. Right. And now let us verify uh whether this service is also present for the same or not. So let me run cube cuttle get service in the name space ingress. Okay one second ingress engineext enter. And here you can see the service is of type load balancer. And here there is an external IP which is pending over here. Now why we are getting that IP address is pending? Does it take some time? Let me run it once again. No, it will be still pending. Why? Because here we are not using any cloud-based load balancer. We are working on mini cube. So because we are working on mini cube that to locally the load balancer service need to be exposed locally. Uh so how do we do it? So basically we have something called mini cube tunnel which you have already 17:06:08 seen earlier. So let me go to another tab and here I'll type mini cube tunnel enter. Here it will ask you for your Mac password. So let me provide the same and here your tunnel will get started. As soon as you start your uh tunnel in your MacBook uh or any device that you are working for. So here it will help us uh here it will act as a load balancer and it will provide us the external address for the controller. So for this local setup we will get an IP address as 127.0.0. 0.1 and this is uh the IP address where our request can enter through the local load balancer. Let me just uh run the cube cuttle get service in the namespace ingress enginex once again. And here you can see this time we have the IP address as 127.0.0.1 which is acting as an external IP address. Earlier it was pending. As soon as we started our mini cube tunnel, we are getting this IP address. So that was the purpose of uh mini cube tunnel. Now let us configure the Etsy C host. Now if 17:07:10 you are coming from the previous videos, we have already uh defined the configuration in Etsy host. Let me just show you the same. If you haven't done it so far, so feel free to uh do the same. So here let me just do a cat on /host and here I'll run it as sudo because it will ask for admin password. Let me just provide the password for the same. And here there is uh one entry which you can see and here we have defined the IP address as 127.0.0.1 which is exactly same as the external IP that we got after turning on the mini cube tunnel. Second is the host name that you have to provide. So in my case I am writing my own name as shubang.com so that it is easy for you to understand what exactly we are dealing with. Feel free to experiment the same with your own name with whatever creative name that you want to do because that is how you will be learning right in order to make things easy for you. We are using some random names. You can also write example.com you can also write shop.com. 17:08:12 It depends all up to you. Right now there is one important thing uh that is the host name will resolve to 127.0.0.1. So for the actual ingress testing we'll be using HTTP rather than relying on ping. Right? So let us create ingress finally. So vim ingress dotl enter. Now again ingress is also a sort of resource type in kubernetes. So here we will be writing four keywords API version metadata and spec escape wq. Now where will I get the API version for ingress? Now again you will have kubernetes talk. So you can uh you make you can make use of API resources. I'll make use of API resources. So cube kit API resources for ingress. Enter. And here we have the API resource for ingress that is 17:09:13 networking.k8s.io/v1. And this is the name of the kind. Let me just go inside my ingress file once again. And here I'll update my ingress file. Okay. Now what exactly? Okay, my bad. Let me just go into insert mode. This will go as ingress. And here we will need to update the network key identity. I need to copy it. Okay, Ctrl C. And now let me just paste the API version over here because that is something we as a human cannot learn, right? Because there are multiple uh multiple resources that you would be creating in Kubernetes, right? So for that sake uh it's very much uh it's so for that sake it's a good practice to rely on documentation and on API resources those are sufficient enough for us to understand the main thing that we need to understand is basically how does things are working and how do we create it right these small information such as API version you can remember it at a point when you are doing work regularly but for a normal human it's 17:10:15 very difficult to uh remember all the API versions right so that's the reason the documentations are created for right so now let's move with the metadata section so here we will set the metadata for this ingress now what should I name this metadata so here we will call this ingress as uh let's say application ingress application ingress so this would be the name that we are giving to that specific uh uh you know uh so this is the name that we are giving to the ingress now let me define the uh ingress class name. So where do I get the ingress class name? So let me just run skq cube cl get ingress class enter and here you can see the ingress class name is nothing but engineext. This is something that we would be using over here. So whim in this specification I will need to define the ingress class name and ingress class name is 17:11:16 nothing but enginex in name. Right now let us define the rule for the incoming traffic. So here I'll define the rules. So rules. Now here we are defining the rules for what? Here we are defining the rules for uh the host that we have defined. So here I'll write the name of the host hostup.com. Right? So this is the host name that we have defined. Now the next thing that we need to define is the uh rule that specifies uh the HTTP traffic. So here I will define the rule for the same. So uh we have defined the host. Now let me define the rule for HTTP traffic. So here inside the host I'll define HTTP and here I'll define the rules for HTTP. Right? So here I will define the path. So here we would be doing pathbased routing. So path would be nothing but uh here I will define the path for the same and here the path that we are talking 17:12:16 about is nothing but slash and then just below the path we will define the part type. So what exactly is the part type? So path type I hope I'm correct with the spellings if not that we'll get error so we'll fix it. So here the part type can be anything it can be prefix it can be implementation specific now based on the use case. Now here since we want to match it with the path and any path which will be below it we will be make use of prefix that we made use of earlier. So prefix and then let us move forward and let us define the uh uh back where actually the request should match right. So here I'll define back end and here it should navigate the traffic to the service and that service is nothing but a front- end service. So here I will write the name of the service that is front end. Front end - service and here we have defined the name of the service. Now let me define the port for the same. So that service actually runs on port 17:13:18 number 80. So here I'll define the port and the number is port number 80. Right? So that's it. Escape col wq. Let me just verify the file. So cube clearing the screen cube ctl apply -f ingress.l ML ingress.ml here we are getting the error error from server as bad request error when creating ingress ingress in version one cannot be handled as ingress JSON cannot be norm unmarshall object into the go struct so basically I think there is an issue with the indentation with the field http ingress rule value spec rules ingress rule value for http parts let me just do a cat on ingress test. So parallelly we'll just uh try to troubleshoot it. It says uh HTTP ingress rule for spec rules. I think the issue is with the service. This service should be in lower 17:14:20 case. So ingress.ml let me just mark it as lower case. This will go and here it comes as smaller case wq. Let me clear the screen and I'll apply the manifest file again. Again we are getting the issue. Here it says HTTP ingress rule value spec rules. Let me just do a cat into ingress once again. Okay, here it says the issue is somewhere rel nearby rules dot rule spec rules and then ingress value HTTP paths. So HTTP paths somewhere nearby. So what exactly can be the issue over here? P A HS paths and then we have defined the path. Oh I guess okay I got the issue basically here we forgot to add a hyphen a dash is required over here 17:15:22 and that's the reason I need to go into insert mode that's the reason we are getting that error. Now this will fall inside it. And now these all will go inside it. Here we have back end. Now it should be good. And this is the number. Now I think we are good. This willfall skip wq clearing the screen. Now let me just again apply the file. And this time finally the ingress is created. So that's why we make use of visual studio code because things become easier whenever we are using it. Right now uh let us list down the ingress. So cube cuttle get ingress enter. And here you can see application is application ingress is created for us. And now let us describe the ingress that we have created. Let me copy the application ingress name. So cubectl describe ingress followed by the name of the ingress. And here you can see the ingress controller 17:16:23 is scheduled for sign. Right. So now when we run a curl - v followed by the host name we should be able to see the welcome page which we s which we saw earlier also. Let me just validate the same. So curl-env http colon/shubgore.comgore.com enter and here you can see welcome to enginex is present. Now let me just go to my browser also and here what I'll do I'll open a new tab http/ubamgod.com and yes we are able to see the welcome to engineix page which was actually expected. Now I'm going back to my terminal. Now uh since this was for the front end part let us update the ingress.l and in the same uh and in the same manifest file we'll define the rules for uh the back end too. Now this time uh I will be making use of uh Visual Studio Code because it will be easier for me to do the troubleshooting. So I'll switch to my Visual Studio Code. 17:17:24 And now here uh I'll open the file ingress.l and I believe uh the file is visible to you. So yes, let me just Yep. Let me just copy this entire path once again and I'll just paste it just below it. Okay. Now what exactly is the change that we would be doing? So the first thing that we would be doing is inside this path we'll just mention the backend API that we want to define. And here in the service name here we'll just write back end. Right? So whenever someone calls the host name shubhanggod.com/appi it will refer to the backend service and whenever someone goes to shubhang.com/ it will navigate the traffic to the front end service. From front end service it will go to front end pod. That's it. So that was the change right? So let me just go back and switch to my terminal once again because I love the terminal more than anything. So yep, here is the terminal. Let us reapply the file. Clearing the screen cube apply f 17:18:24 ingress.ml. And here it says uh ingress.networking k.io application ingress is configured and now we should be good to test the back end also. Now so now what exactly we did? uh we defined the back end rule that whenever someone goes to slash API it should navigate the traffic to backend service from backend service to backend pods whenever someone goes to slash it should go to the front end service from front end service to front end port let's test the same so when I type g htten v http col//r sorry shubham.com/ / enter we are able to see welcome to engineext page all right which is expected now let us test the same and here I'll just type / ai and here you are see you are able to see that we are getting this 404 not found now let us understand why we are getting this now 17:19:26 if I go to my browser also if I just hit shubhham.com/ I will be able to see welcome to engineext but as soon as I type / ai Here we will see 404 not found and but the thing is engineext is running. So let us first understand why exactly we are getting this sort of error right for ingress is currently routing to / API and from / API it is sending the traffic to backend service but if you remember we haven't defined anything into engineix that whenever something comes to / API it should show that page by default all the pages in engineix are been listed in slash that is the root. So the back end service here have two pods. Those pods are running enginex but a normal ser engineext installation serves its default page in the root. So that's why whenever we are moving to front- end ports at that time we are able to see the page but it doesn't automatically come uh with / API and 17:20:26 that's the reason we are able to see 404 not found over here. So what exactly is happening from the browser whenever we are hitting to / API the ingress controller is actually sending the request to the backend service and from the backend service it is going to the back end ports where engine is actually running but since in the root we uh in the root it serves the homepage it doesn't know what exactly/ API is and that is the reason we are getting 404 not found so the ingress routing can be correct but the back end application can still return with 404 error Now let's say our back end application only understands slash we need to change the path before sending it to back end and that's the reason here we will be moving forward with the main topic in this specific video that is annotation. So I don't want to make things uh very difficult. Let me first switch to visual studio code and yes so here we are talking about annotation. Let me go to 17:21:27 my readmi.mmd. Okay. So now let's discuss about annotation. So what exactly is annotation? Don't uh make this term very much complicated. So if you want to understand what exactly is annotation. Annotation is simply an extra instruction attached to a cubernetes object. Now think about it as a parcel box that we usually create. Now let's say in your parcel box if you have regular goods you usually ship it directly but if there are some special cases where your parcel box have few items which contains glass you will add one label that handle it with care and that's spec uh that is the extra instruction that we are giving to the cubernetes with the help with the medium of annotation right so here we are just putting a extra note to that box and we are just saying that you should handle it in a special way because the classes are present. We don't want to break that class. So that note uh that we have added in the box is similar to uh 17:22:28 annotation and that is exactly what annotation does. So in our case we are going to give engineix ingress controller an extra instruction that uh whenever someone goes to / API whenever someone comes to API you should change it before sending it to back end. And that is what an annotation will do in this case and here it will do nothing. it will provide us the extra information right so let us create annotation ingress first I'll go to my uh item over here and now let us first delete the current ingress so cubectl delete-f ingress dotl and here the ingress file is deleted now let me just create a new file for Android so here I'll write vim and node annotation annotation - ingress.ml So here we would be creating the file for annotation now again uh when I say 17:23:31 we would be creating the file for the annotation are we making any other change no basically it will be same ingress file but the only change that here we would be making is we are going to add few special instruction lines so let me just do one thing let me just copy the ingress to annotation ingress file. Now when I do a vim on annotation ingress, we have the entire context over here. Now here in the application ingress itself inside the metadata. This is the exact place where you define the annotation and that would be the extra instruction that you would be writing. So what are the annotations? So let me just write annotations. And here the first annotation that we would be passing is nothing but here we want to enable two thing. First is we want to enable the regular expression for the matching URL. And why we are doing so because we want to rewrite the URL before sending it to the back end. Right? So that's the reason these are the two special instruction that we we 17:24:31 would be writing. Now where do I get this information from? So again I will switch to my Chrome tab and here you can actually find the annotations information. So this is the place where you will get the information for the annotations right and here exactly you can see what all things that I will be using right so these are the two annotation uh information that we would be using. So what exactly we are using here we are telling that engineext ingress kubernetes.io IO we want to make use of reject and mark it as true. And secondly, here we are defining that we want to rewrite the second target. So let me just copy the annotations from here and let's refer the documentation for this sort of thing because it will make our life easier. Right now let me just paste the annotations over here and here I'll just do a little bit of formatting. Okay. So here we have written the annotations. Here we are enabling the reax and secondly in the second statement you can see here we are uh rewriting the URL before we are 17:25:33 actually sending it to the back end services. Now once it is done the second thing that we need to do is we need to check the ingress class. The ingress class here is engineext and then here we will define the rules which are already defined. Let me just delete the remaining path from here which is not needed. So escape entityd. Okay. Now here it's good. Now here uh we would need to make changes into the path because we want to check uh / API in this case. So here in the path section I'll go I'll define the reax that we want to implement over here. Now again this reax information is also present into the documentation. So feel free to check the same. So here I'll define the reax for / API and here we have defined the part type and the part type here is prefix. Now here in this case we want a custom custom rule that we are defining that's the reason here we are defining the part type as implementation specific 17:26:34 implementation specific. Okay. And here we have defined the part type as implementation specific because this tells the engineext ingress controller to handle this part according to the rules. And then we have defined the backend service and things are good for us. Escape wq. Let me first verify the file cube cuttle apply f annotation ingress. ML and it is created. Let me just explain you everything from start because it will eventually make sense for you. So the first thing that we have done so basically we are making use of the same ingress that we have used earlier. So here we are defining the Kubernetes API version. Secondly we have defined the type of object that we want to create in Kubernetes and that is nothing but ingress. Then in the metadata section it's a big metadata section that you have seen so far. So yeah here we have defined the name of the ingress and that is nothing but application ingress. Then here comes the main segment that we should be discussing that is annotation. So here what exactly annotation does? 17:27:36 annotation gives us extra information, extra instruction for this ingress controller. And the first instruction that we have defined is nothing but enable regular expression use reax as true. Then we have defined rewrite target/ dollar2. Now what exactly it does? It rewrites the matching URL and it will send it to the backend service. That's the meaning of it. Then here in the specification we are defining the configuration for that. And again the English should target to which class it should target to enginex class. Then we have defined the rules for the host which runs on HTTP. And here we are defining the path for basically / API. Now here we have defined /pipe dollar and star what exactly it is. So here it matches / API and captures the part of URL that is after / API. For this you don't have to memorize it. You can make use of AI. can make use of the documentation. I will personally tell you to refer to the documentation 17:28:36 because that will actually give you a complete idea. Just one second. I think my screen is freezed. All right. So, uh we were in / API and I hope uh this is uh understandable to you. Now, we have part type as implementation specific. Now, what exactly it does? It lets the engine ingress controller to handle the parts according to its rule. Then we have backend. So what basically this back end does it defines where the matching request should start from should be sent and then here we have defined the service. Now this uh basically defines which service we are talking about. The service name is nothing but backend service and here we have defined the service port which is actually been utilized by the service. Clearing the screen we have already applied the annotation ingress. Now when I run cube cuttle get ingress enter. Here you can see application ingress is now up and running. Now let us describe this annotation ingress so that we will get an idea what exactly it is doing at the 17:29:39 back end. Now here uh when I run cube ctl describe ingress application ingress here we have tons of information. So here let me just tell you what exactly is this. So here we have defined the name of the ingress uh that we are actually using. Then secondly what we are doing is here we have uh here basically the labels what does it signifies that there are no labels assigned to this ingress. Then here what exactly the name space we are using? We are using the default name space and then the address. Now what exactly this address is? The ingress is actually reachable through this IP address that is 127.0.0.1 in miniigube which we actually got it from the miniube tunnel. Then here we are defining the ingress class. So where do we get the ingress class name from? So cubectl get ingress class. And here you can see the ingress class name is exactly same as ingress class 17:30:40 which is mentioned over here. Then we have default uh back end. So there is no default backend configured for this specific case. Then here we have the rules. It defines how the incoming request should be routed. And here we have the host paths back end. Right? So this is the specific section where we should keep an highlight for. So here we have the host that we are currently working on. So these routing rules apply to the host name shubham.com. Now the second thing is the path. Now here you can see the reix that we have defined. It matches the request that starts with / ai. Then here we have defined the backend service that runs on port number 80 and also the associated pods IPs are also listed over here. And then here we have annotations that gives us the extra information the label that we were discussing earlier. So here we have two sort of annotation information present uh in front of us. First is for rewrite target which is this one. So what exactly this does? It rewrites the match 17:31:42 matching URL before it is sending to the backend services. And second is use reject. So here it says use reax as true. So it enables regular expression for the matching path. So both are interlink both are actually needed. Now here we have something called an event section which is absolutely very important section. So it isformational for just checking whether we are getting any error. What is the behavior that is currently going on? Then secondly here you can see we have a reason and in the reason it says a sync. Now what exactly is the meaning of that sync? So here it says the ingress controller is synchronized for the uh for the uh configuration right and then here we have from. So here in the from you can see and in the from section you can see ingress engineext ingress controller. So what is the meaning of it? So here it says that the event was generated by engineix ingress controller and then here we have a message called scheduled for sync. What is the meaning of scheduled for sync? It's it tells 17:32:44 basically the control is scheduled for the ingress configuration for the synchronization. That is exactly what is the meaning of this entire description. Now what exactly is annotation doing over here? Let us discuss the same because that is the significant part over here. So now let's don't worry about what exactly the spelling is. Just look at the idea what we are actually doing. We are giving engineext controller. We are giving engineext ingress controller two instruction. First instruction says that change the request part before sending it to the back end. And second says that use special path pattern that is reax equals to true. So whenever an incoming request comes to the host name shubhham.com or your website.com and if it hits to / API it will go to ingress controller. Now because of annotation it will rewrite the request to slash and it will go to back end from back end it will go to backend pods and from backend 17:33:44 pods the containers are running and we will be able to see it live in front of us. So the back end will receive slash information where the engineix page is hosted and that is how we will be able to serve the welcome to engineix page for us. Now let us test annotation because it's been too long we have been discussing about the same. So let me just clear the screen and let us do a curl-env on http/hung.com/api. Now when I press and enter this time you can see annotation actually worked. I head on / API this time we are getting this this time we are getting 200. Okay we are able to see the welcome page. Now let me switch to my chrome browser. Okay right now you can see it is 404 not found that is the result from the earlier result. Now when I just press it enter you can see welcome to engineix page again present over here. If I press enter once again here you can see again we are getting that result. Why? Because 17:34:47 this is the reason why we are learning annotations in the very first place. And that's actually prove that annotation works. What actually annotation is? It gives extra information a special label to the box that we are working with. What is the pod? Uh what is the box in this sense? Here the box is nothing but the pods that we are working with. Now let us go through the request one more time because since we are discussing about annotation the power of it uh let us understand what exactly happened behind the scene. The user in this case is me. So what exactly happened the user requested for / API the request is to engineext ingress controller and the controller read or extra instruction that we have defined. If I just clear the screen and if we go back to describe application ingress, these are the two special instruction that we are talking about. So based on those two special extra instruction it changed slash API to the root that is nothing but slash and it sent the request to the backend 17:35:47 service and the backend service sended the request uh basically and the backend service received the slash request because of the annotation and it returned the normal page to us. That is the practical meaning of annotation. Now I have been emphasizing on annotation and there is one more thing that if you have observed is if my if I clear my screen and if I just do a cat on my annotation file. One second. Cat on annotation ingress file. Here we are defining the annotation is in metadata. And if you remember we were defining the labels also in uh in metadata section. What is the difference between annotation and label? So both are very different thing. You already know what exactly labels are. Labels are useful for identifying the resources in Kubernetes. For example, earlier in deployments. Earlier in services we have been making use of app equals to front end. So what exactly it does? It 17:36:48 actually helps the service to find the ports. It helps the deployment to keep the track of the ports. Right? An annotation here in this case is difference because annotation gives extra additional information uh to the tool or the controller. So just remember labels are used to identify and select the parts. Annotation is used to give extra information or instruction to the controller. That exact differentiation that exact instructions is very important for us to understand. Labels and annotation both are very different thing. Both have their own use case but both are defined inside the metadata section. That's the reason you should have a clarity on annotations and label. Now why annotation became a problem? Let us discuss the same. I'll switch to my visual studio code this time. Now here if I scroll down what was the problem with annotation because it was literally doing good job. Now here the thing is uh here we are 17:37:49 using engineix ingress controller and our annotation is doing something which is understood by engineix. Now tomorrow imagine that we need to uh change this ingress controller with some another ingress controller. There are multiple third party ingress controller which are currently present. But for our understanding we made use of engine ingress controller. So what will happen? uh will that controller automatically understand the exact engine instruction that we have defined in the annotation? Not necessarily because uh the instruction were created specifically for engineix. If you are using another controller, it may have some different set of instruction, different sets of command. So, uh remembering this thing was very much difficult. It was not in a single lane, right? This instructions are actually understood by the controller and that is the important part. So whenever you are changing the uh controller like let's say if you are currently working with engine ingress controller if you're changing it to some 17:38:51 other controller what will happen in that specific case the instruction will be changed and it should be something like it should be understood by the controller. So this is the reason why it led us to gateway API. Now I hope you are able to see the reason why we are moving from annotations to uh gateway API right you can see uh the reason why we are uh talking about gateway API so as the networking requirements became more advanced we don't want every useful networking feature to be hidden inside the controller specific instruction so uh we wanted a cleaner and more common way to describe that network and that's Gateway API comes into the picture and now we are ready to start our journey with gateway API. But before even that let us first discuss what exactly is gateway API. So forget YAML manifest for now. Gateway API is nothing but it is a Kubernetes API that helps us in uh 17:39:53 describing how the traffic actually enters a cluster and where the traffic should go. how the traffic enters the cluster and where the traffic goes. How the traffic enters the cluster and where the traffic goes. So that's the basic idea. Gateway API is not one object. It is uh it has different resources for different sort of jobs. But for today we would be focusing on these three important sections that gateway actually has to offer to us. Okay. So let us uh so today we are going to mainly discuss about gateway class, gateway and HTTP route. Each one basically have different purpose and it for each each of them answers a different question. Let us first talk about gateway class. So what exactly gateway classes? So gateway class simply tells us who will manage the gateway. In our example, we are making use of NY gateway, right? So we are telling Kubernetes invoy gateway will be manage 17:40:53 this gateway. Main purpose of gateway class over here is uh just to remember who will manage my gateway right. Second we have nothing called we have gateway. So after gateway we have after gateway class we have something called gateway. So what exactly gateway does? Uh gateway tells where the traffic should enter. What gateway tells us where will the traffic enter. So in our example we are expect uh we are accepting HTTP traffic on port number 80. So uh you can think gateway as the entry point for our traffic and you need to remember that gateway class tells us who will manage it. Gateway tells us where does the traffic enter. Now let us go and move forward with the third and important concept that is nothing but HTTP route. This is one of the famous term that you will be hearing because HTTP route is really very famous um service of gateway API uh one of the subm module. So what exactly HTTP route tells us? It tells us where should the request go. For example, if someone hits to slash it 17:41:55 will redirect the changes to front- end service. If someone hit someone hits API, it will redirect the traffic to the backend service. So when a request comes HTTP route defines uh HTTP HTTP route decides which service should receive that request. So just remember three things gateway class gateway and HTTP route. Gateway class actually tell you who will manage it. Gateway actually tell you where does the traffic enter and HTTP route will tell you where uh where does the request go. So that's the basic idea behind gateway API. Now let us build everything from scratch. So now for that what we will need to do we will before uh we install gateway API let us first clean up the ingress demonstration that we have done. So let me just delete uh let me just go back to my terminal and here we are clearing the screen. So the first thing that I will be deleting is the annotation ingress. So cubectl delete - f annotation ingress and annotation 17:42:57 ingress is deleted. Now let us uninstall the engineix ingress controller that we have installed. So for that uh I'll make use of helm elm uninstall and the controller name is ingress engineext and then I will pass the name space. So in the name space of ingress engineext enter. Now here you can see that specific package is uninstalled. We made use of hen for installation also we made use of hen. So for removing it we are going to make use of the same. Now let us delete the entire name space. So cube ctl delete name space ingress engineics. So all the resources which are present inside it will also get deleted will get disassociated. So uh once it is done uh we should be good. Now let me just stop the tunnel which is also running over here. So we can get we can start with a fresh start now right 17:43:59 we will need mini cube tunnel later but for now let us stop it. So now our ingress de demonstration is finished we are going to start with gateway API portion cleanly. First thing that we need to install is nothing but envy gateway. So there are multiple gateway implementation present. We are choosing NY gateway because it is easier to understand where you can find the details for NY gateway. So basically I'll just switch to my chrome tab and this is the exact page that I am referring to NY gateway and this is something which will give us the extra information. This is something that we would be referring to right let me come back to my terminal back and yes here we are. So how do we install envoy gateway? So again we have in visual studio code you can see the helm installation commands present for installing envy gateway. Let me just copy the same. And here if I go back to my terminal, let me just paste it. Enter. Now what exactly is happening over here? Here we are 17:44:59 telling Helm to install uh NY gateway system and it should create a new name space. Now in my system it is still present. That's the reason it says cannot reuse a name that is still in use. So clearing the screen and now now once it is installed let us verify. So in order to verify we will run the cube cuttle wait timeout command and here you can see uh NY gateway is present and here the condition was it should be available right. So now once gateway is installed let us check uh what all things we have present in the current name space. So cube ctl get ports in the name space NY gateway system enter. And here you can see NY gateway is up and running. Right. So now you can see the NY gateway pod is running. Now let us verify the gateway API resources. So where do we find the gateway API resources? We can get it in Kubernetes 17:46:00 API resource. So when I run cubectl API - resources. So this will be only present once you have successfully installed envoy gateway. So resource when you do a grab on gateway enter ubectl API resource resources enter. Okay, these are all the information that we are referring to for us. Uh, what are the three resources that we should be targeting to first is gateway class, second is gateway and third we are looking for is HTTP route which must be here somewhere in the list. Right? So these are the three resources that we are targeting to. Right? Now let us check the CRD. Now what exactly is a CRD? CRD stands for custom resource definitions which we are going to see later. But for now let us imagine that that you have your application you have to define your own 17:47:00 definitions for creating the manifest file. That is exactly where CRD comes into the picture. So now let us do a grip on the custom resource definition. So cubectl get cd and here we are actually looking for gateway.networking.io ks uh networking ks.io IO enter and these are all the custom resource definitions which are associated with the NY gateway that with the gateway API. So this will tell us that the gateway API defines uh def this will so this will tell that gateway API definitions are installed in our Kubernetes cluster and now we are ready to start our journey with gateway API resources. Now first we installed envy gateway we verified a gateway API resources are present. We checked the custom resource definitions and now we should we should be good to start with the g we should be good to start with the gateway API. We should be good to 17:48:02 start with gateway API. So the first thing that we should be creating is the gateway class. So let me just clear the screen and here vim gate. Let me just create a new file gateway class. This would be the name of the file that I would be creating. Now again uh what exactly uh things we would be needing over here since we are we will be dealing with gateway class gateway and http route these are the three files that we are supposed to create. So the first thing what exactly we would be uh mentioning in this gateway class we will be defining the control name controller name. So what exactly is the controller in this case? It is nothing but envoy gateway that we have installed, right? And where exactly we would be getting the information from? We would be getting the information from the official documentation of envoy gateway. Right? I would be utilizing that documentation so that it would be easier for us to follow the same. Right? Now again since this is again a manifest file there are the four keywords that you will have to remember once again and that is nothing but API version 17:49:09 metadata and then spec. Now again uh since we are defining the gateway class what would be the API version? Now since this is a freshly installed add-on that we have done in Kubernetes, let us do a grab on the same. So cubectl API resources, we'll need a grab on gateway class. When I press enter here, we'll get the API version for the same. And here you can see the uh kind for Kubernetes 2. when I do a vim on gateway class I'll define the API version here in this case and that is nothing but okay let me just copy it once again the kind is gateway class escape colon wq let me just copy the API version okay and here is the API version for the same so here we have defined the API version as gateway networking k8s io/v1 and here 17:50:10 we have defined the gateway class now what would See the name of this gateway class. Let us give any name. Um let us give example for now. We can change it later also. And in the specification we will define the uh configuration for this gateway class whose name is nothing but example. Now here in the specification it will expect us to define the controller right. So controller name and what exactly and where we will get the gateway information controller name. For that I will switch to my chrome and this is the exact value that we are referring to that is nothing but the controller name and here I'm getting it in envoy gateway documentation feel free to check out the same and this is the exact value that I will be taking from here. So now let me switch back to my terminal and here I will be defining the controller name. Now what exactly this will do this will actually tell uh kubernetes that invoy gateway will manage this gateway. So once it is done 17:51:12 we are good to go clearing the screen applying the gateway file. So cube cuttle apply -f gateway classamel and here you can see gateway class is created for us. Let me just do a cat and explain you everything because this is something new that we are learning right. First thing that we have mentioned is the API version. So here we are specifying the gateway API version. Where do we get the value from? we are getting the value from cube cuttle API resources. Second uh thing that we have that is nothing but gateway class. So here the kind is gateway class. We are specifying to cubernetes that we are creating a gateway class. Thirdly we have a metadata. So in the metadata we are defining the basic information for that gateway class and amongst them the basic information that we are passing is the name of the gateway. So here we are setting the name of the gateway class to example and then here we have defined the specification and in this specification what exactly are the things we define the settings the configuration for that specific gateway 17:52:14 class. Now inside that we have defined the controller name and the controller name is gateway.nyroxy.io/gateway classy controller. Do we need to remember it? No, you don't have to remember it. you have to go to the documentation, copy it from there and that is exactly uh what we are doing over here. we just have to focus on remembering the implementation rather than remembering the long-term IP address because at the end it won't make any sense because these are the things for that you will have to refer the documentation right so what exactly controller name tells us it tells kubernetes that envy gateway will manage the gateway class so this value is actually coming from the envy gateway documentation which I just showed you since uh we are using uh envoy gateway as a controller we are using that specific value from the name. So we will use the controller name to provide the NY gateway. Right now uh once it is done let us uh just check whether the gateway 17:53:14 class is created or not. So cubectl get gateway class gateway class enter. And here you can see gateway class is actually created for us. And the name here is nothing but example that we have sent. And here you can see the invoy gateway name that we have provided is also present. It says that it's accepted. And here you can see the age of the gateway class. Now let me just describe it. So cube cut describe gateway class and followed by the name of gateway class is nothing but example. There are multiple information over here. So let us go one by one. So the first thing is nothing but the name of the gateway class. Right? And second here is we have defined the name space. Now basically here why you don't see any sort of information because gateway class is not specific to a namespace u gateway class is a clusterwide resource uh so it does not belong to a specific name space. Third u again labels since 17:54:15 you see none basically there are no associated labels that are assigned to this gateway class. Second you can see is the annotation. Now here we haven't made use of annotations. So what exactly it signifies? No annotations are assigned to this gateway class. Now comes the main section that we have defined in the manifest file that is gateway uh API version that is gateway.net networking.k.io/v1. It shows the gateway API version and uh it it shows the gateway API version used by this resource. Then here we have the kind. Now again if you have went to the manifest file now this will be clear for you. what is the object type in Kubernetes that we are trying to create and that is nothing but gateway class. Now here we have the metadata section. So what exactly it contains? It contains the information that is used for identifying the resources. So the first thing that it shows is the creation timestamp. What exactly it denotes when the gateway class was created. Now the second thing is generation one. It shows that the gateway class configuration has 17:55:18 not been updated. That is the reason why it shows generation as one. Now the third thing that we are seeing over here is the resource version and resource version is 72206. Now what exactly it is? It is the internal Kubernetes version for this resource. Then we have UID. What is the significance of this ID? It shows the unique ID assigned to the gateway class. I hope metadata section is clear to you. Now let's move forward to the spec section which is important. It contains the desired configuration the settings that we know we want for the gateway class. Now the first thing inside the specification is the control name. So basically in the controller name we have defined that invoy gateway uh will be actually managing this gateway. Now where exactly this controller name coming from? It is actually coming from the invoy gateway documentation. Then we have something called status. So what exactly this status denoted? It shows the current states of the gateway class. Now here you can see we have condition 17:56:18 and inside consider condition these are the all the information that we can see. So uh what is the condition doing over here? It tells the valid state of the gateway class. Uh last transition time. So it uh basically shows when the current condition was uh changed. So what is the meaning of last what is the meaning of last transition time? It it tells basically when was the last time uh the current condition was changed. Second we have message uh which shows as valid gateway class. It confirms that the gateway class is valid. Third is we have observed generation as one. It shows that the controller has processed generation one meaning no changes has been made so far. Then the main important section that you have to keep in mind and that is nothing but the reason as expected. This is something that you have to verify every time. Now what is the significant significance of it? It shows that the gateway class has been expect has been accepted by the controller. Then status is equals to 17:57:19 true. What is the meaning of it? It shows it confirms that the conditions are currently true. Then type accepted. Now what is the meaning of this accepted? Basically it indicates that the gateway class has been accepted by the controller. And lastly events. Now you are already aware what exactly event tell. It tells that there are no events associated to the gateway class. Now we have gateway class pointing to the NY gateway. So the first piece is ready. We made use of gateway class and the controller that we would be using over here is NY gateway. Right? Now once we are done with gateway class, let us start with the second segment that is nothing but gateway. So for that again we will need to clear uh we will need to create a manifest file. So vim gateway dol enter. Again since this is again a resource we will need to define API version meta data and spec escape col wq. Now again 17:58:21 uh where will I get the value for API version for gateway uh for API version for gateway. So basically I will run cube cl api- resources. We'll do a grab on gateway and again uh here you can see gateway class and gateways both follow the same API version that is gateway.net networking.k8s.io/v1. I will again go to my uh manifest file and this is the place where I will be updating the API version. Now what sort of object we are trying to create? what are sort what sort of resource we are trying to create we are trying to create a gateway that is something that we would be mentioning in the same now what would be the name of this gateway right so again the gateway class name is example I'll give the same name to this gateway and next thing that we would be defining here is the specification now the first thing that you will have to define over here is the gateway class name it should be mapped with the 17:59:23 gateway that's the reason it is required over here so gate gateway class name and the gateway class name is nothing but example which we just created before creating the gateway class. Now here we will need to define the listeners. Listeners l s e n e r s listeners. Now what are uh what exactly is listener? Basically we will tell on which are uh the rules that actually are used. We will be actually defining it over here. So listener so here I'll write the name. So here the listener is basically HTTP and then let me define the protocol. Proto call is HTTP and then again we will define the port on which this um listener is listening. So port is nothing but it listens on port number it escape colon wq clearing the screen. cubectl apply f gateway and it is created. Let me explain you 18:00:24 what we did just now. EML. Okay. So here we have defined the API version for the object that we are going to create for gateway and kind defines the type of object in Kubernetes that we are trying to create. Then here we have given the name as example to the gateway. Then we have defined the gateway class name. And then we have defined the listeners. The name of the listener is HTTP. The protocol is HTTP. listen on port number 80. Now if I put it into simpler words, we are saying uh to Kubernetes that use gateway class as example. Then we are creating a listener and then we are saying that the listener listens on uh port number 80 and the protocol used HTTP. So our gateway is actually listening to HTTP traffic on port number 83. Uh port number 80. So now let us validate the changes. So cubectl cube cl get gateway 18:01:27 enter and here you can see the gateway is created here there is one important question one important thing that you have to uh see that is the class the name here of the gateway is example and the class name is again example that is something that you have to put your focus on that you have to keep in mind uh the next time because these are the values that we would be referring later right Now let me just describe the gateway now. So cubectl describe gateway and the name of gateways example. Now here you can see entire information related to the gateways present. There is one thing that you have to see that is the supported kinds. Here you can see we have defined the group as http route and second thing that you need to see here is the reason that is accepted. Right now that is exactly what we have to check. Now what is happening behind the scenes? Remember we didn't manually created NY proxy. We simply created gateway. NY gateway is 18:02:29 watching or gateway resource and it sees that gateway class is example and the gateway is also example and it creates and configures the infrastructure required for this implementation of the gateway. This is a common Kubernetes pattern that you will observe. So we will describe what we want and the controller will actually make it happen. So this is exactly what we have done. Let me just clear the screen. Now let us inspect the cluster first. So for that let me just list all the ports. Cube cuttle get pods a. So these are all the pods which are currently running. So here we have few back end and front end pods that we created earlier. Here invoy proxies invoy gateway is running and here these are the cubernetes resource which are currently running. Okay. Now let me just list down all the services which we have currently handy. Cube cut service. Here we have a backend service, front end service, invoice service, gateway service which are currently running over here. Now uh we should see 18:03:32 the gateway. So let me clear the screen. I think we should be good to start with the third approach. So the first thing that we created was gateway class. Then we defined the gateway. Now let us start by creating the HTTP route. So here we are going to connect it with the gateway for the front end. So let me create vim http rotamel. Again http route is again a manifest file. So I'll just use the same api version find meta data and spec. Now when I do escape col I will get the resource type. So cubectl api- resources and I'll do a grab on http r enter and here for http route you can see the api version is gateway networking k test.io same as we used in gateway class and gateway so here I'll define the API version for the same. Now 18:04:34 here the kind is http route. So, HTTP route. Now, here what would be the name of this HTTP route? So, let us define the name for the same. Uh, now since we are creating the HTTP route for front- end service. So, let us name it as front end front end route. So, this would be the name of this route that we are creating. Now, here we will define the parent reference uh parents parent ref. So this specifies which gateway is uh this route should be attached to right. So parent refs let me just complete the file first and then I'll explain to you line by line that would be better. So here in the parent ref I will define the name and the name would be example and here the next thing is we would be defining the rules in the HTTP route because this is the place where it will match the path. So rules should match 18:05:36 and rule should match the path and the path should be inside the matches. And what is the path that we are trying to match? It should be path of type path preix. And the next thing inside path prefix V is basically the value where the traffic would be navigated to. And then we would be defining the backend references which will be just below the matches back end references and this is basically telling the name of the service. So front end service and on which port this front end service listens to it listens to port number 80 escape colon wq. Now let me just apply this file and I will explain you everything in simpler language. So cube 18:06:36 ctl apply - f http route enter. Here we are getting an invalid error over here. Let me just verify the same cat on http route. Okay, here we have defined the gateway networking. Then we have defined the name as HTTP route. Then we have defined the metadata as front end route. Then in the specification we have defined the parent refs and okay. So here the issue is with parent ref. So it should be in caps. Ecape colq applying the file once again. Okay. Now let me explain you everything line by line. So let me just do a cat on http route. Okay. So here we have defined the API version as gateway.net networking.k.io/v1 which specifies the GDP API version. Second we have the kind that is HTTP route. So here we are specifying to 18:07:37 Kubernetes that we are trying to create an resource and object in Kubernetes by the name HTTP route. Then we have defined the metadata. So here in the metadata we have defined the name of HTTP route and that is nothing but front end route. Then the in the specification we are defining the exact configuration that we need for this resource which we are trying to create in Kubernetes that is nothing but HTTP route. And what are those configurations? So the first configuration that we are mentioning over here is parent refs. So this specifies the gateway uh this route should be attached to and it should be attached to the parent references where the name is equals to example. So it will attach this u so http route will attach this to the gateway and the gateway name is nothing but example and then here we are defining the rules for the incoming traffic and then we are matching the rule based on the path for the URL that we are providing. So here in the path you can see we have mentioned path prefix. So it will match 18:08:38 this specific path and the paths below it right and what is the value that uh that path references will take care of. So it will matches the request that starts with slash right and under the backend reference what exactly it is it is uh basically defining what are the matching requests that it should be sent to. Now again where we are sending the request we are sending the request to the services. That's the reason we have defined front- end service over here. So here the request will be sent to the front end service and then uh the service is actually using port number 80 and that's the reason we have defined the port number 80 in there. So if I put it into simpler terms uh the route says I want to attach uh to the gateway called uh example. I am talking about this. So the route says that I want to attach it to the gateway called example. Then I want the request which comes in to the path beginning with slash and then send it to front- end service right which listens on port number 80 right I 18:09:40 hope uh this made sense to you let me just okay so now since we are done with this manifest file let us apply the file so clearing the screen cube ctl apply - f http route now here it says the uh HTTP route file is configured. Now let me just run a get. So cube cl get http route enter http route and here you can see front end route the one that we have created is listed over here. Let us describe the same. So cubectl describe HTTP route as along with the name front end route and let me clear the spelling describe. Okay, here you can see uh many information but for us the important thing that we need to check is the parent reference and here you can see 18:10:42 the parent reference is nothing but gateway and the name of that gateway is nothing but example right we don't have to memorize this word we just have to understand uh we just to understand the idea what exactly it needs to say which gateway uh do I need to use and that is exactly what parent references tells us so this is most important section that you should check whenever you are describing the HTTP route. So here through this what exactly we can uh tell? We can tell that the route is attached to the gateway. Now second is we need to uh check backend references. So which you will find over here. So yeah these are the backend references that you should be checking. So what exactly this tells? So again uh you don't have to memorize this name. uh it simply tells the route after matching the request where should I send it. So in our case it is nothing but the front end service. So the request will go to the HTTP route. It will send the request to front- end service. From ser front 18:11:43 end service it will send the uh request to the eligible front end ports. So that's the job of backend references. So now let's check the HTTP route for the uh front end route. So clearing the screen cubectl get http route for front front end and uh here I will define the route that we have created front end route and here you can see we can uh see the http route for the front end route that we have created and now uh we have checked the parent reference and the backend reference uh over here right and the month and there is one thing that we need to check when we are done with creating and there is one thing that we need to check when we are done with creating the front end route that is cubectl describe http route as front end route here we need to check whether it is accepted or not and this is the reason that I'm 18:12:43 telling you to check whether it is accepted or not if this reason is not accepted uh basically the routing is not accepting so don't continue testing it first test first try to fix it and then it will be uh good for you. So uh so first try to fix it and then uh try to follow along with the video. Now let us update the HTTP route for front end and back end. Now we have both front end service and backend service. So let us update the HTTP route. Right. So if I clear the screen right now we have uh let me just do a cat on HTTP route. Here you can see we have the HTTP route for the front end service but we need to create it in such a way that our back end is also been supported right. So now for that I will make use of my Visual Studio code once again. Let me just open my HTTP route file and this time I will be making use of the same. Now again uh when you are dealing with this uh there are few things that you have to keep in 18:13:45 mind. One second I'll just show you the screen. Okay. So there is only minor changes that we need to do. So I will just copy the rules and I'll just paste it over here because this is something that we will be defining. Now here we have to design it in such a way that our back end is also supported. So for that I will just update the value to / API and whenever uh someone is hitting to / API we are talking about nothing but the backend service which runs on again port number 80. Then we have defined the path for slash where we are referring to front- end service. So let us understand what exactly it is trying to say. So the first rule says when someone hits to / ai it should send the traffic to backend service such as like your website.com/appi so the request will go to backend service and eventually it will go to backend ports. Now if the the basically second rule which is this what exactly it says it says basically when someone hits your website.com/ it should go to 18:14:46 the front service from front end service it will go to the eligible front end ports now let us apply the changes and let us verify the http route for the same I will again switch to my visual uh for my terminal and here let me just clear the screen cubectl apply F http route enter and here http route is configured. Let me just run a cat. And here we have defined the path prefix for back end and we have defined the path prefix for the front end. Clearing the screen cubectl uh describe describe http route for the route that we have created. It is nothing but front end route. Enter. And here if I scroll upwards here in the backend references you can see the services for backend service which uh uh for basically the rule that we have defined for slash API and again there is a back end reference 18:15:48 for the service called front end service which is actually is listening on slash that is exactly what we need to check over here. So now let's follow the request step by step. Suppose the user request to uh cubamgod.com/appi. The request will reach to our gateway. The gateway is connected to the http route. The http route will check the request and the path over here is nothing but / ai. And here we are talking about the backend service. So it will share the request to the backend service and eventually we will be able to see the changes. So uh next thing is now let's consider if someone is hitting to slash of your website right at that time it will consider the path fix as slash and it will forward the traffic to front- end service. So that is our gateway API pathbased routing. So uh now there is important thing that we should check before uh we start doing the testing. Right now both our front end and back end are running in default engine page. That means even if the 18:16:49 routing is working correctly, we may see the same page for both the application. Uh that would make it difficult for us to create clearly identify which service is actually receiving the request. But before even we make that change, let me first try to uh check whether we are getting the same response right now or not. So when I go to my browser, let me just switch to my browser. So if you see just one second. All right. So if you see when I hit on uh shubgod.com it shows me welcome to engineext. Likewise if I hit on shubgod.com/appi again hitting on/appi it is again showing me welcome to engineext. So let us fix this. And in order to make the changes what we would be doing we will be writing uh uh like whenever we are visiting slash it should display front end uh application and whenever we are reaching to back end it should display the back end 18:17:50 application so that we know that uh exactly the traffic has been splitted to backend service and front end service. For that we need to update the content of our uh you know this uh front end application. So what we'll do we'll just update the deployment file that we have created. So let me just clear the screen vim front end deployment.ml and here what I will do I will just uh run one command right and here under the specification yep just below commands I will just mention the command that I want to execute over here right so inside the container I want to run few commands so let me just specify the same command So uh these commands will be executed in the shell. So I will just define chibbang /bin /sh and here what are the commands that we will need to execute right? So basically we will need to pass the 18:18:51 arguments. So for that I have defined args and inside the ars I will need to pass this c and this will again go as a pipe. So whatever commands that we write over here will be directly flowing through it. So that's the reason we are making use of pipe over here. And again there will be one more hyphen. Okay. And now let me just define the path over here. So here the first thing that we would be running is echo. And here uh whenever someone reaches to slash it should uh say front end application. So I'll just write front end app. And here this value actually should be updated to the engineix default configuration. So where does engineix stores the HTML file? It stores in user share engine html index html. So that's the path that we will be defining. So usr 18:19:52 share engineext user share engineext then inside html we have a file called index html this is the file where it is storing the information and here I'll need to run the command engine g demon of globally we are turning it off demon off and we are done with this let me just verify the command once again. Yes, I think we are good. And now let me just uh apply the file cube ctl apply -f front end deployment deployment.ml and it is configured now. Now let me just list down all the parts cube cuttle get pods and should list based on the uh label. So I have front end front end enter. So here we have two pods for the front end uh basically which has been uh managed by the deployment is listed in front of 18:20:53 us and now both are up and running. We are going to do the same with the backend application too but for the same what I will do I'll just uh take few segments from here. Uh better I move to Visual Studio Code because that will give me good uh hands-on. So I'll shift to Visual Studio Code now. And here I will be referring to my backend pod. But for that let me just copy this segment because this is something that we will be needing in both the section. So let me just go to the backend deployment and just below the image before the ports we will be defining the same command but here this would be a backend app that we would be defining. Okay. Now, same thing has been done. Now, let me just go back to my terminal once again. And now in item, I'm back. And now, let me just do a change for the back end pod. Since we haven't applied it, let me just apply cubectl apply 18:21:56 -f backend deployment.l. It is configured. Now, let me just run the uh backend pod. So let me just check the back end pods whether they are up and running and both are actually up and running. So the changes has been made. We have applied the changes. We have listed it and everything looks fine. So once both the pods are running, we will have the visibility of different application. The front end pods will show front end apps. Backend pods will display the result as back end application. So before testing let's make sure that the gateway has an IP address. So for that let me just run cubectl get gateway. Enter. And here you can see there is no address present. Now this is where u mini cube null will come into the picture because we are using mini cube or gateway service may need a load balancer and if it is an external address it which shows as still pending we need to start another mini cube tunnel right so what I'll do I'll just go and here I'll type in mini cube 18:22:58 tunnel and I'm ready to share uh my password so that it is allowing us to start the tunnel this time once the tunnel is started when I run cube port get gateway we have the IP address present in front of us right so we want the gateway IP to have the address and it should be ready to become programmed now let us use our host name that is shub.com and yeah again it would be the same process I will just do a cat once host this is the entry that you will have to make sure that it is present if not feel free to add it because that is the actual information that is telling your Mac that u we are mapping your uh IP with that uh host name right so it does not create a public DNS it simply tells our computer that whenever someone request for shubangod.com they are actually talking about 127.0.0.1 0.1. Now let's make our gateway listen specifically to this uh host name. So for that what I will do I'll just do a 18:24:00 vim on gateway.ml and here we will need to define the host name. Right. So here just below the specification I will define the host name. If I go into enter mode I'll define the host name and that is shubang.com. That's it. Right. And here we have actually defined the host name for ourself. So escape colon wq cubectl apply -f gateway dot camel enter. Now the gateway is also configured. Now important part over here is the host name that we have defined. We are saying that HTTP listener is uh HTT uh we are saying that the HTTP listener is for the request which is actually coming for the host which is shubhang.com and now we have applied it. Now let us check whether it is programmed or not. For that we will need to describe the gateway. So cubectl describe 18:25:00 gateway and the name of gateway is example. And here let us verify the same. And here you can see the host name is present for us. So that is exactly the validation point the validation checkpoint that we have to check. Now in the HTTP route we will again need to define the host name. So here I will just go to uh basically the HTTP route. So vim http route and here just inside the metadata section only I will define the uh host name for my user. So here in the uh specification just below the parent reference I can actually mention the host name. So here the host names host names is shubham.com. Now the rules are correct and we should be good with this cube apply f 18:26:02 http route doyamel. Okay, a front end route is also configured. Now we want this route to be accepted by the gateway. So for that let me just first do a cat on HTTP route and then cubectl describe HTTP route for the front end route which we have created and here we will need to verify whether the route value is been updated or not. So here you can see the host name for HTTP route is also uh updated. Now let us test our front end. Uh this is the first route that we would be checking. So here clearing the screen curl-env http/shubhhamor.com/ enter and here it says uh 200 connection. Okay, clearing the screen. Let's do it once again. Here you can see we are getting the HTTP route and the basic thing that we are seeing over here 18:27:03 is this message that is front end app. That is exactly what we program. So what exactly has happened the path is slash or http route slash that whenever slash comes the people are actually looking for front- end service. So the request should reach to the front end application and because uh we changed the front end page instead of engineix welcome page we are getting the front end app written in front of us. Now if I go to the browser uh we are expecting the same behavior over here. So now when I'm requesting for shubongod.com/enter we are getting front end app written over here that is what exactly what we were expecting and that is exactly what we wanted to prove. Now let us test the back end route for the same. So clearing the screen curl vubhham.com/appi. So here we are getting 404 not found. Now what why exactly we are getting this? So if you remember earlier in the back end was served in /path. So / API returned 18:28:06 404. So for that we need to define we uh we need to define one engineext configuration and it actually explicitly handles the / API and returns it to the back end application. Now what is that configuration? Now again you can get it from the documentation that I have present that I have added into the uh readme.md and that is exactly what we are going to make use of. So uh the configuration that I'm mentioning is let me just copy it code and this is the place that I was talking about. So what exactly I did let me just redo it. So here in the backend deployment there is a command section where we have run the backend command but again for this specific section we will need to add few sort of enginex configuration that you can get it from internet. So basically I have again taken it from internet only. So here there is one uh default configuration command that you need to run that is exactly what I'm doing right now. So just before that echo command you need to add this configuration. So 18:29:08 here it goes like this. 18:29:18 Okay. And now this CAD goes here. End of file. And I'm getting one tilt over here. So it says there is an indicator. Let us check what exactly is the issue. So we would be good with that. Okay, what is the issue? So here engine X demonop is present. Echo is also in same place now. Okay, now it is good. It was some space issue and I believe this is uh clear to you. So what exactly we are doing? We are defining a default configuration where we are telling that whenever / API has been received you should return the value as back end application and here uh it should not be back and it should be backend app. So we are just making it similar like front end and then we are defining the value where it should post the value from and that's it that's all what we did. Now let me just go to I terminal and let us 18:30:18 apply the file that we have created. Let me just go back to my terminal once again. Clearing the screen. Cubectl apply-f back end deployment. Mamel. Enter. And back end is configured. My laptop battery is going dead. 1 second. So now let me switch to my Chrome browser and let me show you quickly what exactly I am able to see. When I hit on / API, I am able to see the backend application. Now let me just uh plug in my charter so that we are able to continue further. Uh okay. So let's continue. So what actually are the changes that we made? So these are the actual segment that we made the change for. So this is the documentation for the same. Here we are providing a argument uh to the default share and here we are telling the shell to execute the following script. Now what is the script that we are actually executing? We are actually executing. We are trying to create a default con 5 which listens on port number 80 and the 18:31:19 location is / app and here we are defining uh it should run 200 whenever someone hits on / API and the result that should it should display is backend application and then here we have defined the root location where the index html file is present and lastly here we have a echo which creates the default page with the backend message and that's all the changes that we made. Now in this video there are many things that we have learned. We have learned about annotations. We have learned about gateway API and we learned about u uh how does the application works with ingress or what is the significance of service right? Uh we also validated uh how you can check the changes with um gateway API and uh how you can check the changes with uh how you can check the changes with ingress. So uh the important thing uh that you can take away from this video is gateway API. So the gateway receives the traffic. The HTTP route looks for 18:32:19 the request and based on the path uh it sends the request to the service. So notice that we don't uh we didn't made use of annotation this time. Uh this is normally a path based routing that we did. So this routing is directly described in HTTP route and this is the main difference why we wanted to understand gateway API. So with our earlier ingress example we used engineix with the annotations uh when we needed to change / API to slash. So with API uh with gateway API uh uh with gateway API or HTTP route is already giving us a clear structured way to describe uh the slash API forwarding the traffic to slash. And one final thing that uh we should remember is uh or HTTP route sends the request to / API to the back end. It does not automatically change / API to slash. That is why in this demonstration we changed the backend response itself. So we can clearly prove that / API is to the backend application 18:33:20 and that is the gateway API routing flow. So yes, that was all in this video and I will see you in the next one. Till then keep turning and thank you very much. Hey everyone, welcome back. So in this video we are going to talk about one of the interesting topic in Kubernetes and that is nothing but volume. Now before even when we start our journey with volumes, there is one thing I want to make clear that in this video we are only going to discuss about volumes in Kubernetes because we need to first understand why that concept came and what exactly is the problem that we are trying to solve. Right? For persistent storage we will have dedicated videos. We will be creating persistent volume, persistent volume claims and storage classes. These are the topics that we will be covering in future videos. But for now, just focus on volumes in Kubernetes. What problems are with the volumes and why do we actually need volumes in the very first place, right? So let's discuss about when Kubernetes give you a pod to place a container, what will happen to the files? How do we 18:34:22 manage those files? That is something that we are going to look today, right? So let's discuss about the problem statement. Uh why exactly volume came into the picture. So let's imagine that you have a pod and inside that pod you have a container which is uh which is running an application. Now what that application does it will try to write a file. It will try to read a file. Right? So everything looks fine. The application can uh actually do the work that it is supposed to do. But what's the problem in this case? So the problem starts when the containers go away. Now what do I mean by containers go away? Let's say the container can go into restart. The container can get terminated. So the file system that belongs to the container, it will also get deleted. Right? So when a container is removed, a new container is created by the design of deployment, we should not expect that the file to be there automatically because deployment takes care to recreate the pod which is deleted. It didn't mention about the 18:35:23 storage right so that is something that we have figured out. So we have a very simple problem over here the container is getting created the container application is been executed through that the data has been created. Now what happens when the container is deleted or misplaced at that time a new container is created but what about the data that is something Kubernetes volumes answer and that is something that we are going to discuss today. Now what exactly is a volume in Kubernetes? So what exactly is a volume? Volume is just like a place in Kubernetes that makes available the container which is inside a pod so that they can read and write the files. That's it. So for example you can see a volume can be mounted at / data. From application points of view it looks really very simple like a normal directory. The application can read the file, it can write the file, it can delete the file, it can create the directory. So depending upon the volume and the permissions it behaves like that. Now if you have heard me correctly 18:36:24 I have mentioned two new words over here that is volume and volume mount. So before even we touch the terminal and start creating the file let us first clear these two terms. So what exactly is a volume. So volume basically is the volume that we are providing. Volume mount actually tells the container where should I say this volume. So maybe your volume internally has name like uh for example it can be something called shared storage but inside the container we decide the container to see it as / data that is what we call as a mount path right now let us see the differences between volume and volume mount. So now there is one thing I want you to remember very clearly when we are using a volume there are normally two pieces. First is the volume this defines the volume of the pod. Second is the volume mounts. This tells a particular container where the volume should be appeared. So think about it like volume says the storage exist. Volume mount says the storage to this container at 18:37:25 this specific location. So basically this is the relationship between volumes and volume mount. So now before even we do a deep dive into volume and we do the hands-on on volume, let us first see what was the problem that we were facing earlier. So for that let us create one file without volume so that we will get in clarity what was the issue and what we are actually trying to create right let me just switch to my terminal and here we go let's create the manifest file for a pod and in that pod we are just going to uh run a busy box container and then we would try to create a file we we would try to read it and then uh we'll observe the behavior what will happen if we delete and recreate it whether we are able to see that file again or not. So let us create a manifest file for a pod. So whim uh now let me just name it as no volume doyl. Now again whenever you are creating any sort of resource in kubernetes what are the four keywords you have to remember API version kind 18:38:26 metadata and spec. Let me just write the same. So API version kind. Now what are we trying to create? We are trying to create a uh we are trying to create a pod meta data and here we have the specs escape col wq. Now how will I know what would be the API version of pod? So basically you can make use of cube cut api- resources and here I'll run a grab on pod and here you can see the API version for pod is nothing but v1. Let me just edit my file once again and here I'll update the value for API version and that is nothing but v1. Now again what would be the name of this part? So we will name it as no volume pod and then what are the settings? What are the configuration for this pod? Now in a pod we are trying to run containers. So here we would be writing the settings the configuration for those containers. So containers containers. Now what would be the name 18:39:26 of that container? Now here I will write no volume application. Now image that would be utilized by it. So image would be nothing but busy box. Busy box what exactly it is? Busy box is a lightweight Linux image that helps us in running basic Linux utility commands. Right now here what exactly are the commands that we want to fire? So here I can specify the same. So here in the command I want to run it through a shell. So here I'll write sh and here I want to provide the command light input inside that container and I want to keep uh that container alive for uh let's say 1 hour. So 360 0 escape wq clearing the screen and let me just explain you the file once again. So what we have over here here we have API version as v1. So what exactly it denotes? It uses Kubernetes core API version that is nothing but v1. Then here kind pod. So what exactly it is denoting? It is telling kubernetes 18:40:27 that we are trying to create a pod. Right? Then here we have metadata. And inside metadata we are defining the name of that pod. And what is the name of that pod? The name of the pod is nothing but no volume pod. Now here we have the specification. Now this specification is for what? This specification is for this pod. And what are the specification? So basically since we want to run container inside that pod. So here are the configuration for the containers. Now what would be the name of that container? The name of the container will be no volume app. Which image will it be utilizing? It will be utilizing busybox image. Then here is the set of command that we would be firing. So what exactly command does? It overrides the default container command. Then second is here I made use of hyphen sh. What exactly hyphen sh means? It tells to start a shell. Right? whenever the container is been executed. Second is we have hyphen C. So what is the significance of hyphen C? So please understand it correctly. Uh hyphen C tells the shell to execute the next uh command, next text, whatever we would be 18:41:29 writing as a command. And what is the next text that we are typing over here? We are typing sleep 360 0. So this keeps the container running for an R. Now since we saved the file, let us apply the manifest file. So clearing the screen. Yep. One second. Yeah. So cubectl apply - f. No volume. Mlm. And here you can see the pod is created. cubectl get pods. Enter. And here you can see the pod is up and running. Now let's create a file manually inside that container. So how we will be doing that? So basically if you remember docker we have something called docker exact id and then we used to go into interactive mode. we used to create a file. There was another method in docker. We used to make use of docker exact and then finally we were able to run the command after appending the commands that we need to do. Right? Same thing can be done with kubernetes. So instead of writing docker exact we will make use of cube cuttle exact now here 18:42:31 where exactly we want to run that command. We want to run that command inside this pod. Here inside this what exactly we need to do? We need to pass a shell command. And here we need to run a command which actually creates a file inside it. So what I will do I will first create a parent directory by the name as data and I want to run one echo command which is capable for printing hi from no volume and then I want to save this file into / data directory and here I'll just name this file as temptxt enter and here it says there is an unknown flag so Here I need to pass one space. That's the reason I'm getting that error. So 1 second, enter. And here it's created. Now let us validate whether this file is file created or not. So cube cuttle exact in the pod. 18:43:34 And here I want to run a cat on the file which is which we just created. And the file name is nothing but temp.xt. temp.x. txt one second here we are facing one issue I need to just pass a double hyphen okay clearing the screen let me just see the error once again uh can't open / data temp no such file or directory command terminated with exit corer exit code one okay let me just verify with the previous output so here what we did We ran cup exact volume and uh - f message and here we made one file parent directory and then inside that we ran one echo command which printed uh hello from no volume into the text 18:44:35 file and that should do the job and I think the only thing that we messed up over here is it should be in single quotes. Let me just correct the same. So okay, enter. Now it got executed. Now let me just run a cat. And now it is working fine. So now what we did, we actually created the file and we actually read it. So here you can see we are able to read the file whatever we created earlier inside the / data directory. Right? So the file exist but remember we have not created a kubernetes volume over here. So this file where exactly it is staying this is staying exactly into the containers file system. Now I want to prove that what will happen if the container restart right. So what I will do I will just u delete this part. So cube cuttle delete uh name of the pod is no volume pod. Delete pod. No volume pod. And here the no volume 18:45:37 pod is deleted. Now what is the expectation is now since we deleted the pod what about the data that is a concern for us that is something that we are going to check right now. So let us wait for the pod deletion. Once the pod is deleted then we'll apply the current manifest file and we are going to check whether we are able to read the uh test file that we have created or not. So let's wait. Okay. So now what I will do I will just apply the current manifest file by running cube cuttle apply - f novol.ml clearing the screen and now let me just run the exact command once again to verify whether that file still exist or not. So cubectl exec followed by the pod name that is no uh no volume demo and here no volume pod and then what I will do I will run hyphen - cat on / data and what was the file name we created temptxt enter and here you can see it says no such file dot directory command 18:46:38 terminated with exit code one exactly happened over here is the file is no longer existing there and the important lessons over here is the container got restarted. The file that we created is not there. This is exactly the problem that we are going to solve with the help of volumes. So now for that let me introduce emptydir. Now let me just switch to my visual studio code and let us discuss further over there. So what exactly emptydir is empty as the name suggest empty directory. So what exactly emptydir is and what exactly it is capable of. So empty diir is probably one of the easiest volume type to understand. The name itself tell us that we are talking about an empty directory. So when a pod starts kubernetes creates an empty directory for the pod so that our containers can use it. So uh basically in a pod there can be multiple containers which are working and those containers can also make use of the di. 18:47:40 So what will happen if I delete one of the container from this from that pod? what will what will happen to that empty diir there won't be any effect on it because the lifeline of empty directory is linked with the pod until and unless you are not deleting the pod your data is safe inside the empty directory so kubernetes documents that the empty diir is created when the pod is assigned to a node and it is initially empty that's the reason it is said as an empty directory it can be shared by all the containers which are running inside that pod so This is useful because even if the container is crashing, we can make use of whip and even if the container is deleted, we can make use of the empty directory. The only condition is if the pod is live, then your empty directory still exist. So let's visualize empty. So let's consider that you have a pod. Inside that pod you have two containers container A and container B. Now as per the statement that I have given earlier, a empty directory is initialized 18:48:40 whenever a pod is created. So these two containers can access empty directory. So container A can uh create a file and container B can read that file. Right? Now vice versa can also be done. Container B will be able to read the file and container A should also be able to read that file. Now what will happen if one of the containers goes down? Will the other container able to read that file? So answer is yes. And when the container A is back online then the data is still present because we didn't deleted the part because of empty empty directory present into the picture or data was safe and we will be able to use it. So the both so both the containers are connected to the same empty directory that means container A will write the file to the empty directory and from the empty directory container B will be executing it we'll be reading it. So let's actually prove this. Let us create an empty directory demo. So for that let me just switch to my uh terminal. So here we are. All right. So let me just clear the screen and now let 18:49:41 me create a new file for it. So vim uh empty- diir.l and what I will do escape wq. Let me just copy all the content from the current file that we created that is from no volume. I'll just move it to mtdir. Vim mtdir. Now why did I copy it? Basically we are going to create a manifest file for the pod that is exactly what we have done uh in the previous uh manifest right so I'm just going to make few cosmetic changes for example here in the metadata section I'll just name it as it can be anything I'll just write empty - diir and here basically in this specification this is the main place where we would be making a lot more of changes so what I will do instead of confusing you I will delete the entire commands which are present over here. So let me just remove it. All right. So here let me just save it till here. Let 18:50:41 us go to Visual Studio Code because that will give you a visualization for the file creation and that would be very much helpful for us to refer also. So now what I will do I'll just jump to my visual studio code and this is the file that we are referring to. All right. So what exactly we are doing is we are going to create an empty directory pod and inside that pod there will be two containers that we would be referring to. So the container one is nothing but the writer and the another container that we are talking about is nothing but reader. So basically if you are thinking about where I am getting that emit from so basically there is AI integrated in my visual studio code. This is the reason I'm getting that emit right and I hope that you are able to see the screen right now the next thing that we would be doing is here inside the container in uh so basically inside the writer container I will be telling what image we are referring to. So here the image that we are referring to is nothing but busy box. Same image we will be referring in reader container. Right now again there are few set of commands that I want to 18:51:42 execute when I'm working with the writer container. So for that I will just write command and here the initial command that I will be firing is uh basically I will activate the shell and inside the shell I want to run few uh command that so basically I am writing hyphen C. So that what it will do whatever commands I'm passing as text it will consider it as a command. So here what I will do I'll just trap and here I'll just mark whenever it sees exit code one exit code one okay and now uh since this is done let us move forward with the next one here again I will pass few commands and here instead of passing hyphen C here what I will do I will just mention that it should sleep it should be available for next 1 hour and That's something the instruction that I would be passing what exactly we did we just defined the two containers we defined the commands that it should execute when the container is 18:52:44 pinned up. Now let's actually work about the volume and volume mount. So first thing that I will be doing is I will be first defining the volume for the same. So here I'll just press enter and here I will define the volume and here the name of the volume that we would be doing is we will be just marking as shared data. This would be the name of the volume. And here we have defined the uh empty directory, right? Let me just remove the space. Now it's correct. Now here we will need to mount it. So how do we mount the volumes? So for that we have something called volume mounts. So volume mounts and here the name of the volume is uh shared data and the mount path. So what exactly is the mount path? So this is the place where it will look the container for for the data for and here we would be mounting into shed. uh that would be the name of the folder. Same thing we would be defining it inside the reader container 2. Okay. Now our manifest file is ready. Let me just explain you everything line 18:53:45 by line. So what exactly we are doing here? We are telling Kubernetes the core API version v1. Then we are telling that we are trying to create a pod. Thirdly we are giving the metadata and inside that metadata we have defined the name of this uh pod. What is the name of this pod? that is nothing but empty. Then we have defined the specification the settings for uh this specific file that we are creating. So here we are trying to create two containers writer and reader. So both are using busybox image and then here the differences between the commands. So let me just cover the commands uh for busybox container and this is what I am referring to right now. So here what exactly it means. So basically here we are telling uh by command we are telling actually we need to start a shell and then we are telling to execute the following command and then there is a big command that I wrote that is trap exit one. This keeps the shell running and exit when a signal of termination is received. So what we are going to do we are deliberately going to give a kill operation so that it will receive a termination error and then it 18:54:46 will restart the container for us. That's the reason we are making use of the trap command. Then we have the uh reader. So inside reader again we want to keep it alive for 1 hour. That's the reason we made use of 360 over there. Lastly we have made use of volumes. So here we have created the volume for the pod. The name uh of the volume pod is nothing but uh shared data and here we have defined the empty directory and basically what exactly it does it creates an empty directory volume for this pod. Now here you can see there are two uh two three lines that we have entered that is volume mounts name and mount path. What exactly that does that denotes? So it defines the volume that the container can access and it can use the same uh shared data and it can make the volume available into that folder called slash shared. So let's understand one important point that is that we have a pod and inside that pod we have two containers one is writer one is reader and both containers use shared storage and that is the empty uh directory volume for us and both containers can 18:55:48 see /shared folder. So both are looking at the same volume. Now let us apply this manifest file and I will switch to my i terminal over here. So let me just apply the file. So clearing the screen first. cubectl apply - f and name of the file is emptydir. So here it says cannot be handled as or strict decoding error unknown field as volumes. So here in the volumes I made one mistake that I need to correct. So let me just create uh let me just correct the same. So here volumes is present. So volume I need to give one space and now it should be good. Escape col wq 1 second insert mode escape col wq. All right let me just apply the file again. It says uh line 25 did not expect hyphen indicator. Okay let us check the same escape colon set a new line number 25 over here. 18:56:51 Okay. So here it says that uh hyphen was expected. Uh okay. Let me see volumes is at the same level of container. So that should be good. Then I think uh the spaces are also correct. And here we have defined the empty directory also. So that is again correct. So let us check what can be the possible issue. Skip colq not we didn't made any change or here what it says error in parsing empty diamel converting yl to JSON line 25 did not find expected hyphen indicator. Okay what can be the issue? So mostly the issue is with the hyphen only. 18:57:54 Okay, let me just go and do a BIM again. Let me just remove a space from here. Skip colon wq. The space is removed. Applying the file again is a bad request. unknown field volumes. Okay, let me just check it again. This this is the place where we are facing the error. Escape col WQ. Let me apply it. Okay, now it got created. So the issue was with this space again YAML is very strict with the indentation. Sometimes I also have to face the issue. So here I just added a single space. Earlier there were two space. So it was going inside the hierarchy and it was following this context. So what I did now it is exactly just below the container section. So now it actually worked. I hope that made sense and now you are able to follow along with me. So now let's understand important point. We 18:58:55 created two containers reader and writer both are sharing the same storage and both are mounted into/shared folder. So both are looking to the same volume. Now we have created the pod. Let me just verify the same cube cuttle get pods and okay cubectl get pods and here you can see mtd is up and running. Now since both the containers are running let us create a file from the writer container and let us verify the same from the uh reader container. Right? So what I will do, I will just write cubectl exact. And here what I want to do, I want to just I will just copy the name of the pod. And here inside this pod, what I want to do, I want to target to the writer container. And inside the writer container, I want to pass a shell command. And what that shell command will do? That shell command basically will print hi from writer. 18:59:56 Okay. And then what it will do? It will store the uh data into the folder that we created. What is the folder that we created? The name of that folder was nothing but shared. So shared / uh writer hy writer txt and then I will just press enter and here our file is created. Now let me just verify it from the uh writer uh container itself. So cubectl exact mtdir in the container uh writer and then here I'm selecting writer. Then here I want to read the file which is stored in shared and the file name is nothing but writer txt. Enter. Here you can see hello from light uh writer is printed for us. And now let us validate the same from the reader container too. So that this will prove that the writer container and the uh reader container are actually communicating are actually storing and 19:00:57 reading the file from emptydir which got created when the pod was created. And what is the name of the pod? The name of the pod is nothing but empty. So let me just verify the same. So cube cuttle exact empty direct emptydir and in the container named reader I want to read the file and the uh file is stored in /shared the name of the file is nothing but writer txt when I press enter here I am able to read the message and this is our first real proof for volume now there is another small thing I want you to understand we had shared storage and here I am talking about uh so basically here we have shared data and we have created one file called shared let me just move uh and let me just clear the screen let me just do a cat over here so here we are talking about shared data and the mount path that is shared so what exactly 19:01:57 these things are these are not the same thing let me repeat once again these are not the same thing shared data is the kubernetes name for the volume and /shared is where the volumes appears inside the container. Right? So one more thing does empty diir survives a container restart. Now let us prove that life cycle behavior because that's the reason why we came to understand about volume. Right? So what we are going to do is we are aware that empty directory belongs to the pod. We are aware that emptydir belongs to the pod. So if the container is deleted and anything happens to the container or data is saved. Why? Because the lifeline of the empty directory is linked with the pod. Right. So unless and until we are not touching part the files inside the empty directory should be safe. So let us verify the same. So what I will do I will here just pass a kill uh operation over here. So by that it will be able to tell us that the file are intact or not. So what I will do I will again create a 19:02:59 new file for the demonstration of the same. So what I will do I will just run cube cut exact by the name uh in the empty directory uh pod. And here I want to select the container. The name of the container is writer. And inside that writer container I want to pass on shell command. And that shell command basically should create one file for me. And here I will make use of echo. This is the proof that this container uh containers data survived after the reboot. Okay. And now let us save this file inside the shared directory that we have created. So here it will go to /shared / restart.txt enter. Uh there is a flag error. Okay, I 19:04:00 need to pass one space over here. I'm forgetting it every time. Okay, so let me just go back. Okay, now we are good. Let me just verify the same. So here what we did we executed this command cube cuttle exac into the empty directory in the container writer. Uh here what we want to do we want to read the file that we just created. So hyphen - cat on the shared file where the file name is nothing but restart txt enter. And here you can see the data is printed over the screen. Same thing we can uh verify from the reader too. So here I'll just rename the container name to reader and here we are able to read the file from both the containers. Now what I will do I will uh delete uh or maybe I will terminate I will pass one signal uh to the writer container so that once it 19:05:01 is back we will be able to verify whether it is able to gather the data or not. So I will run cubectl exact in the empty directory and in the container name writer what I want to do is I want to again pass a shell command and what exactly it should do it should kill the first running process and that is nothing but u and that will actually trigger a restart for us. So when I press enter I need to give one space okay enter it got executed. Now let me just run cube cuttle get ports immediately. Here you can see the restart started 3 second ago. Let me press enter. Clearing the screen. The restart actually happened immediately. What exactly we need to do? We need to actually check whether the container survived. If yes after the creation of that container whether we are able to extract or whether we are able to see that data or not which we created earlier. So cubectl after the restart we 19:06:04 are going to uh check this thing. So cube cut get ports here is the proof that the container got restarted and it's been 34 seconds. Now I will just try to read it with the writer container. So cube cuttle exact in the port name empty directory. I am selecting the writer container and here I want to run a shell command or basically here what I will do I will just uh do a cat to check the files that we have created. So hyphen - cad on the /shad and here the file name was restart txt. Here I need to give one space. And here you can see this is the proof that the containers data survived after the reboot. This was earlier getting lost because at that time we were not making use of volume. But now since we are making use of empty directory we are able to get the data back. What we did? We deleted, we restarted a container and then when we went back we were able to gather the data back again. Right? Why? Because the lifeline of container is 19:07:06 linked with the pod. Now this is something that I have been repeating from the starting itself. Now let us actually delete the pod and see what exactly happens uh when we actually delete the pod. So now let me just delete the pod. So clearing the screen cubectl delete pod followed by the pod name that is empty. Now what is happen what is happening over here is once we delete that pod we are going to again create it back and we are going to check whether our data the files that we have created are back or not. Now since we delete the entire pod the pod is gone u and because of that the empty directory which was linked to it is also gone. So here let us verify after recreation of the pod whether we are able to access the file or not. So once it is created, let me just run cube cuttle apply - f app on the empty directory. The new pod is created. Cubectl get pods. Okay, it's it's in container creating state. So let us wait. Now the containers are 19:08:06 created. So now cubectl ctl exact in the container. So first of all we need to define the pod and here we are selecting the writer container and what exactly we need to do? we will actually try to read the file that were present earlier in the ent directory. So hyphen - cad and here in the /shad we created a restart txt file which should be there eventually. But here you can see we are getting a message cannot open restart file because there is no file or directory present. The command terminated with exit code one. So why this happened? Because it is a new pod. Once the container starts and if the pod stays your data is there but if the pod itself is deleted then empty directory is also deleted. That is something that we want to prove over here. So when the pod is removed not when the container crashed not when the container restart when the pod itself is removed the empty directory follows the pod life cycle and it it itself gets destroyed. So then uh 19:09:09 the question should be then for what reason empty directory is good for. So empty directory can be good for temporary data. For example, it can be good for temporary files. It can be good for cach for shared workspace or for intermediate file. So imagine one container downloads a file, another processes it. You could make use of mtdir and that is nothing but a shared workplace and that is important over here. So you can make use of mtdir which act as a shared workplace. So here the important term is temporary. So we are not using MTDR just because we want permanent application data. MTDR is a spare space uh a checkpoint for sharing the files between the containers a common point. Let's talk about where does the data go. So uh when we make use of a normal empty directory, Kubernetes uses the storage which is available on your machine available on your node. So that is exact the storage medium which depends upon the node. Uh so basically in Linux environment uh that is uh we have something called ephemeral storage. 19:10:10 So that is why empty directory is considered to be as temporary storage. So now let us talk about another alternative yet good option that we have with empty directory. So here we are talking about memory based empty directory. So this is another option that comes with mtdir. So we can tell kubernetes that I don't want empty directory on a normal node storage. I want memorybacked file system. So the only difference is where the data has been stored. So here the difference would be instead of storing the data inside the container for the pod here we will be making use of a temporary file system which is nothing but a RAM based file system on Linux. So let us create one for all self. So let me clear the screen and here I will create a new file. So when uh memory memory empty filel and escape colon wq. Let me just write 19:11:11 l. Okay. And let me just write the four keywords that we are actually working on. That is nothing but API version. API version for pod is nothing but v1. Then we have kind. Kind is nothing but pod. Meta data. What would be the name of this pod that we want to call as? So what we will be calling this pod? We will be calling this pod as memory memory empty pod. This would be the name of that pod. And here we will write the specification. Now here we would be writing the specification for the containers that would be running inside this pod. Containers. And here uh I want to give it a name and the name is nothing but let's give it a normal name. So here I will give it as name as uh app and the image that we would be using is nothing but Ubuntu. I will be making use of Ubuntu latest image. And again here we will be passing the normal basic commands that we have 19:12:12 been passing so far. So again here I'll pass one shell. I want to pass remaining text as command. So sleep 360 0 that's the basic command that we have shared. Now here I need to pass one more command that is nothing but volume mount. So volume mounts here now let me just give you the name of the volume mount that we are referring to over here and the volume mount is nothing but memory storage. You can actually write any name over here memory storage. And then here just below the volume mounts you have to define the volume path. So mount path. Now here I will define the mount path as cache and then lastly here we here basically we would be defining the volumes volumes. Then again what would be the name of that volume. So let me just define the name for the same. The volume 19:13:13 will the volume name is nothing but memory storage that we define into the volume mounts. And then again the last thing is empty diir. All right. Escape colon wq. Let me just verify the file. cube cuttle apply pf. Okay. And let me just run a cat. And let me explain you everything from scratch. Okay. So what exactly we are doing over here? First of all, we are telling Kubernetes core API as v1. We are telling Kubernetes that we are trying to create a pod. And what is the name of that pod? The name of the pod is nothing but memory empty pod. Here inside the pod we want to create a container. The name of the container is app. It is using Ubuntu image. And here we are running few commands to keep the pod alive. Here we have created a volume mount which is using the volume name memory storage. And here we have defined the volume mount path that is nothing but/ A. And here we have defined the name of the volume that is memory storage. And 19:14:14 we forgot one thing that is let me just open the file here. Instead of marking this as empty here we need to define the medium. So here instead of emptydir just below that you need to define the medium medium and the medium is nothing but memory. Escape colon wq let me tell you what exactly I'm referring to now. clearing the screen cube delete pod memory pod empty and I'll explain you what exactly I did right now so basically here we are using empty directory volume type and here in the empty directory volume type we are storing memory memory based file system that's the reason uh inside empty directory I defined the medium as memory so once it is deleted let me just reapply the file that we have created okay let me just do a cat on the file. So yep here basically we defined uh in 19:15:14 the empty directory that we would be making use of the RAM that is temporary file system for the storage. That's it. Clearing the screen and applying the file that is cube cuttle apply - f memory empty file.ml cube cdl get pods get pods and here mtdir is up and running. So this is again created for us. Now let us verify uh the last line that we have entered in the the manifest file that medium col memory. What exactly is the meaning? So that can be verified with the help you with with the help of exact command. So cube cutle exact in memory empty pod. What exactly we want to exact? We actually want to run a command for the uh disk fragment. And here we want to run it as human readable format. And this is the mount path that we have created. Yes. And here you can see the file system information is written in front of us that is tmpfs. 19:16:14 This is a temporary file system and that is mounted on / cach a / cach a and that is exactly what we want to prove. So here we I want to I want you to see on TM tmpfs that is temporary file system and secondly it's the mounted on that tmpfs temporary file system is important path that is a proof that we didn't just trust on the yl we checked actually the file system mounted inside that container that is much way to understand this feature so let's compare the empty directory with the memory empty directory so empty directory actually saves the data into the node storage but when it comes to memory based memory backed MD directory stores the data into the temporary file system and that is nothing but it is storing into the RAM. So the volume is still empty directory only the storage medium got changed right but there is one more important thing that I want to tell that RAM is not unlimited uh when you use medium equals to memory the data that you will write as memory the data that you will 19:17:15 be writing inside that volume will use memory so if you keep writing more and more files you are consuming more memory so that's that's the reason memorybacked empty directory should be used carefully and it's useful for temporary data uh when it require fast storage and for fast access but don't treat RAM like an unlimited disk that we get actually wants the files that are written uh by memory bagged empty directory so that uh because it is consuming more data uh it is consuming more memory and may contribute to container memory usage and as large memory uses for the backend volume comes it pressures the pod and it can pressure the node too. So now let's create the file into this memory based file system that we have created. So how do we do it? So basically again the system is same cubectl exact into the memory file system. Let me just list the pod first. cubectl 19:18:16 get pods cubectl exact in the memory empty pod. So here I'll pass one shell command sh and here I want to pass one command for creating a file. So echo this is memory based file coming straight from the RAM and I want this file to be showed to be stored into the file system. So here we made use of /ka and the name of the file can be 19:19:16 anything. So here I'll just write it as a message dot text. Enter cubectl. Okay, it should be cubectl. Enter. Okay, so what exactly we did? We created a file named message.txt which consists of this long message and basically this is inside the uh pod that we have created. Now what we will do we will actually try to read this file. So how we will do that? So again cubital exact memory pod and here I want to run a cat on / cach a slash message txt and when I press enter I'm getting this message state from the RAM and now let us verify the same where exactly this file is stored. So cube cuttle exact memory empty pod and then what I will do I will just run disk utility 19:20:20 command and here it will tell us uh what where exactly this file is stored. So here we are actually trying to figure out what is the file system where this file has been stored. Enter. And here you can see the file system is temporary file system. And here it is mounted on /cach that is actually giving us a proof that we actually saved the file inside the RAM. And that's the thing that we wanted to prove over here. Now we have both uh the proof that the file exist and the proof that what file system is backing by the volume. So uh let us talk about next volume path. So first we talked about empty directory. Then we talked about empty directory that is backed my memory. Now let us talk about the next volume type that is host path. So uh what exactly is host path? So uh the uh the idea is basically very simple. I'm talking about host. What exactly is the host? So instead of kubernetes creating empty directory for the pod, we are saying to take a file 19:21:20 directly from the kubernetes node and make it available inside my pod. So imagine that you have a kubernetes pod. Uh imagine that you have a Kubernetes node and inside that node you have a directory mounted that is / data and there you have a application file. So we want our container to see the same location / data and it should refer it inside it. So that is where we make use of host path. The idea is basically Kubernetes define the host path as the mounting file or directory from the host nodes file system into a pod. So because we are making use of mini cube in with the help of docker driver there is a important thing that you should understand. Uh so when we say host path in mini cube the host path means kubernetes node and in our case the node is nothing but mini cube environment. So it does not automatically mean uh that it will create a normal folder on your Mac. So if I say / data/hostpath demo we are talking about the file system on mini cube node. Let us uh create the 19:22:22 directory on mini cube node. So how we will be creating it? So for that we have a command called mini cube ssh and here what we will do we will just create a directory for this demonstration. So hyphen here we will need to pass sudo privilege permission. So sudo and mkdir for the directory. And what directory should we create over here? Just name that directory as / data /host path and let me write it as demo. Enter. And here it will create the host file directory. Let us validate the same. So mini cube ssh - ls - ld and uh here it is listing the docker driver file. Uh let me just give the actual path / data / post path. One second. 19:23:29 Clearing the screen first. Clearing the screen. Okay. Mini cube ssh ls- ld on / data /host path demo. This is the uh directory that we have created. And now we have validated the same. So we should see the directory. And now we are actually ready to mount it. So let us create the host path file and let us verify how does things works over here. So vim h postpathy enter. Now here again api version kind metadata and here we have the specification. Now here in the API version again we'll start with v_sub_1. So v_ub_1 again the kind would be something called pod. So because here we are trying to create a pod. Then here in the metadata I will define the name of the p that we want to create. So here we will write it as host path demo. And let 19:24:32 us write the configuration for the containers for that pod that we are trying to create. So here the name of the container would be nothing but app. And the image that it will be utilizing is nothing but Ubuntu. And here there are few set of commands that we want to run. So command I want to run the command in the shell. And it should consider the next few lines uh uh text as commands. So sleep 3 600 0. And then what I will do I will just uh provide the volume and volume mount. So I will just define the volume first. volume mount volume mounts and what will be the name of the volume. So let me just write the name. This is the same name that we will follow when we are defining the volume. So let us give the name as host storage. And then here after defining the host storage I will need to define the mount path. Mount path is nothing but data. 19:25:34 And then let us go over here and let me just define volume. And here inside the volumes I will define the name of the volume that we are referring to and that is nothing but the host storage. So hyphen name that is nothing but host storage. And inside that we will define the attributes of it. So here I will need to define the host path for the same and where exactly is the host path. So the path is nothing but the one where we have actually created the mini cube directory. So / data /host path - demo. And now here after that let me just define the type of it. The type is nothing but directory escape colon wq. And here we have defined the hostpath demo. Let me just verify the spelling over here. So / data /hostpath - demo / data /hostpath demo cubectl apply - f 19:26:37 post path yl and here we are getting one indentation error. Let me first clear the error first and then we'll start with the explanation. So here it says cannot unmarshall object gostruct uh spec containers volume mount somewhere around containers volume mounts there is an issue. So let me just go inside the file vim host path file and here we have defined the volume mounts and just below that we have defined the volumes and it's in the same place app container and inside the volumes you have defined the name and uh okay I think host path this is the wrong thing that was incorrect Clearing the screen. Let me apply it once again. Uh converting line number 18 mapping value is not allowed in the context. Okay, let us go. What exactly is in line number 18? Set a new. Okay, in line number 18 19:27:40 here it says this value is not allowed. So let us verify the same. 19:27:51 Okay, for volume we will need the host path. Now let me refer the Kubernetes documentation. Opening my browser. Okay. Let me just correct it. Here we will need that host path 19:28:15 host path and uh here we have the path which we have defined / data/hostpar demo. Okay. and escape colon wq cube cut apply host path again we are getting unmarshall object issue it's nearby containers spec dot containers volume mounts okay 19:28:53 this I guess should be at this level. Now there is an issue at line number 12. We did not find expected indicator. Okay, there is an expectation. Now here in the volume mounts I need to pass one. Oh, okay. Now here I think yes at this point it is expecting me to add one dash. Now it should work fine. All the changes has been made and uh it says did not find an expected indicator. Okay, we just provided it. So the name is provided. Now mount path also provided. 19:29:47 Okay. Insert mode skip wq There are a lot more error we are getting today and now on uh and now finally it is solved. So clearing the screen cube cdl get pods and here we have the host part demo up and running for us. So now what exactly we did uh there were few indentation error that I fixed and like it was done live only. So you already have the context what actually was happening behind the scene. So yes so after fixing the indentation the host part demo is created. Now again what we are going to do is we are going to uh like inside that container we are going to create one file we are going to read it and then we are going to verify the file. So again let us do the same copying the pod name. So cubectl exact in this pod there is a container by the name app and inside that app I want you to create one 19:30:50 file. So here I'll write from the post and this should get stored in / data / message txt enter and here it says again I need to pass one space which I forgot earlier here. So, enter. Now the file is created. Now, let me just read the file once again. 19:31:45 So now once the file is created, let us try to read it. So cubectl exact in the pod name host part demo. Now here we are going to read it. So - cat on / data slash message txt enter. Here we are able to see the message and it says uh hello from the host. Now let us check the same file whether it is present into the mini cube node or not. So for that mini cube ssh and here we will need to pass a sudo cat command and it should be inside the host path that we have created. So / data /host uh I think we have defined hostpath - demo and the file name is message.txt. Let me just clear the screen. I'm using tab over here. mini cube sshen 19:32:48 cat into / data /hostpath demo/ message txt enter and here you can see we are able to list here we are able to read the message from the host path that we have defined into the mini cube so this is the proof that the file that we created inside the container is actually coming from the directory from the node. The difference between host path and empty directory. So in empty directory kubernetes gives the p a temporary storage. When it comes to host path we provide a specific point or place inside the node. So that is the actual difference between them. Now what will happen if the pod uh within that host path is deleted. So now let's something interesting or file are currently existing on the node. Now let us delete the pod. So let me delete it. CubeCTL. Delete. Delete. 19:33:50 Delete F postpath. ML. And here the pod is deleted. But again there is one more verification left that is whether those file are still present into the mini cube or not. So once this pod is deleted, let me just verify the same whether are we still able to access this file or not because that's the reason we are learning host path in the very first place. Okay, now uh the pod is deleted. Let me just verify the same and and here you can see that we are still able to see the message that is hello from the host. Now why we are able to see that? Because that file belongs to the node directory. We deleted the pod. We did uh we deleted the pod but we did not deleted the node directory. The pod disappeared. The host path directory still remains very different from empty directory. So let me just recreate the pod once again. So cubectl apply fostpath.ml. Postpath ml is created. Now here what I 19:34:51 will do? I will again try to read that file. So cubectl exact postpartmo here I will read the same file which is stored in / data and the name of the file is message txt enter here you can see after recreation of the pod we are able to see the message the new pod can see the old file why because the file lives on the node the machine the that is one of the bigger difference between the empty directory and the host path So why host path is not a magic in persistent storage solution? Because you might be thinking that if hostpath survives the port deletion why don't we make use of host path for everything like let's say why we are not using it for application sort of data. The question is good. The problem with host path is basically it is again tied to a node. Imagine in node one you have your data mounted into slash data and or application is currently running on node one but tomorrow the pod is scheduled on 19:35:52 node number two. So uh does it mean that the data will also flow to node number two? Possibly not. So that directory belongs to node number one. That's why host path is tied to your application to the nodes file system. So this is why host path ties your application to the nodes file system. Let us take an a direct comparison between empty directory memory with empty directory and host path. Let me switch to my visual studio code. And here we are. We are talking about the readme.md file and you can refer this documentation. So if I scroll all the way to the bottom. Yes, here is where we are. So let us discuss about the key differences between them. So empty directory is the temporary storage for the pod and memory with empty directory here we have the temporary storage in the RAM. Then when we use of host path here we are talking about directory from the kubernetes node. So this life cycle of empty directory looks like it survives the container restart but when the pod is deleted the empty directory is lost. 19:36:54 Host path basically the data is stored in the node. It can survive the pod deletion too but it is tied to that node. So like the other node cannot access the data from it. That is the basic core difference between empty directory and the host path. So when should I make use of empty directory then? So let us discuss the same. So we can make use of empty directory whenever you are dealing with any sort of temporary data or any sort of cache or you want a shared workspace at that time you can make use of empty but again once the part is uh once the part is deleted the empty directory is also deleted. Now let us discuss about when you should make use of host path. So host path is something very different. You are seeing that I am specifically you are saying that I specifically want this data to present in that specific node. So it is useful for node level use cases but I don't think host path is a normal way to store the database because that is not the key takeaway that we should usually take with hostpath. It is 19:37:54 something that is node specific that is environment specific. So it can introduce security and portability issues. So that's the reason that you have to keep in mind when you are dealing with hostpath. Now what are the things that you should consider when you are working with a database. So let's imagine that you are working now with MySQL and in that MySQL you are dealing with multiple database stores for example customers, orders, payments or maybe transaction. So let's say if I want to put the database data into the empty directory. So will it be a good will it be a good approach? So basically no because uh if the pod is deleted then my empty directory is deleted. So then the next approach would be should I make use of host path then again no because because that data is tied to a particular node and this is where we need a proper persistent storage model and that is exactly we are going to cover in the next sessions. We are going to learn about persistent volume, persistent volume claim and storage classes. So we are intentionally 19:38:55 skipping this topic today because why we want to highlight we want to see what was the existing issues with Kubernetes volume and there is one sentence that you should remember. So from the entire video there is one key takeaway that you can take from this video that uh Kubernetes volume gives container a space inside a pod and that is nothing but empty directory. You can make use of multiple volume based on the lifetime of the options that you are choosing. You will be able to see the different behavior of the volumes. So that is about volumes in Kubernetes. We just understood why containers file system are not sufficient enough. And then we introduced volumes and now you should understand the idea behind empty directory uh memory with empty directory and host path. And now this is the correct point to start our journey with persistent volume, persistent volume claim and storage classes. And that's where persistent storage comes into the picture. So yes, that was all in this video and I will see you in the next one. Till then keep learning and thank you very much. 19:39:57 Okay. So in the previous video we learned about volumes in Kubernetes. We literally started with the container file system. Then we understood that the data which is written inside the container can disappear when the container is replaced, restarted or recreated. Right? Then we uh introduced the concept of cubernetes volume. Then we worked with empty directory and host path. We literally saw the hands-on example and we also learned something really very important that is empty directory follows the life cycle of pod. So like if a pod contains two container then there won't be any issue with the container getting killed but what if the pod itself is deleted then it then your data is gone right so that was the demerit of empty directory then came host part into the picture so host part the lifeline of host part is actually connected to the kubernetes node but now let's imagine that we are running a real application for example let's say it can be any database for example my SQL So uh 19:40:58 basically what h what exactly happens in a database basically we store multiple sort of entries inside the database it can be the product information it can be the ids it can be the name of the customer there can be multiple field or let's say if it is a monitoring tool then basically you are storing the logs right those logs are very much important for us so these are the things which we can't afford to lose now the question is if you use a host part how do you create a storage that has the life cycle independent. This is the place where you can answer persistent volume. So in this specific video we are going to talk about we are going to talk about persistent volume. We are going to learn what exactly is persistent volume. Why did it came to the picture? Why do we even need it and how it is actually different with the uh Kubernetes volume that we learned in the previous video. If you haven't uh gone through the previous video, I will highly recommend you to go through the previous concept because that will act as a baseline for you to understand uh persistent volume 19:41:59 in detail. Right? So we are going to create a actual persistent volume on mini cube and then we are going to prove how the data is going to survive even after the part is getting deleted. So we also create one small persistent volume claims uh like uh it will be a very small hands-on that we would be doing along with this but the deeper explanation for persistent volume will be the target for the specific video for today our main subject is persistent volume persistent volume claim we are going to see a segment of it because we are going to do a deep dive into the coming video. So let's start with a very simple example that is uh let's say imagine we have an application that application creates multiple files. So let's say in / data directory it is creating a file name message.txt and that message.txt file is actually printing hello from kubernetes. So now the thing is everything is working but then the pod is getting deleted right. So should we expect that the file to be still exist there? No. Why? because the 19:43:02 file was created inside the containers file system right that's the same problem we discussed in the previous videos so uh we learned about empty directory and then we came to know about okay empty directory is directly linked with the life cycle of the pod right so then we came to know about another concept that is host path right so then again the issue with host path was the lifeline of host part was directly linked with the node right if the node is deleted then the data is gone and the main thing is for real world application uh we need a volume in such a way that even the traffic is getting splitted to node one or node two that data should be intact the people should be able to use it right so if that same directory is not present into the second node then the data is not automatically available there so now we have another problem we need a way in kubernetes to represent our storage separately from the life cycle of the pod from the life cycle of 19:44:02 the nodes and that is where persistent volumes comes into the picture and this is the actual issue that persistent volume actually solves. Right? So this is what we have discussed. Now let us actually discuss what exactly is a persistent volume. So if I put everything into simpler terms, a persistent volume is a Kubernetes storage resource that represents storage available to the cluster. So the main idea over here is you just have to notice the difference with a normal pod volume we can define the storage as a part of pod but when it comes to persistent volume it is slightly different because persistent volume is itself a cubernetes object just like we created pod just like we created services just like we created deployment likewise we have to create the manifest for persistent volume so think of persistent volume as a storage that has been need available to the entire Kubernetes cluster. The storage might 19:45:03 come from different places. It can be a local storage. It can be your network storage. It can be a cloud storage. But from Kubernetes POV, from Kubernetes point of view, the storage is represented as persistent volume object. Right? So now let me make the things very much easier for you. Let us visualize it with an example. Let's say you go to an apartment in a building. that apartment has multiple storage rooms, right? So the building manager has multiple rooms available. So let's say there are three rooms uh storage rooms that we are talking about. Storage room A, it consists of 100 GB of storage. Storage B basically it consist of 500 GB of storage. Then we have storage room C, it contains 1 TB of storage. So the room exist independently from the people who use them. Now let's say a tenant comes and say uh uh hey manager I actually need a storage room with 100 GB of storage. So the building manager can assign one of those rooms 19:46:05 and that's the rough idea we are working in Kubernetes and that is exactly the concept that we would be applying in persistent volume. Right? So what exactly is a persistent volume? Persistent volume is a storage resource available in the cluster. Later the user can request the storage with the help of persistent volume claim and the pod can actually claim it. Just remember these three lines. Persistent volume represent the storage. Persistent volume claim represent the request storage and basically pod it uses the persistent volume claims. Right? So there are few acronyms that I want you to tell. Whenever I am referring to PV, I am referring to persistent volume. Whenever I am referring to PVC, I am referring to persistent volume claims. Right? Now let's compare the thing that we have already learned about. Right? Let me scroll down. Now there is one small but very important highlight that I want to tell that a persistent volume object. It's not simply a giant folder inside a 19:47:06 Kubernetes API. Uh a persistent volume describes the storage. The actual storage that can come from underlying storage system. Now it can be anything but for our learning we will be uh we are actually going to make use of a directory in the mini cube node and then we are going to create a persistent volume that will actually point to the storage location that we have defined right so before we start with the hands-on there are two topics that I literally wanted to cover and one of them is nothing but static provisioning so let's discuss what exactly is static provisioning right so stand volume is going to be created manually right That means we are going to define it by our own self. That is nothing what we call as static provisioning. So we are manually making the storage available to the cubernetes. But later with the help of storage classes which we are going to cover later uh what storage class will do it will allow Kubernetes to create the storage storage dynamically and that is exactly what we call as dynamic 19:48:08 provisioning. So uh we are intentionally not going to do a deep dive into storage classes today because that is a separate lesson. So now we are going to actually create the storage location. Remember from the previous lesson when we were learning about host path. So we learned that host path refers to the kubernetes uh node file system. So what we are going to do is we are going to create a file a folder uh directory into the mini cube node and then we are going to map it to a directory. So let's actually do it. So for that let me just switch to my terminal and here we go. So the first thing that I will be doing is I will be first creating one folder over here. So mini cube ssh and then what I'm going to do is I'll just create a new folder. So sudo mkdir for making directory as a parent and here under / data I will create a folder name pv - demo right enter. And now let us verify the same. So, mini cube ssh 19:49:11 ls - ld on / data. Okay, my bad. Clearing the screen. Yeah. /ash data / pv - demo. Enter. And here you can see our directory is actually created. This directory will act as a underlying uh storage for our uh demo for persistent volume. So now since we are talking about persistent volume from the starting let us actually create one. So let me just create one manifest file for the same vim persistent volume. Enter. I will go to insert mode. Now again whenever we are creating any sort of resource in Kubernetes we are going to make use of four keywords. API version, kind, metadata and spec. Let us write the same. So here I go API version kind meta data and here here we go with the 19:50:12 specs escape col wq and now I want to know the API version for the persistent volume. So basically I will make use of cube cuttle API resources. So cubectl api- resources and we'll do a grab on persist. Enter. And here you can see for persistent volume the API version is nothing but v1. Okay let us implement the same. Let us write the same into the manifest file. So here in the API version I'm writing the version as v_sub_1. And here let me just copy the name also. escape colon q wq and let me just copy the persistent volume text and now here in the kind I'll define the persistent volume and then again in the metadata what exactly should be the metadata over here so basically what would be the name of this persistent volume so let us give it as demo pvs demo persistent volume 19:51:12 now the next thing that we need to define is we need to first define uh the persistent volume uh capacity capacity like what would be the capacity what is the storage that we are actually looking for so here I'll define capacity and here inside the capacity I need to define the storage so storage and storage meaning how much data we want uh it to get we want to make available so one GB bits and now next inside storage then we need to define the volume mode so here the volume mode would be file system I'll brief you about volume mode also. So volume mode is file system and then after volume mode we would be defining the access mode. So access so basically when we say access mode like here we are defining how the storage can be accessed right access modes and here we'll write as read write once. 19:52:16 Now are there any different sort of access modes available? Well definitely yes. So we are going to cover this after the manifest is created. Then we have to define the persistent volume reclaim policy. Now there are again three sort of reclaim policy that we have retain, delete and recycle. So basically recycle is deprecated which we are not actually using but I'll just for your information just let you know that recycle is something that was earlier a part of persistent volume recam policy but right now it is not the only two policy that you would be looking and you would be seeing right now it would be retain or delete right. So persistent volume volume reclaim policy and this should be as retain. Now post that we'll define the storage class name. So storage class name and this would be manual and then the last thing that we need to 19:53:16 define is the host path. So host path and what exactly is the host path? So basically host part would be the path that we have defined inside the mini cube SSH to data/pv demo. This was the folder that we have created. And lastly what is the type of it? It is a directory escape wq. Let me just verify the file first. Cube cuttle apply -f persistent volume. And here it says there is an error. Let me first uh resolve this then I'll explain you each and everything inside that file. So here it says uh version v1 cannot be handle as persistent volume strict decoding error unknown field spec dot persistent volume reclaim policy. Okay. So I think there is an issue with the spelling here. It says it doesn't know it. Persist. Yeah, persistent. T E N T. 19:54:20 Okay, there is a spelling mistake. Persist E N T. This is not needed. SK Poland WQ. Rerunning the command. Okay, so the persistent volume is created. Clearing the screen. And let me do a CAT on persistent volume. Let me explain you everything line by line. So here what is the first thing that we have defined? We have defined the first Kubernetes core API version. Then here we have defined the kind. Basically we are telling Kubernetes that we are trying to create a resource of type persistent volume. And then here in the metadata we have defined the name of the persistent volume. Now what exactly is the name of this persistent volume? It is nothing but demo PV. Then here it contains the spec the configuration that exactly this persistent volume will carry. Right now here the first thing that we have defined is the capacity. Now what exactly is this capacity? Here we are defining the storage capacity for that persistent volume. Now the next thing that we have defined is the storage. So 19:55:22 here we are telling that make 1 gabits of storage available. Now next is the volume mode as file system. What exactly is this? Here we are telling to expose the storage as a normal file system. Then here we have defined the access modes. So here in the access mode we have written read write once. So what exactly is the meaning is? So here when we say read write once we are telling basically allow readr mounting from one node and then we have defined the persistent volume reclaim policy as written. What exactly is the meaning of it? Here we are actually telling to keep the storage resource available even after the claim is deleted. Next we have defined the storage class as manual. What exactly it means? It says to put the persistent volume in the manual storage class. Then we have defined the uh host part. What exactly host part is? Uh it use the directory from the Kubernetes node. Then we have defined the part of the Kubernetes node. That is something that we have defined in the mini cube node itself. And then we have 19:56:23 defined the type as directory. Here we are saying that directory is already exist. So that's the thing that we have mentioned over here. So that's the short description about the manifest file that we have defined. Let us verify the resource whether it got created or not. So clearing the screen cube get pv for persistent volume. And here we have a big output. Let me just do a zoom out. It will be easier for us to read. Clearing the screen. And here you can see here we have the entire data. So here the first thing that we have is the name. What what exactly is the name? The name of the persistent volume. Then we have the capacity. So here we we are defining that uh the storage capacity that we have defined. Then third we have the access mode. The access mode is nothing but RW that is read write once. Right. So basically there are three sort of uh read write resource. First is read only many which means that allow only uh allow read only access from many roads. Then secondly is read write many which 19:57:25 means that allow read write access from many nodes. And third is read write once part which means which states that allow readr access from one part right now let's move forward and then we have a reclaim policy and here you can see the reclaim policy is refined as retain so this tells kubernetes what should happen after the pv is released from its claim then we have the status and this is very important right now we are able to see that the status is available right so uh that status is very important. Now why we are getting available? Because the persistent volume exist but nobody had claimed it, right? That's our first persistent volume life cycle state. So Kubernetes basically defines the state available as the free persistent volume which is not bound to any claim. Right? Now what do you mean available over here? So let's focus on this word which is called available. that I have a storage room and in that storage room 19:58:27 there is a room which exist. It has 1GB available but nobody is using it. So that is exactly what available status denotes over here. So the persistent volume is ready to be matched with the suitable persistent volume claim. Now how do we mount a persistent volume to a pod? Like is there any way? So uh we created a persistent volume but the question is can I mount a persistent volume directly inside my p. Well normally that uh that model is not correct. Uh we make use of something called persistent volume claim. So the PVC is the request. Uh that is why we are going to create a very small PVC for this specific demonstration. We are not going to do a deep dive into PVC because that is something that we are going to see in the next video. But for now just for maintaining that connectivity between the persistent volume we are going to create a very small PVC to understand the workflow. So let us create a mini PVC over here. So clearing 19:59:29 the screen and let me just create vim persistent or let me just name it as PVCAML. Enter. Now again uh what are the four uh keywords that we define whenever we are using Kubernetes? API version client meta data and then we have spec and now escape colq. Now again I'll need to search the API version for persistent volume claim. How will I do it? So I will make use of cube cuttle api- resources and I'll do a grab on persist. And here you can see persistent volume claim arised. Here the API version is nothing but v_sub_1. Let me update the same inside the manifest file. So here the API version is v1 and the kind is nothing but persistent volume claim. Now comes the next part that is what would be the name of this pvc. Let me just name it as demo pvc. That would be the name of this persistent volume 20:00:31 claim. Now here let us define how the requested storage should be accessed. So here I'll need to define the access modes and here the access mode would be nothing but read write once and then the next thing that we would need to define is the request uh resource request. So resource request and here inside the request we will define the storage that we would be needing. So storage as 1 GB and the last thing that we need to define is the storage class name that is nothing but manual. So storage class name and this comes as manual escape wq clearing the screen and let me just apply cube cuttle apply fvc.ml and here again we are getting one error here it says spec.resource resource. Let 20:01:33 me just correct it here inside spec dot resource. It is not resource. It should be resources with s escape colon wq. Clearing the screen and applying the manifest file once again. Okay. Now this time the pvc is created for us. Let me just uh do a cat on pvc and let me explain you everything from starting. So here basically we are again making use of Kubernetes core API version. Here we are telling to use the Kubernetes score API version as v1. Then we have defined the kind like what sort of resource we are trying to create. So here we are telling Kubernetes that we are trying to create a persistent volume claim. Then the next thing that we are defining is the metadata. Now metadata for this persistent volume claim. Now what exactly is the name of this PVC or persistent volume claim? It is nothing but demo PVC. Now here contains the specs the configuration for this specific PVC. So here we have something called access mode. So here in the access mode we are defining how the 20:02:34 requested storage should be accessed. The request will be read right from one node and then we are defining the resources and then we are defining the storage amount that are being requested. So how much amount of uh storage is been requested. So here in the next line we have defined that here we are requesting 1 GB of storage and lastly we are defining the storage class name as manual. So here we are request will be from a persistent volume from the manual storage class. So once it is applied let us verify the output now cube cuttle get PVC and here you can see we can have few details again over here which contains the name of the PVC that we have created and here you can see the status is bound right that is actually very important because earlier if you see the persistent volume it was available now since the claim got matched it changed to bound so the Persistent volume is now bound to the 20:03:34 persistent volume claim because Kubernetes defined bound as the phase where persistent volume is bound to a claim right now. So let us verify which persistent volume claim is using which PV. So clearing the screen cube ctl get PV enter clearing the screen. Yep. So here you can see we have some data over here and here you can see the claim reference over here. So here who is claiming uh this particular persistent volume here it is nothing but demo PVC. So here it confirms that what persistent volume is using which claim right we can also make use of describe that will actually give us more detail cube cuttle describe and here we would be describing the persistent volume named demo pv okay and here if you go to claim here 20:04:36 you can see default / demo PVC this is the persistent volume claim that is actually claiming this persistent volume and I hope here we are able to identify which persistent volume is mapped to which persistent volume claim right so now since the persistent volume and the claim is ready let us now work on creating a demo pod now so clearing the screen and let me just create a demo port so demo-pody enter now again since we are creating another new resource in Kubernetes uh what are the four keywords uh that we need to remember AP API version kind metadata inspect. So let me just write the same. So API version kind metadata and lastly it comes the spec. So here let me just do escape colon wq. Let me just yeah escape wq. I'll just do a little bit of zoom so that it is easier for me to read. Now let us uh get 20:05:38 the API version for pod. Right now we are already aware for pod we are using core cubernetes API version that is nothing but v1 but let us follow the approach that we have been doing so far so that it would be helpful in the future also. So cube cuttle API resources and here I need to do a grab on pod enter. And here you can see the API version for pod is nothing but v1. Let us implement the same into the demo demo pod.l manifest. So here the API version is v1. Then let me define the kind as pod. Now let me just give the name to this pod. Now what would be the name of this pod? So here it would be let's say demo pod or persistent volume demo pod. This would be the name of this specific uh pod that we are creating. Now again inside pod what exactly has been running? It is nothing but a container. So containers. Now inside a container basically what exactly we are running we are running 20:06:39 the applications right so here let me just write the name of the application that is nothing but applica uh that is nothing but app now here I will define the image that it will be using so I'll just write a bz box which is a lightweight uh Linux image now there are few set of commands that I want to run so command here I will pass the command that it should run so I want a shell to be running then post that I want it to run few command that follows with the text and here I want the container to be alive for 1 hour right now the next thing is we need to define the volume so here I'll define volumes and here just inside the volume we will define the name of the volume name as persistent storage and now the next thing that you have to define into the persistent storage is persistent volume claim. So persistent volume claim and lastly the last thing 20:07:42 that you have to define is the claim name that we just saw. So claim name and the claim name is nothing but demo PVC. Now again you have to define the same thing just inside the container two so that it will create a map for us and it will be easier for us to uh understand what exactly has been happening. So we have created the volume now we need to mount it inside the container. So volume mount volume mounts and inside volume mounts you need to define the name. So here the name is nothing but persistent storage again. And now here you will need to define the mount path. So here let me define mount path. And here we'll define the mount path at / data escape wq. Let me clear the screen. Apply the file cube cuttle apply - f as demo pod. And here it says there is an issue with line 20:08:43 number 20. So vim demo pod and let me just fix what exactly is the issue in line number 20. So escape colon set nu. So basically set nu is used to see the uh line number. So that exactly is the utility that we are using over here. So here in persistent volume claim we have written the claim name. But here it will work like this. Escape colq applying the file again. And now the pod is created. But before even that let me just explain you what exactly we did inside this demo pod. So demo pod.l. Okay, let us discuss it once again. So here we are using the Kubernetes core API version. Then here we are telling Kubernetes the resource that we are trying to create and here we are trying to create a pod and inside that pod we are going to try we are actually trying to run a container. But before even that what exactly is the name of this pod? So the name of the pod is nothing but persistent volume PV- demo pod. That would be the name of this 20:09:46 pod that we would be referring. Then comes the settings the actual configuration for this specific pod. So here uh we are trying to run a container inside that pod. The name of the container is app. The image that has been utilized is busy box. Then there are few set of commands that we want to run. So what exactly it does? So basically here uh we are using command because we want to override the default command. Then here we are making use of shell. So we want the shells to get started. And then once the shell is started we want to execute the following command through the shell. And the command that we are actually running over here is sleep 360 0. What it does? It keeps the container running for 1 hour. Now next thing that we have defined is volume mount. So basically here we are defining the storage the container should see and then we have named the uh storage over here. So here we are telling to use the persistent storage volume. Then here lastly we have defined the mount path. So here mount path basically it says that make the storage available at / data. Then here we have 20:10:46 defined the storage. So this storage defines the volume used by pod. And then we have defined the name of the persistent storage. And then lastly we have defined persistent volume claim that is nothing but PVC. And then we have given the claim name over here. That is exactly what we did over here. The pod basically it needs a storage persistent volume claim uh basically need a request that requires a storage persistent volume basically it provides the storage. So storage is the actual place where the data is created. So the pod uses the PVC and the Kubernetes connects the PVC to the suitable persistent volume. So once it is applied, let us just verify the file. So cubectl get ports and here you can see the pod is actually up and running. Now let us do the actual hands-on for for the thing that we have actually came. So let us create a very uh let us create a basic file over here. So uh let me just run cube cuttle exact and inside the 20:11:48 persistent volume demo I want to run a shell command and what exactly that shell command would be I need to run one echo command. So echo hi from persistent volume and I want this to be stored inside the / data that we have created. Name of the file would be message txt. Enter. Let us verify the same. So cube cuttle exact into the PV demo board. And now here what exactly I want to do? I want to just run the I just want to read the file which is store inside / data and the name of the file is message.txt enter. And here you can see the message is listed in front of us. So our uh so basically our application successfully wrote the data into the s into the storage. So now let us inspect the node itself because we have done that mapping right. So now for that let me run mini cube ssh and after that I will just run 20:12:49 uh sudo cat into / data and the uh directory that we have created if you remember it was nothing but pv demo and just inside that we are expecting this message.txt to be present inside it. When I press enter here you can see high from PVC high from persistent volume high from PV is actually listed in front of us. So this is important because our pod is writing the data into slash data but on mini cube node we have defined / data as the mounting path. So now we have a completely working persistent volume. So now uh the question is how does this is different from mtdir. So let us compare it with the previous example that we have seown. So basically the storage follows the pod life cycle when it comes to empty meaning if the pod is deleted then the data is gone. But uh with our persistent volume the persistent volume is basically separate kubernetes 20:13:50 resource. So the storage is no longer is a part of pod. That is the important architectural difference over here. Now we are going to text exactly the same. What will happen to the file? Will it behave differently when a pod is getting deleted? So let me just delete the pod. So cube cuttle delete pod pv - demo pod. So now we have deleted the pod. Now what I'm going to do is I am going to recreate that pod once again. So uh once it is deleted let me just apply cube cuttlef followed by the manifest that we have created and then inside that pod we are again going to read it. So that this will give us a valid checkpoint that even after the pod is deleted. Our data is still present and we don't even have to worry about it. That was the power why we are actually learning about persistent volume claim. Now you might be getting another question that Shubam okay uh since it was relative pod you moved into persistent volume but why you are not 20:14:50 making use of host path. Now see the thing is host part again ties to a node right. So here when you create persistent volume it is in the entire cluster. Just think about that. That's the reason we moved from host part to persistent volume. Right? Now let me just apply the file cube cuttle apply f demo.tml. The pod is created. Now let me just run cube cuttle exact pod name I want to do a cat into / data / data / message txt enter and now since the pod was recreated once again we are able to see the data and this is the moment where I want you to understand that we deleted the pod we created a new pod but the data is still there Why? Because the data was not tied to the lifeline of the lifetime of the original pod. The pod was actually using the 20:15:52 persistent volume and that persistent volume was still exist. That's the core reason why we are learning this concept. Now let's talk about the life cycle of persistent volume. So a persistent volume can move through different states. The main states that I want you to remember is available, bound, released and failed. So let us understand each one of them. But let me just move to my Visual Studio Code for that. Okay. Now let me just scroll down. Okay. So these are the life cycles that I was referring to. So let us talk about available. So here when we say uh the state of the persistent volume is available. So here the persistent volume exist and it is not currently bound to a claim. Right? Now secondly comes bound. What exactly it means? So here the persistent volume is connected to a persistent volume claim. Meaning that linking is been completed. Next is release. So here the claim here the 20:16:54 claim that was using the persistent volume has been deleted but the storage has not yet been reclaimed. Now next is failed. So this indicates that the volume failed an automated reclamation process. This is something that you can use it as a first troubleshooting step but it is good to know information. Now since we are talking about the different states we already saw available, we already saw bound. Let us demonstrate release. So now actually see how release will work. So first of all let me switch to my I terminal and yep let me clear the screen. Okay. So the first thing that we would be doing is let me just do a get on persistent volume. So this is my persistent volume and here you can see the status currently is nothing but bound. Right now let me just delete the persistent volume claim that we have created. But before even that let me just list the PVC to uh cube cut PVC here. What I'm going to do is let me just delete it. cube cuttle delete 20:17:57 PVC and the name is uh name of the PVC is nothing but demo PVC. So right now what we did we deleted the persistent volume claim. Now when this is getting deleted the next thing that I would be doing is I will be just I will just run a get on PV. Then we will be able to see that uh the persistent volume is moved to released. So that is very important because the persistent volume has not simply become available. It is again released. So now what why exactly this change of status happened? Because uh the previous claim has been deleted. So the storage still contains the old data. So what does Kubernetes says about PVC? When a PVC leaves the persistent volume and the associated storage resource in the place, it puts the persistent volume into the release phase until it is manually been reclaimed. Right? So let us wait until it is getting deleted. And also there is one more observation. If you think like your terminal is stuck, basically it's not stuck. It is taking 20:18:58 some time to delete it. I'll just open another terminal over here. And if I just run cube cl get pvc. Here you can see the statuses as the status as terminating. So if you're seeing that your terminal is stuck, so don't worry. It is actually deleting your persistent volume claim. So now let me just pause the video and let us wait for some time. Once it is completed then we'll start it again. Here you can see it is still in terminating mode. So what we can do it is actually linked to the pod. So what we'll do we'll just delete the pod itself so that we can get rid of that issue. So cube cuttle delete pod followed by pv demo pod. And once this is deleted then we'll delete the persistent volume claim. Okay. So now the pod is deleted. Let me just delete the persistent volume claim 20:19:59 2. So cube cuddle get PVC and that PVC is deleted too. Now let me clear the screen. And now when I do cube cdtl get persistent volume. Here just see one thing there is a change in status. And here you can see the status got changed to released. Now there is one thing that I want to discuss in detail that is persistent volume reclaim policy which we defined into the files but uh there we didn't cover it in depth. So I want to just discuss the same. Let me just go to my visual studio code. And now let us talk about persistent volume reclaim policy. So now uh what does retain mean over here? in simpler terms if you put it into simpler terms. Here we are saying to keep the storage after the claim is deleted. So this is useful when the data is important and you don't want Kubernetes to automatically delete the associated storage when the claim is removed. So the PV the persistent volume state will move to released which we 20:21:01 actually saw and here manually uh a cleanup is required. And second option that we can make use is nothing but delete. So there are two reclaim policies that we are actually covering over here that is first is retain second is delete. So when we are saying retain basically we are saying even if the underlying resource is deleted we have that storage intact with us we will keep it but when it when we are using persistent volume reclaim policy as delete it will actually remove it. Now why did we choose retain in this demo? So I intentionally chose retain because for this demonstration uh because I want you to see how does the data survive. So we can clearly observe that the pod got deleted. The data was there. The PVC got deleted. The persistent volume then became released and the data was still there. This makes the life cycle very much easier to understand. That's the reason we took the example of retain over here. Now what about delete? So now what will what would have happened if we 20:22:01 made use of persistent volume reclaim policy as delete. So uh in that case what would have happened is when the claim is released the kubernetes will delete the persistent volume and the associated storage assets along with it. So this is how uh it behaves. Basically it depends upon the storage implementation that we are doing. That is why reclaim policy is an important architectural decision. So for production storage you should understand what storage system uh will uh what storage system you will be actually choosing but for that you should have a clarity on the reclaim policy. Now before we close there is one more thing that I want to make very clear that uh is about hostpath. Now you might be wondering that uh this is very much similar to hostpath but again there is one more big difference over here is whenever you were using hostpath it was directly linked with the life cycle of that node right you were not able to access it across the nodes that was the demerit of host path that is something that has been solved by persistent 20:23:02 volume now since we were working on mini cube that was another reason why we followed with this host path approach if you have multiple kubernetes node the same part does not automatically mean that the same storage and the same data will be present on every node. So, Kubernetes specifically wants that the local storage can make workloads dependent on the node where the storage is existing. Right? So, yes, that was all in this video where we literally covered about persistent volume. That was a dedicated video that I wanted to create on persistent volume. And yeah before we close there is one thing that I want you to remember is whenever someone asks you what exactly is a persistent volume you can say a persistent volume is a kubernetes storage resource whose life cycle is independent of individual pod. That's it. So yes that was all in this video and I hope you liked it. So yes that was all and I will see you in the next one. Thank you very much. All right. So in the previous video we learned about persistent volume or what 20:24:04 we call as PV. So there we created the resource. We understood what exactly PV does. PV basically it represent the storage available in the Kubernetes cluster. Now there is important question then let's say if the persistent volume is available then how does the application or user request that storage and this is where persistent volume claim come into the picture. So basically if someone asks you what exactly is a PVC you can just say PVC is simply a request for the storage made by the user or application. So in this lesson we are going to understand what exactly is PVC why do we even need it and how does a PVC connects to a PV right and finally we'll connect our persistent volume claim to a pod and then we'll prove that how does the data has been retained even after the pod is getting deleted. So Kubernetes defines PVC as a users request for the storage while PV represent the available storage resource. So Kubernetes binds a suitable PVC to a pod so that they can consume 20:25:05 and claim it. So now let us first understand what exactly is the problem that is solved by PVC and why do we need a PVC in the very first place. And in order to understand that let us uh take a very simple example. Let's imagine that you have a Kubernetes cluster. you have created a pu persistent volume of 10 GB of storage. Now the application says that hey I need uh 10 uh I need 5 GB of storage. So should the application developer should know like where is the storage which disk it is a part of or which node it has usually no because the application should simply say that hey I need 5 GBs of persistent storage and that request is exactly what has been represented by persistent volume claim. So if I take an example so let me just show you one example over here. So think about a renting parking space. the building owner has the parking space available. So it can be by the name parking space A, parking space B, parking space C. So you don't have to 20:26:06 worry about which exact parking space the building manager will give you. You will simply say that I need a parking space and that one request is nothing what we call as PVC. So here the parking space basically is equals to the available resource and then we are making a request for the parking and that is what has been done by PVC. So in Kubernetes PV basically acts as your parking manager who will tell you the available uh storage. PVC is something that will be represented by us because we are someone who was who is actually requesting that storage. Right? So the important idea over here is persistent volume provides the storage and PVC actually request that storage. That is the basic difference. Now since we are talking about difference let us actually see the differences between persistent volume and persistent volume claim. So uh let's put them uh next to each other. So let's first cover about persistent volume. So persistent volume represent the storage that is available to the cluster. Right? So for example in a persistent volume we mention about the 20:27:07 storage that we actually need. So we mention that the available storage that we require is 1 GB. Right? Now what exactly persistent volume claim does. So basically persistent volume claim or what we call as PVC it is nothing but it represent a request for the storage where the PVC will say hey I need 1 GB bits of storage. So the persistent volume is the provider and PBC is nothing but the requesttor. So Kubernetes what it will do it will then try to match both the request to the suitable storage. Right now before we do the hands-on for this demonstration, we'll continue with the um static persistent volume from the previous lesson. So let me just copy the same. I'll just go through the previous folder and this is the persistent volume I'm talking about. I'll just use the same because we won't be repeating the same uh thing again and again again like I can explain you everything which we have already done. But let me just explain you once again. Here we are creating an uh persistent volume whose API version is nothing but v1 which is core kubernetes object. Here we are telling 20:28:08 kubernetes that we are trying to create a persistent volume. Then in the metadata we have defined the name of this persistent volume and remember the name of this persistent volume is nothing but demo pv. Then here in the specification basically this specification is nothing but the configuration for the persistent volume and in the cap uh in the specification we have defined the capacity. The storage that we would be needing is 1 GB GB. So here basically we are telling that the storage that is available for the users is nothing but 1 GB. Then we have defined the volume mode as file system and access mode as readrite once. Then we have defined the persistent volume claim policy as retain. Then storage class as manual. And then we have defined the host path as/ data search PV and the type of the data is nothing but directory. Now let me just go to my terminal. Now here you can see my mini cube is started. So let me clear the screen and here when I do ls - ll long long list you can see the persistent volume present over here. Let me just apply the file. So cube cuttle apply - f persistent volume.ml. Let me 20:29:10 verify the same cube cuttle get persistent volume. And here the first thing that you have to observe over here is the status. It should be available. Now if you are someone who is following from the previous video and if you haven't cleaned up a mini cube then you might see release status over here. Now why that's so basically the thing is there is a file present inside your mini cube cluster. That's the thing. So before even you move forward first of all just verify whether there is any file present there or not. So mini cube ssh ls-la into the / data/pv demo right and here you can see in my case there is no file present that's the reason I'm getting the status as available. Now again if there is any single file present then the status will change to released. Right? So now initial thing is done. The first thing that we wanted was the persistent volume. Now let us create the claim for it. So vim demo pvc dotyl. Now again whenever we are creating any sort of manifest file in kubernetes what the four keywords API version kind 20:30:12 metadata and spec. Let us write the same. So API version kind metadata and lastly we have the spec. And now uh what exactly are we trying to create? We are trying to create a persistent volume claim. Where do we get the API version for the same? So we can just type cube cuttle API resources and we'll do a grab on persist enter. And here you can see for persistent volume claim the API version that we would be utilizing is nothing but v1. So let me go back again to demo pvc and here I'll update the values over here. So the API version is as expected v1. Then we have defined the client that is nothing but persistent volume claim. Here we are telling kubernetes that what sort of resource we are trying to create. Then here we will need to give the metadata basically what exactly uh the name of this persistent volume claim would be. So we are giving the name for this PVC. So let me call it as demo PVC 20:31:14 same as the file name. Then here comes the spec the configuration. what exactly will be the setting for this specific persistent volume claim. So here the first thing that we need to define is the access mode requested by the claim. So here for that you need to define access mode. Now inside access mode what all things can come access mode basically what would be the access mode for this specific PVC. So here we will define the request for the resource and the request that we would be using over here is read write once which signifies that read access will be given from either one of the node. So here I'll just mention read write once. Now let's define the resources requested by the claim. So here for requesting the resource you again have to define the same thing into the specification. So here you have to define the resources. Resources. Now what all resources are we requesting? So the first thing that we need over here is the storage. Then how much would be the storage? Now here the 20:32:15 storage would be 1 GB. So I'll define the amount of storage that I require. The re user require the application require. So here I'll define storage. Storage is one GB. See this is not GB. This is GBY. Okay. Now the next thing that we need to request is uh we need to define is the storage class name. So here I'll define storage class name. And what is the storage class name? It is nothing but manual. After defining the storage class name as manual or work is done. Let me just uh save the file. Escape wq. Clearing the file. Let me apply the same cube cuttle apply f demo pvbc. Mml. Here we are getting one error. Error from server as bad request. Error when creating demo PVC. Persistent volume claim in V1 cannot be handled as persistent volume claim. Strict decoding error. Meaning there is an issue with the YAML. YAML is strict with the indentation. Here it says unknown field spec.ac mode and 20:33:17 there is another field that it says spec.resources. So there are two places that we need to check where exactly is the issue with right. So this is something that we would be troubleshooting. So let me just go inside the file demo PVC. Okay. Now based on the error that we have uh we got actually we will try to resolve that. So let me just let me just uh take a look over here. So here it says uh cannot be handled strict decoding error. Spec.axis mode. Okay. So here if I go to spec.ac mode this is not access mode. This should be access modes. Okay. So the initial uh issue is resolved. Escape wq. Now next it says spec.resources dots storage. Okay. Spec do.resources dot storage. And here in the storage. Okay. So here basically in the resources you have to put one more entry that is 20:34:17 nothing but the request because resource is something that we are requesting right. So here I'll define the request and just inside the request I'll define the storage because that is something that we are requesting for escape colq. Now things should be good. Let me apply the file and here the PVC is created right now let us verify whether the PVC got created or not. So cube cuttle get PVC enter. And here you can see the PVC is created in front of us. Now there is one thing that I want to uh discuss before we move forward. Let me just do a CAT on demo PVC and that is nothing but the access mode. So access mode in PVC. What exactly is access mode? So we discuss access mode in detail in the persistent volume lesson. Uh so here what exactly we are saying inside a PVC we are saying that this is the access pattern I want the storage for. So here we are requesting for readride once which means readride access from one 20:35:18 node. Now second is the resources dotre request dot storage. Now what exactly this means because this is the place where we got the error right. So here what exactly we are trying to say? We are trying to say that I am requesting 1 GB bytes of storage. Now think about it exactly like requesting a resource. So pod request the computing resource. PVC will give the request to the storage and our claim is saying that we need 1 GBs of storage. Right? Then that was the thing that we have to look into. And then the next thing that we have is can a PVC request less than the persistent volume? Then the answer is yes. This is important because persistent volume provide you 10 GB of storage and if the PVC is requesting 5 GBs of storage then that is a valid match. So Kubernetes can bind the persistent volume with the earliest requested capacity. So here if the PV is of 10 GBs and PVC of 5 GBs, it is a match. Right? But again if it is 20:36:19 the reverse that thing is not possible. Right? Now there is one more thing that I want you to discuss is storage class name. Here we mentioned storage class name as manual. So what exactly is this does? This actually tells Kubernetes which storage class we are requesting. Right here our persistent volume has the storage class name as manual and the PVC also have the storage class name as manual. So they both have the same class that makes them compatible for the storage class perspective. Right now once it is done then there is one thing that we need to notice over here when we just ran cube cuttle get PVC you can see the status as bound. Now what is the meaning of this status right? So this is what we wanted. So bound here means that persistent volume clean has been connected to the persistent volume. So before if you can see when we requested for the persistent volume the status was available. But now after creating the PVC it is now mount. Let me just list the PV also. Cube cut PV. And here again you can see the status as 20:37:21 bound. Now this persistent volume claim and this persistent volume both are bounded. Both are linked. meaning the storage that we requested is actually present for us. Right? So this is our first proof that the PVC successfully the PVC successfully requested the storage and uh what will happen if uh there is no matching persistent volume for it. So here in this case let's say if we are requesting a PBC of 10 GBs and the persistent volume which we have currently uh is of 1 GBS or maybe 5 GBs. So none of these volume can satisfy that 10 GBs of request. So the PVC will remain as pending. It doesn't mean that Kubernetes has broken. It simply means that there is no suitable persistent volume available. So what Kubernetes says? Kubernetes says that uh a claim can remain unbound indefinitely when no matching volume exist and it can bind later when a suitable persistent volume is present or whenever it is available. 20:38:22 Right now uh let us discuss one more thing and that is nothing but matching process. So when you create a persistent volume claim Kubernetes looks at the request and here it says okay you have you want a PBC of storage 5 GBs and the access mode is readr once and the storage class is manual. So Kubernetes will check through the available persistent volume and it will try to find the one that will match those requirements and based on that it will try to bind it. Once it finds a match then it will bound both of them. So what exactly is happening over here? So here we have a control loop where uh the cubernetes watches the PVCs and find the matching persistent volume based on the request and the access mode based on the class and the other applicable criterias. So this is the important rule. A bound of PVC and PV have a 1:1 relationship and that is exactly what we proved right now. So now let us use the PVC from the pod. So now 20:39:23 we have a persistent volume. We have a claim. Let us create a pod with the PVC so that we can actually experience how does PVC actually works. So let us create a pod for the same. And exactly for this specific demonstration again you can make use of the previous files that we have been using. So what I'll do I'll just go back to the 21st folder and here I'll just copy the demo part because that is something that we would be experiencing over here. So here again like we are using busy box and here we are mounting the persistent storage. Here the claim name is demo PVC that is exactly the PVC that we have created and the mount path is / data. So I'll switch to my terminal now and here let us perform the operations now. So what we'll do cube cuttle apply and here we are going to apply the demo cube cuttle apply - f demo pod.ml and the pod is created for us. So cube cuttle get pods 20:40:23 and here you can see the pod is up and running. Now the first check that we would be doing is we are going to create a file inside that pod. we are going to read it. That will prove that the data is able to been written inside the pod. And then once the pod is deleted, we are going to check whether the data is still present or not. After recreating another part, right? So for that, let me just run cube cuttle exact. And inside pv demo pod, I want to run a shell command. And that shell command would be nothing but to create to create a file. And inside that file we would be writing few content and that is this is from TV. And then I will be saving this file to / data and the file name would be nothing but message txt. Enter. So the file is created. Now let us validate the same. So cube cuttle exact. And here uh in pv demo pod I want to read the file which is present inside / data directory. Name of the file is 20:41:24 message.ext. Enter. This proves that we are able to read and write the file inside that pod. Now the next thing is what will happen if we delete the pod itself. So let us verify the same cube cuttle delete pod followed by the pod name that is pv - demo pod. So once the pod is deleted we are going to recreate it and then we are going to verify whether the same data exist or not. Okay. So before even we recreate the part there is one thing that we need to check that is uh when we delete a part does the status of PVC and PV change. Let us verify the same. So cube cutle get persistent volume and cube cuttle get PVC. So see the thing over here is both the status are bound. What exactly denotes meaning there is no uh change in the status of this. Why? Because the storage is different and the pod is different. Right? So now let us apply the manifest file again. So here we are 20:42:25 recreating the pod that we deleted. So cube apply - f demo pod.l. Now we are creating the same pod. Now the next thing the next validation check that we are performing over here is we are going to check whether the file that we have created still exists there or not. Clearing the screen cube cuttle get pods. Okay the pod is running. So now let me just read the data which was present inside the / data directory. this cube cuttle exact in the pod name PV demo pod here what I want to do I want to run a shell command and here basically I want to run a cat command into the / data and the name of the file is nothing but message txt because that was the file which we created earlier and now here you can see this is from pv the text the message that we wrote inside that specific uh storage location so this is a proof that we deleted the pod we created a new one but the data remained or not. Now we can confidently say that the data actually persist. So 20:43:25 storage was actually not tied to the life cycle of the original part. Right? So here is there is one more important thing that I want to tell that PVC itself isn't the disk containing your application file. Think of PVC as someone who is requesting and binding it to the storage. The actual storage is represented by persistent volume and it is provided by the underlying storage system. So when someone says what exactly PVC does it points to the storage assigned to it and what exactly PV does it represent that storage and storage is the actual place where the data has been hold that's why PVC is not equals to data right let's talk about a very nice uh separation about the application of PVC let's imagine that uh you have a Kubernetes uh cluster and there is an administrator who take care of persistent volume storage classes and storage system so the developer basically what he will do he will create a persistent volume claim and he will just mention his specification his need whatever he want he will say that I need can b he will say that I need 10 GBs of 20:44:27 storage I will need uh this excess mode I will need this class so the developer will not necessarily need to know the underlying implementation and here that request will be taken care by PVC and that is exactly what is the application of persistent volume storage so now let us talk about static provisioning so in this lesson uh we are using static static provisioning because our persistent volume was created manually by us. So this is uh what we demonstrated today. So Kubernetes supports uh so Kubernetes has a support for both manually created persistent volume also dynamically provisional persistent volume which can be done with the help of storage classes that we are going to see next. So uh there is one more important uh concept that we need to talk about that is nothing but protection. So let's say when we run cube cuttle delete PVC followed by the PVC name. So Kubernetes has a protection mechanism and the PVC will remain in termination stage. So why basically it will wait for the port to stop because uh it is a potential threat for the data 20:45:29 loss in order to avoid that it has this it has this protection mechanism. Let us verify this uh let us verify the same. So here I'll switch to my terminal again. And now what I will do I'll just run cube cuttle get pods and here you can see uh the uh demo pod is running cube cuttle get pvc now what I will do I will just delete this PVC cube cuttle delete PVC followed by the PVC name that is demo PVC here uh so here what it says persistent volume claim deleted from the default name space but again if I open a new tab and here if I just do Do a zoom cube get PVC enter. Here it says it is terminating but exactly it is stuck over there. Why? Basically this is preventing the accidental data loss because the volume is still active. Now in this case what exactly should be done? So basically here basically you will have to first free your pod. So once you 20:46:30 delete cube cuttle delete your pod followed by the pod name that is pv demo pod then only your persistent volume clean will get released right that was one of the important concept that we wanted to discuss right so here uh the important difference that you have to keep in mind that is if you remember only one difference that would be very much helpful that the persistent volume is the provider and persistent volume claim is the requester that's it that's the entire summarization ation of persistent volume and persistent volume claim. So here Kubernetes bring those together for a pod and then the pod will utilize the PVC and through that it can actually utilize the storage. That was the whole idea. Now if someone asks you what exactly is a persistent volume claim then in a single line you can actually answer answer them what exactly is a PVC. So what exactly is a PVC? A PVC is a request for persistent storage made by the user or an application in Kubernetes. Now here just important 20:47:30 three lines persistent volume is the storage is someone who is providing the storage persistent volume claim is someone who is requesting the storage pod is someone who will utilize the PVC and that's the entire graph entire mind map of PVC so yes that was all in this video I hope you have learned from this video and let me just show you the terminal meantime uh since it was hanged earlier so here you can see earlier it was uh stuck into termination but then when we deleted the pod Right? The PVC is also deleted. So that was the demonstration. Right? So yes, that was all in this video and I will see you in the next one. Till then keep learning and thank you very much. All right. So we already learned about persistent volume and persistent volume claim and we are clear that persistent volume is actually representing the storage and persistent volume claim actually uh represent the request for that storage. Right? But there is one thing that we are doing manually over here and that is nothing but we have to create the persistent volume by ourself. Right? Now imagine that you are managing 20:48:32 a cubernetes cluster and inside that cluster there are multiple applications which are running. Now let's say there is application one right. So yeah now let's say there is application A that needs 10 GB of storage. There is application B that needs 50 GB of storage and there is application C that needs 100 GB of storage. Right? So do we really want an administrator to manually create the PV every time whenever someone requested right so that is the problem that has been addressed by storage classes and in this video we are going to learn about storage class along with we are going to understand about dynamic provisioning right but before even directly jumping into directly provisioning let us first understand what exactly is storage class in the very first place so if I put everything into simpler term so basically the idea is what problem are we trying to solve over here so Let's say when an application ask for a storage then Kubernetes should be able to create the storage automatically. That is something that we are going to discuss over here. Now the first thing is why do we even need a storage class. So imagine that 20:49:34 you have a Kubernetes cluster and that cluster has access to different sort of storage. Now what are the different sort of storage options that we have? First is standard storage, second is fast SSD and third is high performance storage. So different application may require different storage option. Let's say if you have an application A that may require a standard storage then you have a application B that might require a fast storage. So we don't want the application developer to worry about which disk should I create, which uh storage API should I call and like how do I create the volume. This is something that Kubernetes should take care by itself. Right? So basically what exactly we want? We want the administrator to create the storage class and then storage class will describe what kind of storage should be created and which provisioner should create it. Now when I say provisioner here provisioner meaning it can be AWS, it can be any cloud, it can even mini cube, it can even be your local storage. Right? Now let us take an example. So if you want to understand uh storage classes, the very best example for it 20:50:36 would be to ordering a cab. So let's say you are ordering a gap. So you don't need uh you don't need to create a car. You simply will say that hey I need a ride. Apart from that what exactly you will be choosing? You will be choosing uh the car options. So it can be economy, it can be premium. So this service already knows that which vehicles to use and how to provision them and how do we satisfy the users request. So storage class also works in a similar pattern. The user will create a persistent volume claim and it will say hey I need 10 GB of storage. That is exactly what we are doing. Basically what we will be doing, we will just create a PVC and there we'll just say hey I need 10 GB of storage and this will use the storage class and the storage class will tell the Kubernetes that which provisioner should create the storage and that is exactly what we call as dynamic provisioning. Right? So right now we understood what exactly is a storage class. Now we understood what exactly is dynamic provisioning. Right? I hope that thing is clear. There is one 20:51:38 more thing that I wanted to clear is storage class is not the storage. Storage class itself does not contain your application data. It it is not a disk. It is not a directory. It is not a persistent volume. Think it about as a template or a set of instruction for creating the storage. Then the provisioner follows the instruction to create the actual storage. Right? And I already mentioned you about what exactly a provisioner. Right? Let's come to dynamic provisioning. Right? Now we just saw a slight introduction to dynamic provisioning. Let us understand what exactly it is. So dynamic provisioning basically uh it is a storage created automatically when it is requested. If you remember earlier we created a host path right and before even that we have to create that mount path right here when we talk about dynamic. Dynamic means something that is done automatically. So the storage is created automatically whenever it is requested. So you don't have to manually create the persistent volume first and the request will actually flow from the persistent 20:52:40 volume claim and just remember the only thing that you will have to worry about is the PVC because what exactly PVC denotes it denotes that I am requesting for the storage and that is how Kubernetes will see the request right so the storage class here will tell which provisioner should be used and the provisioner will create the storage and Kubernetes will create the persistent volume representing that storage and the PV VC will be bound to it. That is something that is happening automatically over here. Right? So now let us begin the tutorial. And here in this video again I will be making use of mini cube. So if you are using cubedm or kind feel free to do the same. But again there is one more thing. If you feel like to start with a new or fresh profile there is a mini cube command that will help you out with uh creating a new profile. So you can start with creating a new profile and this will actually help you to create and start from the scratch right. So now uh let me just switch to my terminal and here we are actually start and here we are going 20:53:40 to create the storage class first. So here we are okay right now I mean by terminal so the first thing that I will be creating is nothing but a storage class. So the YAML file that I will be creating over here right. So here let me just create vim storage - class dotyl enter. And now what are the four keywords whenever we are creating any sort of manifest file in Kubernetes API version kind metadata inspect. So now let me just define the same. So insert mode API version. Let me just do a little bit of zoom. Yep. API version client. I'll increase the brightness for myself. Okay, meta data and here comes the specs. Now again what exactly are we trying to create? We are trying to create a storage class. Okay, so that is something I'll define over here. Storage class. Make sure that S and C in storage class is in uppercase. Now how do I know what exactly is the API version for it? 20:54:41 So again for that we have a best friend for us in the console itself. We'll just write cube cuttle api- resources and we'll do a grap on storage. Let me first run the storage. And here uh we'll find the API version for storage class 2. And here you can see the API version for storage classes is nothing but storage.k8s.io/v1. All right, let me go back to my storage class file and here I'll update the API version for the storage class. All right. So here we define the storage class. Uh here we define the API version for storage class. Next we define the kind the resource that we want to create. Now let me just name this uh storage. Uh so let me name it as demo storage. Storage. And now let's come uh to the specification the configuration for this specific storage class. Now again when it comes to storage class we really don't have any sort of specification here. Basically you will have to define the provisioner. Now if 20:55:42 you remember I mentioned about the provisioner can be anything. It can be mini cube, it can be your Azure cloud, it can be your GCP cloud, it can be even your local storage. Right? So here we don't need specification in this case. Right? Here the only thing that you will have to define is nothing but provisioner. So provisioner now how do I know what exactly will be the provisioner from mini cube? So you just go to internet and search for provisioner for mini cube and that is how you'll come to know the provisioner for mini cube as kats.io/minicube mini cube- hostpath. Now this is the uh like this will tell the Kubernetes which provisioner will create the storage right and then the next thing that we would be defining is nothing but reclaim policy reclaim policy and here the reclaim policy that I will be defining is delete delete and the last thing that I will need to 20:56:43 define is the volume binding mode. So volume binding mode and here the volume binding mode will be immediate. Let me explain you everything from starting. First of all, let me clear the screen. Let me verify my file to cube cuttle apply 1f storage class. Okay. So here it says storage class demo storage is created for us. Let me just run a cat into the storage class. Mameml and let me explain you each and everything line by line. So here we'll start with the API version. Here the API version is storage.kest.io/v1. This tell kubernetes which API group which API group and the version this resource belong to. And here we are saying that this storage class actually belongs to storage.est.io and the API version is v1. So this tell Kubernetes to create a storage class object. Next we have kind. So here we are telling that we want to create a 20:57:46 object name storage class to the Kubernetes. Now here comes the metadata. Now what exactly would be the name of the storage class that is nothing but demo storage. Now here you can just uh write anything for now since we are doing the demonstration. I just wrote demo storage over here. Now here comes the main part that is provisioner. What exactly is provisioner? So this tells Kubernetes who is responsible for creating the actual storage. The answer over here is ks.io mini cube- hostpath. So that's the mini cubes hostpath provider. And this is the part that makes dynamic provisioning possible. Right? If you are provisioning through AWS, if you are provisioning it through Azure with GCP, this value might change. But since here we are learning it for the first time, provisioner that we are using is nothing but mini cube host path, right? So a storage class provider identifies the uh provisioner responsible for dynamically creating the persistent volume. I would again like to emphasize on provisioner. So let us understand what exactly is a 20:58:47 provisioner. Right? So a provisioner is a component that actually knows how to create the requested storage. For example, the provisioner might be anything like uh let's say if you want to talk to AWS, GCP, local storage, right? The storage class doesn't create the storage itself. It will tell the Kubernetes to use this provider. Then the provisioner will handle this creation and Kubernetes basically it will describe the provisioners as the component or the plug-in that is responsible for creating the provisional class the provisional storage for the storage class. Now the next thing that we have defined is the reclaim policy and that is again as delete. So this answer what should happen to a dynamically provisional persistent volume when it is deleted right because here we are making use of delete what exactly delete denotes over here so whenever a claim is released so the persistent volume which was created automatically will delete automatically over here that's the meaning of it right 20:59:47 so here in reclaim policy we have two options present so first is retain second is delete so basically what delete does whenever a persistent volume claim whenever a claim name is deleted whenever a request is deleted it will automatically delete the persistent volume right and second is when it comes to retain so what will happen if a PVC is deleted the persistent volume will still be there it will be retained now for this demo we are explicitly making use of delete why because I want to show you how does dynamic provision is different from automatic cleanup because earlier if you remember we were automatically cleaning up all the resources here that headache is solved right so Kubernetes will dynamically create the persistent volume and as soon as we release the PVC or whenever we delete the PVC you can observe how does it deletes the persistent volume too right last thing that we have over here is volume binding mode and that is nothing but immediate right so what exactly does it controls when should Kubernetes provision and bind the 21:00:48 storage so again here we have two option first is immediate and second is wait for first customer so let us understand both let us understand about immediate So what it does the volume is provisioned and bound as soon as the PVC is created. So we can actually observe this in the following demo in the current demo only and the main thing is the pod doesn't even have to exist over here right and when it comes to wait for first customer the this option basically when we can use it so this means that don't provision and bind immediately wait until a pod actually uses that PVC this is specifically useful when we want to follow a storage topology what is the difference between immediate and wait for first customer so whenever a persistent volume claim. Whenever a claim is created, it will automatically create the persistent volume wait for first customer. What exactly it will do? It will wait for a pod to use that PVC. Right? For this specific demonstration, we will make use of immediate because it makes the dynamic provisioning process easy to understand, easy to visualize. 21:01:48 Right? So now since we have applied the changes, let us verify the same. So cube cuttle get storage classes and let me remove the autofill. Enter. And here you can see we have two storage classes present in front of us. First is the demo storage. Clearing the screen. Let me just show you here. Yep. So first is the demo storage which is the one that we have created. And there is a standard and the default storage class which was created earlier. Right. In order to get more detail about storage class, let us run cube cuttle describe storage class. And the storage class that we are interested is nothing but demo storage. Now here there are few things that we need to look at. First is the provisioner. So here you can see the provisioner is nothing but mini cube. Second is nothing but reclaim policy. So here the reclaim policy is delete. And third is nothing but volume binding mode and that is nothing but immediate. These are the three things that you should check every time whenever you are dealing with storage classes. So this is 21:02:50 a useful command for troubleshooting. So basically whenever you will face any sort of error you will make use of describe right and these are the parameters that you should actually check whenever you're creating a storage class for the very first time right now here we have something called parameter you might have observed that in parameters it shows as none so that is intentional because the parameter field contains the provisioner specific instructions so different provisioners can understand different uh parameters. Now when I say parameters it can be the configuration. If you are into cloud storage then it may have different parameters for example d types for example performance tier or uh it can be related to the replication setting. But for our mini cube the host path provider doesn't need any parameter for this specific demonstration. So let us leave it as it is. So now let us focus on create the persistent volume claim. Now vim uh let me call it as pvc.l. Now again I'll make use of the four keywords API version 21:03:53 metadata and spec escape colon wq. Now again in pvc if I want to know the API version for pvc what it would be. O cube ctl API - resources we'll do a grab on PVC enter and uh let me just check API resources reso ur okay API version is nothing but v1 I'll go back to my file and here I'll update the API version for the persistent volume claim now what exactly are we trying to create here we are trying to create a persistent volume claim so persistent volume claim and just remember we didn't create any persistent volume. Let me just show you first. So cube ctl get PV and here you can see there are no resources present for persistent volume. Now why I why exactly I highlighted? So basically whenever we are applying this PVC a persistent volume will get created 21:04:54 automatically. That is something that we would be verifying. Okay let me go back and continue editing my PVC file. Okay. Now here let us define the metadata for the persistent volume claim and here I'll just name this as dynamic uh since it will be creating the uh persistent volume for us automatically. So I will call it as dynamic PVC. And now let me define the specification for this PVC. First thing that I will be defining would be the access request mode. So here I'll define the access mode and here inside the access modes I will define the first access mode over here that is nothing but read write once and then the next thing that I would be defining is the storage class name. Now what exactly is the storage class name? Now right now only we created one demo storage that is nothing but the storage class name. So let me just define storage class name and it is nothing but demo storage. 21:05:54 Okay. So demo storage is created. Now the next thing that we would need to focus on is nothing but we need to define the request. Right. So for that what exactly we are requesting? We are requesting the resources. So let me just define resources. Resources. And inside resources what exactly we want to request? We want to request let's say 1 GB of storage. So I'll just write request and here inside the request I'll define what exactly I want to request. I'm requesting nothing but storage and the storage is nothing but one gbytes escape colon wq clearing the screen again cube cuttle apply - f pvc.ml enter and here you can see a persistent volume claim is created for us but before even me explaining you the uh file let me just show you something. So cubectl get PVC clearing the screen. Cubectl get PVC enter. Here you can see a persistent volume claim is created for us. Right. 21:06:55 Let me show you over here. Yeah, clear over here. Right. Okay. Now here you can see we have a persistent volume claim created for us. Now when I type cube cuttle get PV. Earlier you remember I showed you there was nothing present over here. But as soon as I created a claim, a persistent volume got created automatically. That is the first observation that you should check whenever you are dealing with dynamic provisioning. Right? Here again, second thing that you need to check is the status. The status here says that it is bounded. Right? And the third thing that you need to check is the claim name. And here you can see it's dynamic PVC. That is exactly the name of the PVC that we created. Which means that this persistent volume claim is able to identify the persistent volume that got created automatically dynamically. Right now we didn't even created any pod and it got created automatically. Let me just explain you the file that we have created. Now so cat on pvc.yamel. So again what exactly this file does. So 21:07:56 here the first thing that we are defining is the API version which tells that we are using Kubernetes core API. Then here we are defining Kubernetes. We are telling Kubernetes what sort of resource we are trying to create. Here we here we are telling Kubernetes that we are trying to create a persistent volume claim because we want to request 1 GB of storage. And then here in the metadata we have defined the name of this PVC. What exactly is the name of this PVC? It is nothing but dynamic PVC. Then here in the specification, this specification is for this PVC that we are creating. So inside the specification, the first thing that is defined is nothing but the access mode. What exactly it does? It defines the requested access mode. Now what exactly is the access mode? In this case, we have defined readr once. So this request uh read access from one node. And then we have defined the storage class name. And what is the storage class name? Demo storage. And that is exactly what we have defined over here. Now here we have defined the resources that we want to request. So here we are defining that we want a resource and we want to request a storage on 1 GB. That is exactly what we 21:08:58 did right now. I hope that made sense. Right now let us create a part that will finally help us in understanding dynamic provisioning over here. So here let me clear the screen and here I'll write vim dynamic dynamic portl enter now again api version kind metadata and here comes the specs and here I'll define the API version for pod. So what exactly is the API version for the pod? I don't have to remember this. But since we have been doing from long now we remember the API version for pod is nothing but v1. Then here I'll define the kind uh what exactly is the resource that we want to create. Now here let me just name this pod and here I'll just write dynamic dynamic storage part. This will be the name of pod that we are actually trying to create. Then here whenever uh we are creating pod 21:09:59 what exactly we want to run inside that pod we want to run a container. So I'll write containers and here we'll just define the name of that container. What should be the name of that container? Uh it can be anything. So I'll just write application uh storage. So let's say it is a storage application. Now the next thing that I will be defining is the image that it will be utilizing. So image will be you can make use of Ubuntu or anything. I will make use of busy box for now. busy box and then the next thing that is uh that we want to run few commands whenever this container is created right so for that I'll just write command and what exactly are the commands that I wish to run right first is I need to run a shell and inside that shell that uh I need to pass one parameter so whatever uh things come that uh so whatever things whatever things that comes after hyphen c it will consider it as a text and it will execute it and it will execute it as a following command. So here we want to execute sleep for 3 600 21:11:00 0. What exactly this will do? This will actually make sure that my container is running for an hour. Then here last thing that we need to define is nothing but the volume and volume mounts. Let us define the volume first. I'll just write just below the containers I'll write volume and here inside volume. So let me just give a bit space over here. Yeah. So it would be easier for us to read. So here inside volumes I will need to give it a name. So name and this will be nothing but app-en storage. And then the next thing that I will be defining over the uh volumes is nothing but uh persistent volume claim. So here I will tell actually use a persistent volume claim as a volume source. So here I'll write persistent volume persistent volume claim and just below persistent volume claim I will need to define the claim name and what is the claim name. So claim name is nothing but 21:12:01 dynamic PVC. All right. Now we have defined the volumes. Let us define the volume mount. Right. So here just inside at the level of the container specification I will define the volume mounts. So here I'll write volume mount and here in the volume mounts I'll define the name of the volume mount. So what is the name of the volume mount? Here we have given the name as app equals to app. Here the name of the volume mount is nothing but app storage. And then the last thing that we need to define is the mount path. So basically why we are defining the mount path. So basically here we are telling the container to mount the storage at / data which will be inside the container. So mount path as / data escape wq clearing the screen and let me just apply the file. So this is the file that we have created that is dynamic port. So cubectl apply f dynamic port.l. Here we have an 21:13:03 error and it says unknown field specs. Uh let me just go inside there and here this is nothing but instead of spec it should be spec. Clearing the screen. Let me apply it once again. Now this time we are getting another error. Here it says unulfilled as volumes. Okay. And there is a strict decoding error that we are getting. Okay. There might be an issue with the indentation that we need to correct. Okay. So I just entered it at the same level of spec. So I'll just fix it right now. Right away. Escape colon wq. It was nothing but the space issue. Now let me just apply. This time it should work. And now the pod is created for us. Let me verify the same. So cube cuttle get pods. And here you can see the dynamic storage pod is created for us. Right now let's write some data inside this pod. So for that we will make use of cube cuttle exact. So cube cuttle exact and here we need to run the 21:14:03 commands inside the dynamic storage pod and here I will run a shell command for creating the file. So let me just run one echo command over here and the file that we would be creating would be nothing but inside / data and the name of the file is message txt and what data I will be printing inside that file would be um this is uh dynamic storage example. Okay, enter. And here the file is created. Now let us verify the same. So cube cuttle exact exact in dynamic storage pod I want to run a cat on / data / message txt enter and here you can see the data is printed in front of screen. Now here what we created we just created one 21:15:04 simple text file inside this latch data and we actually tried to read it. So we are able to see everything. Now there is one thing that I want to observe. I want you to observe here is let me just list the current status of the port. So cube cuttle get ports. Here you can see the pod is running. And now let us list the persistent volume and persistent volume claim. Enter. Here you can see. Okay. And here you can see both the persistent volume are in the status bound. And here our container is actually here our pod is actually running right. So basically what we are going to do right now we are going to do some persistence test. Let me delete this pod. And now basically when we delete the pod our idea is uh the PVC should not be deleted. It should be still there. Right? Because we are able to see that the current status of the PVC and the PV is bound. Right? So now let me just delete the part. So cube cuttle let me just do a little bit of 21:16:05 zoom for you. Uh all right so cubectl delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delet delete f d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d dam. ML and here we have deleted the pod. Now after that let us verify the statuses of persistent volume and the claim right because here we are telling that uh it is independent of the pod but again we are verifying whether it is getting deleted or not right. So let us wait for the port deletion. Once it is deleted, let us verify the persistent volume claim. And it should be still there. It should be still in bound status, right? 21:16:46 Okay. So the pod is deleted. Let me just uh list the persistent volume and persistent volume claim. Enter. And here you can still see the statuses for the persistent volume as bound and the status for the persistent volume claim as bound again. Right? Which proves that the uh which proves the relationship between the persistent volume claim and persistent volume into a into a dynamic pattern. And here it is not individual to a pod. Now let me just recreate the pod once again. So cubectl apply f dynamic pod.l. Now here the pod is created for us. Now what exactly we are trying to do? We are actually trying to we are actually trying to see whether the data is still persistent or not. So now let me just verify the pod. So cubectl get pods and its pods. Get pods enter. Here the pod is up and running. Let me just run cube cuttle exact in the pod name dynamic storage pod. Here I want to run a cat on 21:17:49 / data / message txt because that was the file which we created. And now here you can see this is dynamic storage example. The exact message is printed in front of us. What exactly we did? We delete basically we had a old pod and we created a persistent volume claim. Automatically a persistent volume got created since storage class were handling things at the back end. We didn't even have to worry about anything. Now what we did we deleted the pod then a new pod came we have the same PVC we have the same persistent volume and we have the same and we have the same storage. So here our data remains that is exactly what we wanted to test. Right now here we are going to test the reclaim policy because if you remember in the uh manifest file itself we have defined the reclaim policy as delete. Let me just show it to you once again. So cat on storagecl class. Mamel here you can see the reclaim policy we have defined as delete. So what we are going to do is we are going to delete the pot first then we are going to delete the 21:18:50 PVC and then we are going to immediately check what is the status of PV whether it is getting deleted automatically or not because as per the definition it should be linked with the persistent volume claim. As soon as the claim is deleted then the persistent volume should also be get deleted. Right? So now let me just clear the screen. cubectl delete-f dynamic port. MML. Now this is to delete the port that we have created. Now before even deleting the claim, I will first show you the current status for the persistent volume claim and the persistent volume. Then we'll delete the claim so that we are able to see the live change what exactly will happen to the persistent volume. Right? So now let us wait for it. 21:19:47 Okay, now the pod is deleted. Let me show you uh let me show you the persistent volume. Now cube kettle get persistent volume and persistent volume claim. Okay, now here just pay an attention here you can still see. Let me just do a zoom out easier to read. Okay, here you can see the status for the persistent volume is bound and the status for the persistent volume claim is again bound over here. Right? Now what I will do? I will delete the persistent volume claim that we have created. Right? So cubectl delete appc.ml and now our persistent volume claim is deleted. Let me clear the screen now and let me just run cubectl get persistent volume and persistent volume claim. Let me just do a little bit of zoom. Enter. Here you can see node resources are found. That is exactly what happens with dynamic storage provisioning. So the dynamically created persistent volume is actually 21:20:47 removed as Kubernetes reclaims it as per the storage policy that we have defined. And in the storage policy what we have defined we defined the storage policy as delete and that is the benefit of using a storage class with it. Right? I hope you got a lot about this video and I believe dynamic storage provisioning is clear to you. Let me just switch back to my visual studio code and here you will find entire documentation for the things that we have learned so far. So yes, today we learned about two concepts that is nothing but storage class and secondly we learned about dynamic storage provisioning right so yes that was all in this video and I will see you in the next one till then keep learning and thank you very much all right so let's start and let's move to another important topic in Kubernetes and that is nothing but config map so let's say in an application there are many values that change depending upon the environment now Those values can be anything. Now let's say if you are working into core your uh core API 21:21:49 equals to that value can change depending upon the environment. Also you can also define the app_env as development as integration as prod. So what are these values? These values are nothing but what we call as configuration. So uh these are not really the part of the application code itself and we don't even want to rebuild it with the code that we are actually building the image for. Right. So for example, let us say that you have a docker image by the name app/v1 and uh basically the thing over here is this image is been utilized in development, in testing and in production. But the configuration can change. For example, let's say your database host for production. The value may differ with the value that has been present in integration and in the development environment. So that is something that is been solved by config map. Why? Because we don't want to build a completely new image just for this configuration changes. And those configurations are actually handled by 21:22:50 nothing but config maps. So what exactly is a config map? So if I put it into simpler word, a config map allows us to keep a nonsensitive configuration separate from the application image to make a configuration available to the pods. Right? Right? Now here we saw the problem statement. We came to know that let's say if an application uh has a dependent value. Now what is that dependent value? That is nothing but the configuration. Now based on your environment these values can change. Uh let's say the database uh the host can change for uh integration and it can be different for the production right the log level that is info sometimes maybe it may be one and also the app port it may be different from development to the testing and prod right. Likewise, these are nothing but the configuration data. And how do we manage this configuration data, these values in Kubernetes? Well, basically this is something that has been solved by config maps. In this video, we are going to see what exactly is a config map. Why do we even need it? 21:23:51 Right? So, what is the actual problem that has been solved by config map? Let us take an example to understand config map. Okay? So imagine that our application needs uh this app env as development and second is the database_host as MySQL. But uh we cannot put this value directly inside the container port. We cannot put this value inside the container image. Why? Because these value will be changed afterwards. Right? So uh the thing is imagine we need to deploy this application into the production. Will it be a fair thing to change the code just for that configuration change? No. So here in application we handle those changes, those configs separately. Now here there are two approach. Either you follow it uh with the environment variable or you can directly pass a environment variable file. So the application code will remain intact. It won't be changed. The only thing that will be changing up across the environment would be nothing but the configuration change. So if 21:24:53 configuration uh will be baked into the image then what will happen then you will have to rebuild the image and every time there will be unnecessary build that you will have to work over here right. So the thing is what solution we want we want a solution where our application image remain intact where exactly the main code is present and we want the configuration separate. So when both of these work our application will show us the desired result. So here the thing is the application image stays the same. Uh the configuration can change independently and that is the problem that has been solved by config map. Now if you want to understand config map in a simpler term. So let us imagine that you have a TV at home. In your TV basically just imagine that your TV is nothing but an application and there are multiple settings when you watch a TV right there are multiple modes where you can adjust the brightness where you can adjust the volume right. So based on that you can particularly say that you're not changing the build of your TV 21:25:54 you are changing the configuration inside it meaning the setting can change but the application remained intact. So here basically what we are doing the application code is staying the same. The only thing that we are changing over here is nothing but the configuration that is something that we do with config map. So if you understood this example now let us see what exactly is a config map. So what exactly is a config map? So in a simpler terms, I know this is clear to you now. So a config map is a Kubernetes object which is used to store nonsensitive configuration file. I'll repeat once again. Config map is used to store the nonsensitive data in Kubernetes. Okay, here because these things are used as environment variables which we can put it to the code, right? So here the thing is we don't want to bake a new image. If we want to pass this configuration as a file or as a variable. So Kubernetes stores these values as a key value pair and the important part is config map stores the 21:26:55 configuration not the application data. That is again an important point that you have to keep in mind. So Kubernetes sees that config maps as object storing the non-confidential configuration data. That is exactly what is the definition of config map. Now we understood what exactly is a config map. But what all things should go inside a config map? It can be all the things that may vary over the time. For example, your environment variable, right? Uh it can be your ports, it can be your host name, it can be your feature flag and it can be a configuration file or it can be your environment specific settings. For example, uh let's say your env. So here you can see the app env. This may vary from uh environment to environment. Right now here you can see it is for development. But again this setting may change for testing. This may change for production. Likewise the app name. So here you may call a core application as shopping hyphen API into dev and test. 21:27:55 But usually if you're calling it into the production then it may be v_sub_1 or v2. Right? So that can be the difference that you can see. So again I'm just giving you the example to understand what exactly uh the things that we can pass into the config map. Right? So what are these? These are nothing but the configuration. So here there is one more important thing that you have to keep in mind that we don't make use of configuration. Uh we don't make use of config maps to store the password, tokens, private keys or any sort of confidential information. For that we have another resource in Kubernetes and that is nothing but secrets. So uh for sensitive value we basically make use of Kubernetes secrets which is an appropriate context that we would be discussing in the coming video. But for now let us focus on config map. And before even we move forward there is one more thing that I want to highlight over here is config map is yeah before even we move forward there is one more thing I want 21:28:56 to highlight over here is that config map is not a storage volume. So here the thing is config map is not like a storage volume because uh we have came across with mtdir host path and persistent volume but a config map is a kubernetes object and kubernetes give different way uh to make that configuration available to the application. Now again there are two methods you can either pass the config maps as environment variable or you can pass the values via the environment variable file. So these are the two methods and both of the methods we are going to see right now. So on that note, let's get started and create the first config map file for us. Let me switch to my terminal. Okay. And here we are. So the first thing that we would be creating over here is nothing but the config map. So let me just create one. So here we go. So vim and name of the file would be app-config. Enter. Now again since we are creating a config map which is again a resource in Kubernetes. What are the four keywords we need to define into the manifest 21:29:56 file? API version kind metadata inspect I'll define the same. So API version kind. So what exactly we are trying to create? We are trying to create config map and then meta data and lastly is the spec. Now again what is the API version of config map. Now again we have two methods over here. Either you can go into cubernetes documentation or you can make use of cube cutter API resource. Now since we are inside the terminal itself, we will make use of cube cuttle API resources. So cubectl api- resources and let us do a grab of config map. Enter. And here you can see for config map the API version is nothing but v1. I'll copy it and I'll again go back to my app config.ml. And this is the place where I will be updating the value for config map. So here we have defined the API version as v1 which says it is a Kubernetes core API version. Then we have defined kind which says the resource that we are 21:30:57 trying to create in Kubernetes is nothing but config map. Now what would be the name of this config map. So for now let me just give it the name same as the file that we have created and it is nothing but app config. Now again now here comes the specification. So what all things actually come into the specification into a config map. So here since we are creating a config map now what exactly a config map is config map is something which stores the data for the environment variables and value and here the kubernetes stores the value in key value pair right so here you don't need spec specifically here basically you are storing the data you need to define the data and now here just define the values that you you want to put so now let me take example here I'll take example of app _ env for now let me make it as development and let us take one more example for the env. So it can be uh let's say let me just give the app underscore name for 21:31:58 now and the app name can be anything for now let me uh say it as core okay escape colon wq clearing the screen and let me just apply the file cube cuttle apply - f app-enconfig and here it says config map/app - config is created so what exactly has happened over here if I explain it to you once again here Here we defined the Kubernetes uh version and then we defined we are trying to create a config map. The name of the config map is app config and here we defined two config map. So basically here we are storing the value in key value pair. So here the key is app env and the value is development. Let us verify the same. So cubectl get config map and here you can see app-en config is present over here. And now there is one more thing that I want to show you over here is the data. Now since here we defined two keys that is app env and app 21:33:00 name. Here the data value is nothing but two. That is something that you have to keep in mind. So here the data column tells us how many keys are stored. Now let us see the actual contents of this config map. So for that what you will have to do let me just copy the name of config map. We'll just make use of describe. So cubectl describe config map and here the name of the config map is app config and here you can see inside data you have the value of app envs development and app name as there is another method where you can verify the name of uh verify the values for your kubernetes config map and that is nothing but cube kit get config map and here I'll Define the name of the config map as app - config - o yl enter. And here you can see we have the data for the config map that we have saved. So here the name of the config map is app-en config and 21:34:02 here is the data which is present app_v as development and app name as score. So these are the two ways through which you can verify the values of your config map. So what is the difference between describe and cube cuttle get config hyphenoml? So when you type hyphenl this shows the actual object stored in kubernetes but right now the pod is actually not utilizing this values. So now let us think uh let us create a new pod that will actually use these values. Now before even we move uh further there is one more thing that I want to you to tell that is nothing but about namespace. Now we are already aware that namespace is a isolation that we can create based on the environment. Right now since we are working into development right now I haven't defined anything. So everything will go into the default name space but again the same configuration of the config file can be utilized into multiple name spaces. So that is something that I wanted to clear over here. Right. So here when you are 21:35:05 making use of name spaces the file name can be same but the values may differ. Okay. So now let us create the pod which will be utilizing these values. So let me just create u the file name would be config map uh - envl and here let me again define the four keywords. So API version metadata and spec. Now here in the API version let me define the API version for pod. Now for pod the API version is nothing but v1 and here let me define the kind. The kind is nothing but pod. Let me give the name to this pod. Now what would be the name of this pod? Let me just give it as config let's say config map envy pod. This would be the name of the pod. Now here under the specification basically what do we want to run inside a pod? we want to run a container. So here I will define the specification for the 21:36:06 containers containers. And here the first thing that you will need to pass is the name of the container. Now what we would be calling this container. So let me just call it as app uh application container. This would be the name of the container. Now which image it would be utilizing? It would be util utilizing the busy box image. uh again you can make use of Ubuntu also like it's upon you. Now again here there are few set of commands that I want to I want to run over here. So command now what all commands I want to execute over here. So the first thing that I want to do is I want to start a shell once the container is up and running. Then here I will pass hyphen C. Now what hyphen C does whatever text that falls after uh this will take the it will take it as a Linux command. So sleep 3 6 0 0. So this will make sure that my container is up and running for 1 hour right and then now let me define the environment 21:37:06 variable for it. So how do we define the environment variable over here. So here you need to define the word env. And just below that you will be defining the environment variable right. What is the first environment variable? Escape colon wq. Let me do a cat on app config. So here we have defined the environment variable as app env and app name. Let me just update the same over here. So when I go inside env. I'll be updating those value. So app env is the name. So here let me just pass the name as app env. This is the first environment variable key. Okay. And now basically we have defined the name of the environment. So here what we are telling uh what we are telling we uh trying to create the app environment variable where will it get the value from it will get the value from the config map right. So here you will need to define value from and here we are going to define 21:38:08 where it will get the value from. So basically value from is the keyword it's used to get its value from another Kubernetes object. Now what is the name of that Kubernetes object? It is nothing but config map. Now again here since we are making use of config map you need to pass a reference over here. That's the reason we are making use of key refs. Config map key reference right. And then here now the last thing that you will need to pass is what is the name of the config map. So here the name of the config map is nothing but app config. Let me show you once again. cube cuttle get config map and here this is the name of the config map that we utilized into this manifest file. I'll go back again. So here we defined the first uh config map value and here we need to define the key that it should read. So here what exactly is the key that we are looking for? So inside this 21:39:09 config map you will find a key name app - config. inside this app - config what key it should refer so basically here I will define the key and what is the key name key name is nothing but at app env likewise we will copy this entirely because we will need to do the same thing for the next variable escape wq and what is the next variable when I do cube cuttle let me just do a cat into app config the second variable is app_ame so let us do the same for app name so what I will do I will copy this entirely because this is something that will get repeated over here into insert mode and I'll just paste the value over here. Now here here I need to define the app name that is the variable that we have used over there. Second the value would be from config map key reference and what we is the key that we are looking for it is nothing but app name escape col wq let me just verify yeah so everything is uppercase and that is what we have defined in this manifest file. So now 21:40:10 let us understand what exactly this manifest is doing. Right here the new thing that you see over here is env. So what exactly it says? It says inside the container we have an environment and this tells Kubernetes that create the environment variable inside this container. Then you have seen value from. Now what is the meaning of value from? It means that don't directly write the value here. Instead use the value from another Kubernetes object. Now here we have Kubernetes config key map reference which is this one. So what exactly this what exactly this means it says read one specific key from the config map and the config name is nothing but app-config and the key that we are looking for this specific variable is app env likewise it will follow for the app name as well so the number of environment variables are there the number of lines will be increasing over here and that is how you define a config map key reference inside a pod inside this manifest file Right. So that is the basic thing over here. So 21:41:12 what exactly it means? It says that go to the app - config search for the key name app_ame take its value and put it into this pod. And that is how the environment variable will be available inside this container. Now let me just save this file. Escape col wq clearing the screen. And let me type cube cuttle apply f config map env. Mml. Here it says pod - env pod created. cube cl get pod for verifying it. And here it says the pod is up and running. Now the next thing is we are going to verify the environment variable. So for that we will need to run cube cuttle exact and we would be executing command on config map env. And then here I want to print the environment variable. So print env. And here we need to do a grab - e on let me pass the environment variable 21:42:14 value. So app env. And the second thing that we need to verify is nothing but app name. Okay. Enter. And here you can see the environment variable value is defined over here. And here this value is actually coming inside from the container right and this is actually what we can say is the use of config map over here. So if you noticed one thing what we did for each environment variable we explicitly selected a key for example we mentioned over here is app env then we mentioned app name this means that we have control over exact key that we want to expose. If I didn't want to make use of app name, I would have opted it inside while I'm creating the pod itself. Right? So this gives us the free hand that what sort of configuration we want to choose for a container. Now there is another way. Now since if you remember when we were creating this pod at that time there were multiple lines that we were passing 21:43:15 over here which I personally felt that this is too many information that we are passing. Now is there any another simplified way where we can pass a simple file through which the container will be taking the input from? So yes the another way is nothing but env from. So instead of selecting every key individually like this we can import all the keys from config map and the field can be made available with the help of env from. So for example here what it will do basically you will define a file and it will take all the values from it. So it will be just one single input. So let us create an env from example. So for that let me clear the screen and let me create a file from env from pod doy. So this would be the name of the file. Now again here we are going to create a pod itself. So here what I'm going to do again api version for pod it's nothing but v1. Then kind we are trying to create a pod. then uh 21:44:16 meta data. So this would be the name of the pod. So here we will call it as env from - env from - demo- pod. This would be the name of the pod. And lastly what we would do is we will define the specification for it. So spec and in the spec I'll define containers and here in the container I'll define the name of the container. So what would be the name of the container? container name would be application env. And here I will define the image. So image is nothing but BZ BZ box and after image I will define the commands that I want to run inside it. So here command and here I want to start a shell first sh and then next thing that I want to do is I will pass a hyphen C and then I want to keep the container running. So sleep sleep 36000 0 and then next thing that 21:45:19 we need to define is the main thing that we are looking for and that is nothing but env form. So here env form will import all the configuration from that uh file right. So here let me just uh let me just define the same. So env from so where are we taking the env from? We are taking it from config map. here config map reference and then here you need to define the name of the config map that we are talking about. So name the name of the config map was nothing but app-en config. Now escape colif name of config map to cube cuttle get config enter and yeah app config is the name of the config map. Let me apply the manifest file. So cube cuttle apply - f env from pod and here it says error converting yl to JSON line 15 mapping rules not allowed in this context line 15 okay let me go to the file line 21:46:20 number 15 escape colon set a new line number 15 says here okay uh there is one issue with the command I need to correct this okay env from we have defined and here we have defined the config map reference And we have defined the name of the config. Okay. In line number 15, it says this. Let me just uh rerun the command once again. Here it says the env from pod converting YAML to JSON line 15 mapping values are not allowed in this context. Okay, I got the issue. So basically the issue is over here. So here basically I was messing with this. Now escape colon wq and now let me just apply the file and this time the pod is created. Okay, sometimes even I will have to check what exactly is the error. So now let us verify the same. So let me just list the pod cube cuttle get pods and here we are 21:47:22 we are able to see that config map env from demo port both are actually running. Right now let us verify the values from it. So what I will do I will just run cube cuttle exact in env from demo pod and here I want to print the environment variable value and I want to do a grap on the values that we pass through that config map file so here what are the uh things that we are looking for first of all I'll pass hyphen e over here and here I'll define app env and second thing that I'm looking for is nothing but app name so these are the two values that I am actually searching for. When I press enter, here you can see all the values are actually imported with just one single command and that is nothing but env from. Here we actually made use of env from keyword that helped us in importing all the key and value from the files that we have defined in the config map. So these are the two methods which you can make use of when you are working with config map. Right? So uh here if 21:48:25 you want to see the difference between config map key reference and environ. So here the thing is when you make use of config map key reference here the config map will basically select a specific key from that dictionary but again if you make use of env from it will import all the environment variables which are present in that config map file. So the easiest way to remember is config map key reference will select specific keys and config map and secondly environ will choose all the environment variables which are present in that config map. Right? So here we learned about these two way and the second way to use it is via a config map files. So environment variable are one way but application doesn't always expect the values in key value pair. Sometimes they expect the values through a file. Again how do we identify it? Now again it depends from application to application. Few application expects the value in k value pair which we just saw and few application expects the values the configuration mounted through a specific 21:49:25 file. Now it can be for example anything it can be app.properties and inside that app.properties you will have the application configuration. So now we just saw the key value pair example. Now let us see filebased config maps. Right. So for that let us create a config map for the same. So clearing the screen and here let me create app file config config. ML. Now again here we are trying to create a config map. So again what are the four keywords? API version kind metadata and here since we are making use of config map we don't need to pass spec here we will be passing nothing but data okay now what is the API version for config map we just saw in the API resources the config map version that it is actually utilizing is nothing but the core cubernet is API version and that is nothing but v1 now what exactly is the resource that we are trying to create we are trying to create a config map. So 21:50:26 here we have defined the kind as config map in the metadata. Let me just define the name of this config map. What is the name of this config map that we would be calling? So I'll just call it call it as app- file config. And now let us define the data inside is so here basically I will store a multi-line text under the app.properties key. So let me just define the key. So app dotproperties and inside this app.properties there are multiple keys that I will be passing inside it. So what exactly are those? So first thing I will be just giving the I will be passing is the name of the app. So here app dot name is nothing but uh let's say cart - api and second value that I will be passing is the environment variable. app dot environ environment and that is again what exactly we can call as development and now that's the thing that we have defined over here and that's it. Now here if you have noticed 21:51:27 something very important that is nothing but app.properties. Now this is something different that you have seen so far. So the value will contain multiple lines over here and when we mount this config map as a volume kubernetes will present this key as a file. That's the basic logic why we are making use of app.properties over here. So let us apply this file. Clearing the screen you ctl apply - f ff fileconfig.ml. And here it says uh error converting to JSON. Line number 8 could not find colon. Okay, let me just go to web. In line number eight escape colon set nu. This command is a Linux utility that will show you the lines on the left hand side which you can see right now over here. Now here it says that on line number eight it is expecting a colon over here. Okay. API version kind metadata and inside data we have defined the app properties and inside app properties we have defined a grip and 21:52:29 those values are actually present inside it. This should be inside app.properties. SK WQ. Let me apply the file and here config map for uh and here config map for app file config is created. Let us verify the same. So cube cuttle get config maps and here file config is created in front of us. Right? But here you can see the data as one. Why? Because we passed app.properties. Now that app.properties will act as a file for us. Right? Clearing the screen. Now since we have created the config map now again it's time to create a pod that will be utilizing this uh values. So let me just create a pod name config map volume dotl enter. Now again uh we are making use of pod. So API version would be nothing but v1. So API version v1 then kind would be nothing but pod. And in meta data I will define the name 21:53:32 of this pod. And the name of this pod would be nothing but config map volume. And now here I will define the spec for this pod. Now what exactly runs inside a pod? It is nothing but the containers. And what would be the name of this container? We will call this container as app volume. And then here we will need to pass the image busy box. And now I will I actually wish to run few commands once the container starts. So the first command that I want to run is I want to start a shell. Then after starting a shell I want to pass few commands and here that's the reason I'm making use of C. And then here I want to keep the container running. So initial thing is done. Now here earlier if you remember I mentioned that we need to mount this configuration as a volume. So we need to define a volume first. So how do you define a volume in Kubernetes? So first of all just at container level itself I will define the volume. So volume and inside volume I will be defining the 21:54:32 name of the volume. So the name would be nothing but uh config volume and then after config volume I will need to define the config map. So config map. Now what is the name of the config map? So escape wq. The name of the config map is nothing but config file app. Name of the config map is nothing but app. Name of the config map is nothing but file config. I'll again go to my pod and here I'll update the value for the config map. And here the name of config map is nothing but file config which we just saw. Now since we have created the volume now we need to mount it inside the container. So here what I will do just below the commands here I will define the volume mount. So volume mounts and here in volume mounts I need to define the name of the volume that we are referring to. So here the name of the volume is nothing but config volume. So here I'll just pass one hyphen and 21:55:34 just below it I will be passing the remaining parameters. What are the remaining parameter that is nothing but the mount path. So mount path and the mount path is / env and let's say we want to put it inside the my application folder. So my app. So here we have mounted the volume and next thing that I need to correct over here is nothing but inside volume I need to pass on hyphen and here these all will go inside it. Okay. Now I think indent uh the indentation is correct. escape colon wq clearing the screen cube cuttle apply - f config map volume pod enter and here config volume pod is created cube cuttle get pods okay so here you can see config map volume pod is up and running now uh what exactly we did we have a volume and that volume defines uh that volume is defined for the pod and here I just want to make 21:56:35 one differentiation that it is uh very different from MTDIR or host path or persistent volume that we have learned instead we have made use of config map over here so the source of this volume is nothing but config map let me just do a cat on config map volume board and here this is what I am talking about here in the volume we are not creating any sort of empty directory we are not creating any host path we are not making use of any persistent volume here we are making use of config map that's the reason we have passed this file basic Basically the purpose is we are passing this file. That's the reason we have created this for you because the nature of your applications are like they are not expecting a and b variables as key value pair. They expect the values from in terms of files. Right? And now that's what exactly what we did over here. Now the next thing that we would be doing is let us verify the changes over here. Right? So now let me just clear the screen over here and let us get the value out of it. So cube cuttle exact the pod name is 21:57:39 let me check the pod name config map volume pod and here what I want to do I want to print the environment variable which are present inside it but before even that what we will be doing is we will first list the app.properties properties file that we have created. So config map volume pod and here I will do ls-la and where we have stored that file we have stored that file into /c/myapp right if you remember so I will just define /c/my app this is the folder that we have defined enter let me just run it once again I'll just zoom out okay uh / ets/myapp and here it says no such file is present over here ls-en Okay. Command terminated with exit code one. No such file or directory present over here. Okay. So we need to verify whether that file got created or not. Uh let me just list the files over here. 21:58:39 Config map env. Here we have created uh the volume pod. And now cat on config map volume. And here we are referring to app file config. Okay. So cubectl get config maps. And here we already have app file config which is present over here. So it should actually utilize inside it. So it should have listed a file named app.properties in front of us. Uh let me just check it once again. Okay. So I got the issue actually in the mount path we have defined the path as /nvn/my app and here we are actually checking the value at wrong place that's the reason we are getting that output here we are checking in / c/my app but the mount path that we have defined is nothing but/ env/my no worries let us 21:59:39 correct the same so what I'll do I'll just run cube cuttle exact config map and here we'll do a list on / env / my app and here you can see app.properties that file that we were referring to is actually present over here. Now let us read that file. So cube cuttle exact config map volume pod and here we need to run a caton / env / my app and inside that we need to read this file. Name of that file is nothing but app.property. properties that we have created. Right? Now when I press enter, these are the two values that we were looking for. First first is app dot name that is card API and second is app.tnv that is nothing but development. So this proves that config map mounted to a volume will be passed as a file to the application and that will be served 22:00:39 that will be present into the specific directory where it should be present and here in our gate and here in your case it is nothing but/ env/myapp right so the application now can read its configuration as a normal file now why we should use a file instead of environment variables so basically it depends it is conditional because some variable because some application expect the values in form of environment variables and few expects it in the way of configuration file. So this is something that we want to run. Now uh that application file can be anything. It can be your application yl, it can be your app.properties, it can be your engineext configuration. So in that case config map provides us with both these two option where we can pass the value as k value pair or we can pass the value as a file. Right? Now one more thing a config map can contain multiple files. Right now here we created a single file called app.properties. Now likewise you can create multiple files over here and you can just append the data list and it 22:01:40 will create multiple files over here. So all the files will then get mounted into /c file. So let me just show you what exactly I'm referring to. So here in your case what we have done we have just added app.properties properties and this considered uh this was considered as one file. Now let's say your application require multiple files. So here you can just add on to the current uh uh current data space and it will actually create all these environment variables inside the directory that we have defined inside the pod. So that was exactly what I was referring to earlier. Right now we are going to look something very important over here and that is nothing but what if we change the value of the environment variable. For example, right now we have been utilizing the app name or app env value as development. What if we change it to production? So does a running pod automatically see that new value? So now the answer depends upon how the config map has been consumed. Right? So now basically here we have 22:02:41 seen two methods. First the value has been consumed through key value pair and second the value is consumed through the file. Let us check through both the methods and then let us fall to a conclusion. How does the port consumes the environment variable? Right? So let us update the filebased config map. So first we are going to test uh the config map that is currently mounted as a file. And here in our case it is nothing but app file config. So what I will do I will just uh first list the cube cut config map and here you can see we have all these three all these two config map which is present. Right now what I will do I will just edit this config file and what I will do I will do a live edit over here. So cube cuttle edit config map and the name of the config map is file config. What I will do over here just in appendv I will just update this value to production. 22:03:44 And now just save it. escape colon wq. Now you have saved the file. Now let us find the value over here. Right? Now let me just check it into the pod where this config map has been mounted. This config map is mounted to cubectl get pods. And we have mounted this config into config map volume. So now what I will do I'll just verify the same cube cuttle exact in config map volume. What I want to do, I want to print the environment variables uh which are present into the app.properties. That is something that we have done right now. So, kon / uh it was on env/ my app and inside that we had uh app dotproperties enter. And here you can see the value got updated and here the value changed from development to production. Now if you have noticed here we didn't recreated the pod the mounted config 22:04:44 file eventually reflected the updated config map right so uh file updation does it means application reload will basically know kubernetes will update the mounted file that does not mean that it will automatically restart or reload the new configuration right so imagine that your application does like this your application starts it reads the application properties it stored the configuration in a memory later when config map change it will refer to the file that we have mounted. So the application may still use the old values in the memory. The application itself needs a mechanism to detect and reload the new configuration. So from this we can come to a conclusion that when we update the file right the application is not updated automatically with the new file. That is an important distinction. Right? Now let us test with another method. So here we are going to update the another uh configuration for the config map that is nothing but for app config right. So let me just edit it. So cube cuttle edit config map 22:05:46 and the config map name is app config. Now here here we have env as development. Let me just mark it as prod over here. Insert and this will go as prod and here in core I will change it to v1. And that is exactly what we are doing over here. Now after doing that let us save this value and let us verify the same escape wq and we have saved the file. Now what I'm going to do is I will just print the value which we have saved over here. So cube cuttle get config map and here the config map we are referring to app config o yl and here you can see the app env changed to prod and the app name changed to v1. Okay, that is one thing that you have to observe over here. Now let's check the pod that is utilizing this value. Right. So let me just list the pod. So we have the pod already present over here. Earlier we made use of config map volume pod and this time let us check the value of this because this pod is utilizing 22:06:49 this config map. So let us verify the value for the same. Clearing the screen cube cuttle exact into this pod config map env pod and here I will print the environment variable and here I will be printing the environment variable for let's say grab on app env because here we named it as prod here you can see it says development what about the env name we made it as v1 but It is again core right. So through this uh what we can say here the environment variable didn't change. Why? Because the environment variable part of current container process. So what actually happened over here when the container started the config map actually shared the value of app env. Here in the case it was development. Then the container start and it started to do the process based on the value that it got. Later we changed that value from development to prod and app name 22:07:50 from core to v1. Right? So Kubernetes did not rewrite the existing environment variables for the already running pods. This will be applied to the newly created pod. So that is why whenever a new container or a new pod is created, these are the values uh that will be reflected over here. The one that we updated inside the config map, right? So Kubernetes says uh that the config map values are consumed as environment variables and they are not updated automatically inside the running pod. Right? So now what we'll do, let us do one experiment. Let me just delete this pod. Cube cuttle delete-f config map env pod. Enter. And we have deleted this pod. Now what I will do, I will just recreate that pod once again. So cubectl apply - f. Okay. Now let us wait for the pod to get deleted. And after that once it is getting created we'll again verify what exactly is the environment variable value for app env and app name. Why? 22:08:53 Because we changed the value right we changed the value from app env to from development to prod and app name from uh core to v1 right now the pod is created. Now let me just verify the value for app env here you can see now earlier it was app uh earlier you can see the app env was development now it is app now it is changed to pro now if I change if I check the value for name here you can see earlier the app name was core and now it is v1 so with this we come to a conclusion that whatever values we changed it didn't change on the current running ports it changed for the next coming ports. That is something that we defined over here. Since this is a new container process, it started from the config map that was changed. So it received the current value that we made over here. Right? So now let us discuss about the behavior with the environment variable where we pass it as a key value pair and when we pass it through a file. 22:09:54 Right? So when uh a container starts take the value from the config map and the environment variable is set later when we changed it the environment variable didn't change the current running pod it got updated to the newly created pod. The second observation was with the mounted file and in that mounted file how it was working the config map was been pointed to a file that we have created that is nothing but app.properties properties and that file since it was mounted to that specific pod the values got changed eventually but again remember when you update a file it doesn't mean the application got reloaded okay that is the key distinction over here right another important benefit is that container image can stay the same here you don't have to worry about changing the image tag again and again just because the configuration is changing now here you can use the same image for development for testing for prod the only thing that will be differing over here There is nothing but the environment variable values and here we saw two methods through which we can actually change it. Right? Now here this is something that we have done through manifest file. Now 22:10:56 does Kubernetes provides a way where we can define the config map imperatively. Well yes so far we have created the config map with the help of YAML. Now let us uh do the same with the command line approach. How do we do it? So let us do the same. So basically here it's very easy. You just have to write cube cuttle cubectl create config map and the name of config map. So config map and the name of the config map would be nothing but let's say example config. And now what we will do we will need to pass the uh key value pair. So for that we will make use of hyphen -y from -y lit and then we will pass the key value pairs over here. So from lit let's say the app name is equals to is nothing but uh shupam do ai enter so let me just correct it as cubectl cubectl enter now here you can 22:11:56 see x - config is created this is the command line approach through which you can create the config map what exactly I did I gave a instruction cube to cubernetes by cubectl to create a config map and the name of The config map should be x - config. And now here I'm passing from literal that actually what it does it will help us to create the environment variables. What is the key over here the app name is the key is nothing but app name and the value is nothing but shubami. Let us verify the same. So cubectl get config maps and here you can see x-config is created. So cubectl describe config map and the name of config map is x config. And here you can see app name is present and the value for uh the same is also listed over here. So these commands are actually useful when you are working in Linux environment. Okay. Now there is one limitation that you should keep in mind when you're working with the config map because uh don't think like since we are storing key value pairs in config map then it allows 22:12:56 us multiple uh database storage. No, it's not like that. The maximum storage that Kubernetes can document for config map is not more than one megaby bytes. Right? So if config map data is more than 1 m bytes, it won't be helpful for us. Right? Don't think about config map as a database or a huge data repository. Config map is just indented for configuration. And that's the actual use case over here. Now you might be wondering now let's say if I'm running on production and I don't want someone to change the config map for it is there any way is there a particular way where kubernetes provides us with a solution where no one is hampering our manifest file for that specific config map right because if you remember we on the runtime only we have changed the config map itself and the values were getting reflected when it was through a mounted mode but again let it be mounted mode let it be through uh key value pair I don't want anyone to touch the uh configuration file of the config map 22:13:57 when it is running on production. Right? So for that what exactly we can do here? We can make use of immutable config map. What exactly is immutable config map? Immutable something that is uh what exactly is immutable? Immutable means something which cannot change. Right? So in config map we have something called immutable tag. So that tag basically based on the flag that you share. If it is true then basically you won't be able to change the value over here. Let us see how exactly it works. So let me just create a new config map over here. So that that will give you the clarity how does immutable works into the config map. So vim immutable config. This is again a config map that we are going to create. So API version for this would be again v1 kind would be nothing but config map. And now meta data. Now let me just call this as imitable config config. 22:14:58 Now again here the next thing that I will be defining is nothing but data because here when we are dealing with config map we are nothing uh we are not we are actually working with the environment variable values. So now let's say that we are working on app env and we are working on production production. All right. And now the last thing that you have to keep in mind when you're working with config map and you don't want anyone to override it, you make use of immutable tag as true. Okay. Now what exactly it will it will do? Let me just tell you. Let me first apply the file cube cuttle apply f immutable config.ml. And here you can see the file is created. Let me explain you the manifest file first. Basically it is a very smaller manifest file so that it will be easier for you to understand what exactly is happening behind the deck. So here basically we have defined the core kubernetes API version which you are already aware of. Here we are trying to create a config map. We gave the name to that config map. Here in the data we have provided the key value pair uh the environment variables that is 22:15:59 that is nothing but app envs production. Here there is a new term that we call as immutable true. This actually prevents future changes to the config map once it is applied. Now let me just tell you what exactly is the current value. cube cuttle get config map and the name of config map is nothing but immutable config - o yl and here in the kubernetes object you can see the app env is nothing but production right now let me just edit this file so cubectl edit config map and the name of config map is nothing but immutable config enter now what I will do as earlier we edited the file and changed the value from development to fraud. Let me just change this to from production to let me just change it to development. Okay. Now what will happen? We made use of immutable as true, right? And when I do escape colon wq enter, you can see we got an error. Why? Because we won't be able to update 22:16:59 this value. And here we got an error. Config map immutable config was not valid. Data forbidden as field is immutable when immutable is set as true. Right? That is the basic use case of immutable tag. If I go back again to cube cutter get config immutable config. You can again see the value didn't got changed. Why? Because of that specific keyword that specific tag. Whenever you implement immutable as true, no one will be able to edit it because that is something that we have set it for future. So once it is immutable, you cannot modify the config map data. If you need a different configuration then you have you will have to create a new config map. Right? So uh do we need immutable config every time? No. Basically it's an optional feature that has been provided for uh that has been provided by Kubernetes. For this specific lesson we have kept the config maps as mutable because we want to demonstrate how does the uh config map variables values can change and how does 22:18:00 it behave. Right? So immutable configs are useful when configuration should remain fixed and you want to prevent accidental changes. Right? I hope in this video you have learned about config map and this was really a very good concept that you will usually use into day-to-day life. Right? And again uh whatever things that we have done it's already pushed into the GitHub repository by the time you are referring this docs things will be already present into the GitHub repository. So yes that was all in this video and I will see you in the next one. Until then keep learning and thank you very much. Okay. So in the previous section we learned about config map. We understood what exactly it is. We know that config map is used to store the configuration such as your app env. Uh now it can differ from your environment to environment. It can be production, it can be dev, it can be testing. Now there is one more thing that we emphasized on that is config map actually store the non-confidential information that is nonsensitive information. Right? But now consider that your application needs 22:19:02 values such as your DB username, your DB password, your API token, right? So these are something that we categorize as a sensitive information, right? Which cannot be shared directly. So this is the place where Kubernetes secrets comes into the picture. And here basically when we are talking about Kubernetes secrets, we are talking about sensitive values. And before again we start with Kubernetes secrets there is one thing that I want to clear from here only that is when we talk about Kubernetes secrets does it give you complete foolproof uh security well the answer is no because Kubernetes secrets is used for encoding your password right now again uh focus on my word encoding I'm not talking about encryption right encoding and encryption both are two different words encoding means here we are doing B 64 encoding which can be decoded Encryption is another layer that we can encrypt with right. So when we are using any sort of encryption method, it is kind of difficult to decrypt it. But 22:20:02 again, Kubernetes doesn't take care of that. For that you can make use of different security mechanism, right? Okay. So on that note, let's get started with Kubernetes secrets. So now we understood what exactly Kubernetes secret is. But first of all, let us understand the problem statement that Kubernetes secrets is actually trying to solve, right? So now let's imagine that you have an application and your application needs to connect to your database. Now if you want to connect to the database there are two things that you will need that is your username and password. For now, let us take an example of MySQL, right? In order to connect to MySQL, there are two things that you need. You need the username, you need the password, right? If you're coming from Docker, you already know whenever you want to spin a container, these are the two values you definitely need for sure, right? But again, what are the possible options that we have when we want to spin up such sort of application? So, the first option is to put them directly into the application code. Well, this is the bad idea. Second option that we have is to bake these uh values inside the container image 22:21:01 itself. So again that is a wrong idea. Third option that we are left with is to put these values inside the body. That is again not an ideal case. So what really is happening over here is we want our application to take the secrets from a place where it is storing the sensitive values. So here the application will remain unchanged. So basically your code will be intact right like your code will work independently just like config values here we want to refer we want something that actually your application refer and it will be able to utilize it and your application will be running fine that thing is actually been designed by Kubernetes and that issue is been solved by Kubernetes secrets right in order to understand Kubernetes secret in again a well manner let us take the example of your house now let's say your house is nothing but your application, right? In your uh application, basically whenever you want to go inside your home, you need to a key. That key is nothing but a sensitive information. You do not share it with anyone, right? And you have a dedicated 22:22:03 place in your home to keep that key. Likewise, in Kubernetes, Kubernetes actually stores your sensitive information, your credentials in secrets. So that is how you will be able to understand Kubernetes secrets, right? So here what exactly is happening? your application can use the secrets without the credential being the part of the application image itself. Right now I mentioned that uh Kubernetes secrets are very much similar to Kubernetes config map. So let me just uh tell you a brief about what exactly is the difference between them. Okay. In config map we are storing the non-confidential information or the configuration. Now it can be anything. Here you can store the environment variable for your training uh your production environment, your testing environment. Now here see I am making use of the word name as variable. Variable may vary right. So these are the values that you store in config map right but again secrets is actually used for sensitive information. Now what can be that sensitive information? It can be 22:23:03 your password. It can be your API key. It can be your SSH key. It can be your registry certificate. These are all the things that you store in a secret. Right? So if someone asks you what is the difference between config map and secret you can definitely say that config map is used to store nonsensitive information and secrets are actually used to store the sensitive information that is the fundamental difference between both of them. Now when I talk about secrets uh like it doesn't mean that it is completely encrypted. So if you remember at the starting of the video itself I mentioned that when it comes to secret it is encoded not encrypted right? So when I when someone says secret is equals to completely encrypted password that is actually not true here kubernetes secret sees the values as a data field and basically these values are B 64 encoded right. So base 64 is a encoding pattern it is not encryption right. So if someone types admin then the B 64 value would be something like this that you can see 22:24:04 over the screen. So if you type admin so so if you type admin your value will become something similar like this which can be decoded from anywhere right anyone who have this encoded value can actually decode it and can get the password. So secrets provide Kubernetes an object for storing the confidential data but the thing is you need to provide proper security controls over here. So I think enough theory is done let us work on creating the AML files and here we are going to create our first secret. So let me just switch to my terminal and yep here we go. So here we we are actually considering that here we are working on a database. Now let's consider my SQL for now. Now for my SQL there are two values that you will be needing as a credential that is nothing but the username and password. So let us create a secret file for now and this will be very much easy believe me. So vim db- secrets secret doy enter. Now again whenever you are working with any sort of manifest file 22:25:05 in Kubernetes what are the poke keywords API version kind metadata inspect. But again if you are coming from previous video you are already aware that when we are working with config map at that time we define data and here when we are working with secret we need to define the type of secret right. So now let us work on that. So first of all let me define the API version kind metadata and then here we need to define the secret type. So I will just define type escape colq. Now again what sort of resource we are trying to create? We are trying to create a secret. Where do we get the API version for secret? Now again you can refer the cubernetes docs or you can make use of API resources. So cubectl API - resources. I'll do a grab on secret. Enter. And here you can see the API version is core Kubernetes API version that is V1. Let me go to DB secrets again. And here I'll update the value for API version. Okay. So API version is sorted. What exactly are we trying to create? We are trying 22:26:06 to create a secret. Okay. So here I'll type secret. Now again what could be the name of the secret. Now since we are creating the secret for database. So let me just name it as DB - credentials. Okay. And the next thing is type. What is the type of the secret? So basically there are multiple type of secret that I will show you later after this. But for now just focus on opaque. Now what exactly opaque is? It will store the arbitrary value that we are providing and it will store it as a text value. So here the type is opaque. And now what are the values that we want to provide? For that we need to provide the string data. So string data and now here I will provide the actual values that we want to keep as a secret. So first of all I will provide the username and the username will be admin and let me pass the password and the password would be pass at the rate 123 hash. So this is the password that we want to create. Escape colon wq and 22:27:09 yep the file is saved. And now let me just apply the file cube kit apply - f dbsecs.ml. And here you can see dben credential is created for us. But before even we go with the inspect and everything. Let me first do a cat on db secrets and let me explain you what exactly we have created over here. Okay. First of all, we have defined the API version as v1 which is telling Kubernetes that we are making use of core Kubernetes uh object. And then here we are telling that we are going to create a secret. Then third we have defined the metadata for the secret. And what is the name of the secret? The name of the secret is nothing but DB credentials. Now here comes the important part. This is something new that we are seeing over here. That is nothing but type. Then the type is nothing but opaque. What is the meaning of opaque? Opaque is a general purpose default secret type for userdefined values. Right? Then the next thing that we have defined is the string data. What exactly it means? It allows us to write the secret values as normal string. And 22:28:09 then we have defined the secrets that we actually want to keep. So these are the thing that we have created. So we don't have to manually convert these values as B 64. Kubernetes will take these value and it will store internally and they will mark it as a secret as a secret configuration. Now let us verify the same. So for that let me clear the screen. cube and then I'll type cubect ctl get secret enter. And here you can see db credentials is created. The type is opaque. And here you can see data s2. Now if you remember there are only two keys that we have passed over here that is username and password. And if you're coming from config maps this thing will be very much similar for you because this is exactly what we were looking in config maps. Right now let me just inspect the secret and let us try to get maximum out of it. Because if you remember when we inspected our config map at that time the value for this config map was actually exposed. But will that be the same case with secrets? Well exactly it should not. Why? Because secrets are actually uh we are telling 22:29:11 that it is a confidential information right it is a sensitive information. So now let us verify the same. So cubectl describe secret and the secret name is DB credentials enter and here you can see the DB credential name is mentioned since we haven't created any sort of name space it is falling under default name space let us focus out two things that is the type the type is opaque and here is the data now if you see here we can see these two value what exactly is the meaning of this thing you can see the key names but Kubernetes didn't display the actual values over here Okay. Now let us try to internally look how does cubernetes is storing it as an object. So for that what I'll do clear the screen cubectl get secret and the secret name is db - credential - o yl and this is how we will see how does kubernetes is storing them internally. Now here you can see there is some value that we are able to see over here. Now here you can see these values are present but exactly we 22:30:13 type something different. If I do a cat into my DB credential uh DB secret, you can see the username uh we entered was admin and the password that we entered was passed at the rate 1 2 3. But here there is some different value present over here. What exactly does it mean? Basically here uh Kubernetes performed B 64 encoding over here. Right now again I'm repeating one more thing. Encoding is not equal to encryption. So if you want to decode it, you can actually just run a B 64 decode command and you will be able to get that uh value over here. Right now how do you decode it? So basically uh for that you need to go to the documentation I have created. It's a very basic command. So I'll scroll down and here basically you can find this this command which you can make use of. So here basically you are running cube cuttle get secret in the db credential the secret that we have created and then we will print into output json path and then we will be decoding it same thing that I mentioned earlier and now here when I press enter here you can see the 22:31:14 value of the password when I do a cat on db secretsl here you can see the password that we have entered was pass at the rate 1 23 hash and that is exactly what is printed over here now there is one more thing if I want to check the username what is the mechanism over here Well, basically it will be the same here. Instead of passing data or password, you need to replace it with data dot username. Enter. And here you can see the username is again admin which is which is exactly what we passed earlier. Now again there is something that you might have noticed is that is data dot. What exactly is data dot? For that we need to go to the output that we have generated earlier. Now whenever we are referring to data do username data dot password we are actually referring to this object data. Password meaning this specific entity that we are targeting to data dot username meaning this entity that we are referring to right so that is how Kubernetes is storing those value as an object in uh internally right now here basically we talked about how does encoding works how does we decode it let 22:32:15 us talk about uh one more important section that I was referring earlier that is nothing but the type of secret that we were working on for that let me just switch to my visual studio code and here we we are talking about secret types. So what are the different secret types that are available right now? So basically these are the common built-in uh secret types which are available and there is also one older secret type which is present that is kubernetes.io docker cfg it is used as it is used for old docker registry format right now let us understand what exactly each one of them mean. So let us talk about opaque. So what exactly is opaque opaque is general purpose secret. So basically here it is used for arbitrary application credential. So that is the reason why we are using in this lesson. So Kubernetes identifies opaque as the default type for the userdefined data. So basically here when we define the string data it will convert your values the strings into the base 64 encoding pattern. Second we have something called config JSON. So basically this is used 22:33:17 for the uh credential that needs to authenticate to the private container registry. For example, if your application image is stored in a private registry, then cublet may need the credential to pull that image. So third we have is basic. So basically this is intended for basic authorization credential. Next we have is SSH O. What exactly SSH O is? Basically it is intended for SSH authentication such as SSH private key. Next we have TLS. What exactly TLS secret over here is? So this is used for TLS client or a server data and it is typically a certificate and a private key material. Then we have something called service account token. So what exactly it is? So this is an important and historical key but you don't have to use it blindly because Kubernetes now recommends a shortlived service account tokens through the token request which can be made through the API. So instead of manually creating longlift tokens, you can make use of the token request API. Then we have 22:34:18 something called / token. This type is associated with bootstrap token data that appears during the cluster to bootstrapping. And then here we have docker cfg that we have already covered. Right? So in our case we simply made use of username and password. So that is the reason opaque was the very appropriate type for use case. Right? Now since we have talked about secret so far let us create a pod and let us see how does the pod utilizes the secret. Right? Let me just switch to my terminal. And here we would be creating a new pod over here. All right. So, let me just clear the screen. And here we go. Clearing the screen. Now, let us make a new file. So, let me just name it as secret env.l. Now, again here we are creating a part. So, API version, kind, metadata, inspect. These are the four keywords that I think you all are now aware of. You already remember now. So, now let me just type the same. So API version then we have kind then we have meta data 22:35:19 and lastly we have nothing but spec. All right what exactly we are trying to create? We are trying to create a pod. Now again what is the API version for pod? It is nothing but v1. How do we verify it? So escape colq just type cubectl api- resources and we'll do a grab on pod enter. And here you can see for pod the API version is v1. Right? Let us go back to the manifest file again. And the next thing that we want to do is we need to give the name to this uh pod. So what exactly would be the name of this pod? Name of this part would be nothing but secret env pod. That would be the name that we would be giving to this pod. Now again when you are working on a pod what exactly want to run? Basically we want to run container. So let me define the container. So container what could be the name of this container? So let me just give the container name as nothing but app. Now again which image it will be using it will be making use of busy box. Feel free to experiment over here. And then I 22:36:21 want it to run few set of commands. So that's the reason I want I am typing command over here. Now the first thing that I want over here is I want to start a shell and then I want to pass hyphen C as a flag because that is uh something that is making the further commands available as a text. So whatever I am typing as a text over here will eventually turn into a command over here. Right? So we have defined the command as slip 360 0 which actually will keep the container up and running. Now again the important section over here is we will define the environment variable. environment variable because here we are injecting the secrets as an environment variable. So for that I will type env. Now again what data will fall over here basically here we are passing two values that is database username and database password that we actually defined in the secrets. So I will give the name to this env. The first one would be db username and second thing that we would be defining is the uh password. So the 22:37:23 password would be nothing but db password. Okay. Now again uh when we say environment basically when we pass db uh username and db password basically here kubernetes will create these two as an environment variable. Now where do now basically where it will get the value from? So basically here we need to pass the references right. So here we will type value value from now from where it will get the value from we have define the secrets right and just like config map here you need to define the value such as a key reference. So secret key ref. So this actually defines that here we are talking about secrets right and then here we need to define the name of the secret that we have created. So first of all let me get the name again. So cubectl get secret and here the name of the secret is nothing but DB 22:38:23 credential. Okay, I'll go back again and I'll try to update and here I will update the name of the secret reference. And here let me just update it. So here we go. And here we have updated the secret key references. Lastly the thing that we have to pass is nothing but the key. Now inside DB credential, what key we are looking for? when I press escape colon wq let me just do a describe into the secret first cube cuttle get secret secret name is uh db credentials hyphen o yl and here you can see here this is the key that we are looking for so for this case in our case the key that we are looking over here is nothing but inside db credential I'm looking for the key that is username and that username value should be present over here and that is something this container will utilizing likewise I'll just copy this entirely because this thing will be same used by DB password the only thing that will be changing over here is nothing but the password key okay escape colon 22:39:25 wq clearing the screen first and let me list down all the file this is something that we have created now let me first apply it cube cuttle apply - f secret envl the pod is created let me do a cat on secret env report. Now let me explain you each and everything from starting right. So here API version v1 means that we are using Kubernetes score API version as v1. Then second here we are telling Kubernetes what sort of resource we want to create. We are interested in creating a pod. Then what would be the name of that pod? That is something that we defined in metadata. In metadata we have defined the name of pod. The name of pod is nothing but secret env. Then here comes the specification the settings the configuration for this pod. The first thing that we have defined is we want to create a container. So that's the reason we have defined containers. Now what would be the specification for that container? Here the name of that container would be nothing but app and which image it will be utilizing. It will be utilizing the busy box image. Then here there were few set of commands that we wanted to execute uh after the 22:40:27 container is created. And here uh sleep 360 is the command that has been executed when the container starts. This keeps our container up and running. Now here comes the important segment which I want you to put your focus on. So the first thing that we have defined over here is env. Now here env basically signifies Kubernetes that we are trying to define the environment variable. The first thing that we have defined over here is uh DB username. What exactly it means? So here we are telling Kubernetes to create a DB username as an environment variable. Now what is the meaning of value from? So value from basically signifies that read uh basically signifies to get its value from another cubernetes object. So for that we need to pass a reference. What is the reference? So earlier if you remember when we were learning config map at that time we were passing config map key reference. Here since we are dealing with secret we are passing the reference for the secret key. So that's the meaning we are making use of secret key reference. Then what is the secrets that we are talking about? We are talking about the secret by the name DB credential that we have created. And 22:41:27 again which key are we are referring to we are referring to username. So that is exactly what we are mean when we say uh uh name equals to username and kubernetes secret key reference. Same thing applies for DB password. Basically here we have defined the environment variable for DB password. Here the value is coming from a secret key reference. The name of the secret is nothing but DB credential and the key that we want the value from is nothing but password. That is exactly what we have been doing. Now let me just clear the screen and let us verify the pod. So cube cuttle get pods and here you can see secret env pod is up and running right now next thing that we need to do is now since we have defined the environment variables as a secret. Now let us try to read it because if you remember secrets are nothing but confidential information right so now let us actually see and let us verify whether these values are present or not. Right? So here basically we're trying to check whether these values are actually injected inside the container or not right. So let me just run cube cuttle exact container name the 22:42:30 pod name and inside that pod I want to print the environment variable and here I'll run grape- e and what exactly are the value that we are interested in. So we are interested in two value that is db user name and second thing is db password enter and here you can see both the values are listed in front of us. So this proves that the secret was injected into the container environment right and if you notice something print TNB actually uh shows the secret right so that's the reason whenever you are dealing with secret do not directly run commands like this casually in production environment why because this will actually print in the output into the console so avoid using uh the output in the terminal avoid using the output in uh genkins output logs right or any CI/CD CD logs because once you print the secrets then you have exposed the value right now just like config maps if you 22:43:31 remember uh here secrets are supporting env from so instead of choosing the key individually here we can pass the here we can pass the entire key as a secret right so let us create an env from pod that will help us to demonstrate if you want to pull all the keys exactly at once how it can be done right so basically if you are relating these things with config map things will be very much easier for you. Right? So now let us create another pod which will be responsible to import all the environment variables from the the secret that we have created. So let me clear the screen uh vim and here we'll create secret env from part dot yl enter. Now again API version kind metadata and spec. Now this time we'll uh we are already aware what we are creating. So API version for pod is v1 and the kind that we are defining over here is 22:44:31 nothing but pod. We are telling kubernetes that we are trying to create a pod. Then here I will write the name of the pod. So secret uh env from port. So this is the name of the pod that we have defining. And then here we'll define the uh pod configuration. So here inside that part we want to run container that container name is nothing but uh application and inside that application the image that it should use is nothing but bzbox and next is we want to run few commands which will make sure that the container is up and running. So here uh the first thing that I want to run over here is uh I will start a shell then I will pass one - c that will make sure that the thing whatever I'm typing next it will consider it as a Linux command and here comes the important section that we were actually waiting for that is nothing but env from. So now I'll define env from. Now what does envir here we it we are telling Kubernetes to 22:45:31 import all these secret key values as an environment variable but again for that also you need to pass a secret reference. secret ref. So once you part the once you pass the secret reference you need to pass the name of the secret right. So here the name of the secret is nothing but db_credential right db credentials escape colq let me verify the name as well cubectl get secret enter yeah it's db - credential and I think the same thing yes we have updated the same let me just apply the file over here so clearing the screen cubectl apply f uh secret env from podyl and here it says there is an issue pod inversion v1 cannot be handled as pod strict decoding error unknown field spec.containers containers and env from okay so I made an mistake over here let me just clear the same vim over here and here this is not in upper case again yl 22:46:32 is stick with the indentation this proves the same so it is env from escape col wq so now let me apply the file so cube ctl apply - f secret from env from podl again here it says invalid value secret env pod a lower case subdomain consist of alphabet. Okay, here I need to change the value of pod over here. Let me mark it as secret env. Let me make it as secret env. This will be the name of the port that we would be creating. Applying it again. Clearing the screen. Let's cube CDL apply f secret env. ML. Here we are getting an output. Let me just see over here what exactly it is saying. Forbidden part updates may not uh change fields other than spec.container image spec active deadline second toleration 22:47:32 only additions to existing tolerant allow it to be set one if it was previously negative. Uh let me just check the current ports. Cubectl get pods. Okay, secret env. And the new part that we are trying to create is nothing but cat on secret env from. Okay. So the pod name is actually conflicting. That's the reason we are getting that error. Let me just change the pod name over here. We already have created secret env. So this time let me name it as secret env. I'll add it in lower case. So this time it will be working fine. clearing the screen and cubectl apply -f secret env from pod.ml and this time it got created. If you remember what exactly was the issue. I was trying to recreate the pod which was already present in the default name space but with different configuration that's the reason it was throwing an error and it was asking us to validate what exactly 22:48:33 we are looking for. Right. Let me just list it once again. Cube cuttle get pods and here you can see env from pod which is the newer pod that we have created is successfully created and it's up and running. Now let us try to fetch the information from it because uh we have injected the value from the entire uh secret that we have created. So again cubectl exact in the secret env from pod and here what exactly we want to do? We want to print the environment variable. So hyphen - print env. And basically here I will be doing a grab - e on uh the first thing is db username and I'll do a pipe. Second thing we are looking for is db password enter. And here it says it's not present. Let us wait for some time so that it is able to grab all the information. Here uh I'll also pass one more thing for our uh ease that is nothing but uh username and I'll 22:49:35 do a python password so that all the values are actually being fetched over here. You cut exact secret uh and we are printing the values and here you can see the values are actually printed in front of us. So here the username is admin and the password is pass at the rate 1 2 3 that is actually what exactly we have defined earlier. So here if you notice something in the first part we explicitly said that DB username and DB password. So we controlled the names but here with env from Kubernetes uses the secret key names as the environment variable names. So that is the reason when we earlier executed db username and db password it was not aware what exactly it was. That's the reason when we do a grab on username and password this time we were able to get the value that is the basic difference that you should get it. So whenever a container is running so basically they are utilizing these two as the environment variable. When I say environment variable here in this case in or context it is nothing but secret. So that is the exact difference that I want you to keep 22:50:35 in mind. Now uh here we learned about uh injecting secrets in two way. First in as in key value pair into environment variables and second is importing. There is another third way as importing the environment variables the secret as a file. Same thing that we have done with same thing we have done with config map. Likewise similarly we can inject the secret as a file also. Here the environment variables are one way but application may expect credentials as a file sometime. So for example for your password there will be a dedicated file for your username there will be a dedicated file that you can be mounting. So Kubernetes can mount a secret as a volume. So let us create a secret volume pod that will be helping us to understand the same. So clearing the screen and here I'll do a vim on uh secret volume pod. So this is the name of the pod that we are creating. Let me just mark it as secret. Okay. Now again since we're creating a pod what I'll do escape colq. I'll just copy it from either one of the pod that we have 22:51:35 created. So cp uh let us take secret env from pod and uh we'll paste the value into secret volume pod and now I'll again go back and do a vim and here what I'll do till here things will be same from here it will be different so now what exactly here the things are the first thing that I will need to change over here is the port name so I'll delete the current context okay so here we have defined define the API version as V1. We have defined that we are trying to create a pod. In the metadata, I will now give the name of that pod. So let me name it as secret volume pod. Okay. Now here in the specification, it will contain the settings of this pod. So inside a pod we want to run container and these are the values. Basically these are the configuration through which uh the container will be running. So here the name of the uh container is nothing but application. Here I'll say application uh balls or something. So that will be a 22:52:36 differentiator. Then the image that we are utilizing is nothing but busy box. And then there are few set of commands that is helping us to keep the container alive. Right? Now here there is one thing that we want to do is we want to mount the uh secrets. Right? So how do we do that? We need to first define the volume. So I'll just define the volume. So I'll just write a volumes over here and rest ins. Uh the first thing that I will be defining is the name of the volume. Name of the volume is nothing but secret volume. So this is the name of the volume that we are actually giving over here. Now while mounting uh this volume name will be utilized over here. Now after defining the name of the volume let us uh define the secret over here. Right. So here I'll say that here we are creating the volume for secret and secret rate and the name of the secret is nothing but here I will find here I will pass the secret name. So secret name is nothing but DB - uh it was DB - credentials I guess credentials 22:53:38 let me verify the same you cut get secrets enter yeah it was DB - credentials let me go inside the file and I'll update the secret names too it is DB credentials insert mode and here is the value okay so here what we did after The container creation we have defined the volume. Name of the volume is secret volume. And here we have defined the secret name. Secret name is nothing but DB credential. So here we are telling Kubernetes to use the secret name. The DB credential which is actually created. Now since the volume is created, we need to mount it to the container. Right? So for that what I will do? I will go to here. Here I will define the volume mount. So volume mount. And here in the volume mounts I will define the name of the volume that we are referring to. So the name of the volume is nothing but secret volume. So after defining the secret volume, we will define the mount path over here. So mount 22:54:38 mount path. Now what exactly is the mount path here in this case? So basically we are going to store the value inside the container into HC and let's say the the directory that we would be using is / credential. So / etc/ credentials. Okay. So this is the mount path. And lastly here we are passing one more parameter that is nothing but read only. Read only. And this should be basically true. Escape wq clearing the screen. Let me first apply the manifest file and then I'll explain you. So let me apply the file. It is cubectl apply - f secret okay secret env from and here it says it's a b request error when creating uh env from pod.ml cannot handle as pod stick decoding error here it says unknown field as volumes okay let me 22:55:40 just go inside the file Secret env from port.l. Okay, here it says that this is an unknown field. Let me just delete the space and let me just check the indentation. So here we have defined the spec. We have the container commands everything in line. Here the volume is undefined. So here basically this will fall under containers. These all will go inside it. Okay. Escape colon wq. Let me apply the file. This time the pod is created. Clearing the screen. Now let me explain you the file get env from pod.ml. And this is the file that we have created over here. Now till here things will be very much easier for you because here we are defining the pod. Here we have defined the settings for the uh here we have defined the settings for the pod configuration that we have been looking from the starting itself. Right? So these are the default configuration that we have been defining throughout. So here the main focus that 22:56:42 we have to put on is nothing but volumes and volume out. So let us discuss volume. Here we have defined the name of volume. The name of volume is secret volume. Right. Then here you have to put in uh IO on secret and the secret name that we have passed DB hyphen credential. So here what we are actually telling it we are telling Kubernetes to use a secret as the source of this pod. Right? And that source name is nothing but DBNE credential. This means that this is the specific secret that we are referring to. Second, after the volume is created, we have mounted it and with the help of volume mounts and the name of the volume is nothing but secret volume. Make sure that this name matches with the volume that we have defined over here. Then the next thing that we have defined is nothing but mount path. So here the mount path is /t/credential. So this tells Kubernetes where the secret should appear inside the container. So our secrets basically contains two values that is username and password. So we should get two files over here. / HC/credentials as username /h/c credentials as password. So each key becomes a file. So what exactly 22:57:42 kubernetes key says in this case basically it says that the secret volume data is made available as a file based on the secret type secret keys over here. Right? So now let us verify the changes now. So clearing the screen. Cubectl get pods. Enter. This is cubectl get pods. And here we can see secret volume pod is actually created in front of us. Now next thing is let us list the directory to verify whether the two files that I was mentioning earlier is created or not. So for that cubectl exact the pod name secret volume pod and here what exactly we want to do? Basically we want to list uh all the files which are present in / the name of the uh folder that we have created it is nothing but credentials enter and here you can see there are two files which are present and as I mentioned earlier there will be two files will be created as it is expecting two keys first is the username and 22:58:43 second is the password right so here when we say uh username here it will contain the username that we have added and when I say password here it will contain the password that I was mentioning right so what I will do I will first read the username and then following we will be doing the same with the password too so for that what I will do cubectl exact and the port name u secret volume port here what exactly we need to do we need to run a cat on /c credentials and here we are interested in reading the file name username so data dot username so username let me just remove the slash Enter. Here you can see admin is printed. Now likewise what I will do? I will just print the value which is present in password. Enter. And here you can see the password value is also present over here. That is how secret uh volume mounting actually works. It is very much similar to config map. Right? Now here there is important thing that uh these secret volumes are nothing but read only. So secret volumes which are 22:59:44 mounted are read only. So our application can read the values for the username and the password. But it is not supposed to modify the secret through the mounted file system. Now there is another important uh security detail that I wanted to highlight over here that is on Linux node secrets uh secret volumes are actually mounted into the temporary file system. So that is nothing but the RAM based file system. So this means that Kubernetes doesn't write the secrets into the normal persistent storage. It will mount it into the D storage of the node into the RAM. Right? So let us verify the same. So what I will do I will clear the screen and here I will just run cubectl get ports and here what I will do cubectl exact here basically what we are trying to prove we are trying to prove that the values that has been stored is stored in the temporary file system. So here I will run df - ht and then here we want to get the type of directory credentials. Enter. Here you can see the 23:00:46 type of the file system is nothing but uh tmpfs that is temporary file system. So here we proved that it is actually using the temporary file system right and here we are checking the mounted file system. So now there is one more thing that you can make use of then let's say you have created one secret and uh there are multiple parts which want to refer it. So basically they can also make use of this secret. So basically it will be one secret which has been referred by multiple parts. Right? That is also one segment that I wanted to mention over here. Right now since we are talking about secret just like configuration if we are rolling out with a new password due to a password change policy is that even possible. So basically let us test that uh uh so let us test that scenario too here what exactly we'll do let's say that after 60 days our rotation policy has changed and we need to uh change the password how we will do that so here what I will do instead of us making use of the password as password at 1 2 3 let us make it as password as 4 5 6 or 7 8 9 right and then we are going to observe what happens to the environment variables and 23:01:47 what happens with the mountain files that we have created just like we did the same with the config map right so here what I I will open the dbsecs.ml dben secret.ml here uh as per our need I will just change the password from 1 2 3 to 4 5 6 and I will remove this hash escape col wq remember what exactly we changed here we changed the password here we are considering that we want to adhere the policy and we are actually rolling out a new password for it right so now let me just save the file and after saving the file let me just apply it so here I will type qct DTL apply - f db - secret.ml. Okay, here what it says db credentials is actually configured meaning the secret itself is now updated. Now let us check what exactly happens to the volume port. So here let me first list the port. So here we have the volume pod. So let us verify what exactly is the value that has been printed over here. So cube ctl exact the pod is secret volume pod 23:02:47 and here what I want to do is I want to do a cat on / c /c credentials and here we have password pass what enter here you can see the new updated password is reflected in front of us right so here basically if you notice we didn't recreated the part the normal secret volume was actually mounted to it and due to that reason it was actually updating the value right so let's check the same thing with the environment variable part right so now I will rerun the same command but here it will be with the environment variable pod so cubectl exact in the environment variable pod and that is being but secret env what I will do I will do a print env on the environment variable that we have created So grab hyphen e on 23:03:48 db password enter. Here you can see it is still using the older password. The older password was nothing but password pass at the rate 1 2 3. Here the thing is we can still see that it is utilizing the older password but we have already changed the secret. What exactly is happening over here and those changes are reflected into the mounted file pod also. Right? So why didn't the environment variable change? So basically here the fun is simple as we have followed in configuration map also because the environment variables was created after the container process was started. So here secret was uh injected after the uh so basically what usually happens over here is the secret was injected during the container creation and they are using that password right now after the secret got changed basically the new password is not reflecting but it will be able to consume it after a new port is created that's why the ports need to be recreated in such a case. so that they can they will be able to utilize the new environment variable and the new secrets. But for this case the values that are available are from the older 23:04:49 configuration that we have injected. So here what exactly Kubernetes is trying to say? Kubernetes here is trying to say that the secret value is consumed over here is nothing but the outdated value that we have injected earlier while creating the pod in order to make it consume. So basically what we will do we will delete this current pod and we'll try to create it so that uh the next time when we are going to print it we are going to get the updated value. Let us verify the same. So cubectl delete pod followed by the pod name and the pod name is nothing but env from pod secret env. The pod is deleted. Let us create the pod once again. cube cuttle apply f. Let me just write the name of the port and the port name uh and the file name that we have created is nothing but secret envl. Let us wait after the deletion. It will try to create a new port for us. 23:05:56 Now here you can see the pod is created. Now let us verify the new values from here. Right? So what I will do I will again rerun the same command. So cube cut exact env. We are going to print the environment variable value which we have stored as a secret. And the key that we are using is nothing but db password. When I press enter this time you can see the password is updated. And this actually proves that whenever a container is created it consumes the new fresh value that has been present. Okay. Now further if I change that password from 4 5 6 to 7 8 9 again we will have to delete this part we will have to create it create a new part here basically the values has been consumed from an environment variable right here the values are been consumed as a key value pair that's the reason we have to restart it again so that it will be reflected in the container here there are some basic rules that applies to environ if a secret is consumed through a environment variable like this uh changing the secret doesn't automatically mean that environment variable is updated into the existing pod A new pod will have to be created in 23:06:57 order to receive this value. Right? So now what would be the difference in the behavior uh on the pods when we are injecting the secrets with secret file and when we are injecting the values with secret enviable. So let's see the behavior side by side. Now let us discuss what will happen when we inject with the environment variable. So when we inject it with environment variable at that time the secrets are injected during the container creation project and the pro pod will start and it will use the existing value. Now later when you change that value the pod will still use the old value right then in order to make sure that the pods are using the new value you will have to create a new pod and then it will be utilizing it. Now what happen when we are making use of a secret volume here the secrets are mounted through a file and that mounted file get eventually updated so that whenever the pod is running it is reflecting the newest latest value. That's the reason uh if someone ask you what is the difference between environment variable and mounted file you can see the when we are making use of environment variable we have to create a new port so that the values 23:07:56 that are updated it will be reflected immediately. So if someone ask you what is the difference between uh using secrets with environment variable and a mounted file. You can see when we are using environment variables the pod will utilize the current environment variable values. after when you update it, it will for that it won't be consuming the latest value. It will be still using the older environment variable values. For that in order to consume the newer one, you will have to create a new pod. Now, when it comes to mounted file, basically when you update the file itself, the changes will be reflected directly into the pod. Here you don't have to restart the pod. The values will be uh restarted. That is exactly what we saw over here. So, when we are using the mounted file, the values can be updated while the pod is running. Right now since here we are talking about secret let's talk about security too. Right? Because here uh secret is the sensitive data and u you should not think at that when we are using kubernetes secret that things are automatically secure. Now in order to make your secrets more secure you can make use of kubernetes secrets 23:08:58 on top of it. We can apply rulebased access control. So only the people who should have the access will get the access. And thirdly, you should apply least privilege principle. So when you combine all these three principle, basically your secrets will become more secure. Right? Now when it comes to uh when I so basically I mentioned about lease privilege. So let us talk about arbback. Arbback is nothing but rolebased access control. Now suppose uh let's take an example of this example itself where we are dealing with username and password. So let's say uh that there is a user who want to read the secret for uh that need a permission to read the username and password. So how will you give that? Basically you will give to that specific person right because uh you won't give every user to list the secrets to watch the secret to get the secret right basically uh these permissions are something that we need to manage it that we need to manage and that is something that is managed by the rolebased access control mechanism right so secret access should follow least privilege principle and that is being 23:09:58 controlled by rolebased access control so now by default the secrets are stored unencrypted in atcd for a production cluster administrator should enable encryption at last for security data. Uh let me switch to Visual Studio Code so that you can get better clarity on what we are referring to. Let me just go over here and yes here we are talking about after this we will go to secret security. So what exactly uh do we mean when we talk about secret security? Because here we are not considering that when we are using secret we are already secure. No when you want to make secret uh with greater security you need to provide few more additional information over there few more additional things that you need to do. First of all uh if you think that secret will automatically secure application. So basically that thinking is wrong. Basically instead you what exactly you need to do you need to prepare you need to prepare a mechanism 23:10:58 where your secret uh will be having rulebased access control and you are only providing lease privilege uh access to the people who only require that access by doing so by putting all these three and four action you will be able to secure your secrets now let's talk about arbback what exactly is arbback arbback is nothing but rolebased access control now let's say I create a secret name let's say db credential so If a user has the permission to read the secrets in that name space, they may be able to retrive the secret. But uh we usually don't give u access to all the users so that they will be able to uh get the secret. They will be able to list the secret or was the secret. Basically we will provide that uh permission on need basis on use basis. That's the meaning of uh rulebas control and that's the meaning of least privilege. Right now let's talk about encryption at rest. What exactly is it mean? By default secret objects are stored encrypted incd. But for production cluster the administrator 23:12:00 should enable encryption at rest for the secret data. So this what exactly it will do. It will protect the secret if someone gains access from the cityd storage. Now there is one more thing that we need to keep in mind that when we are working with Kubernetes with secrets you don't have to commit the real secrets to git and basically uh this is the string data that you can see basically if you type that password then it will be like sharing your password publicly. So basically this is something that you should avoid. Even though the string data is easier to read, it still contains real credential, right? And if someone converts that B64 encoded data, then basically your password is exposed. So that is something that you have to keep in mind when you're working with Git also, right? Now again there is one more thing. Now just like config map there are some size limit with secrets too. So basically the size limit in secret is nothing but 1 MB byte. So here the secrets are not designed to hold a huge amount of data. 23:13:02 They just like config map uh here just like config map they don't usually use a general purpose file storage system. That is the reason there is a size limit of 1 bp bytes. Right now let's talk about immutable secret. If you remember we talked about immutable uh config map. Likewise we have immutable secret. So what exactly here the thing is basically again when you are creating a secret at a time if you define the immutable as true basically no one can change its data. Let us see things in action. What I will do I'll again copy this entire manifest file. Again this is uh something that you have already done. So it is already aware uh you are already aware of it. What exactly here we are doing? Basically here we are defining the API version. We are defining the secret that we are telling Kubernetes we are trying to create a secret. Name of the secret is immutable secret. The type is opaque. We are already aware that opaque is a type Kubernetes secret type that helps us to store the secrets in uh basically a key value pair and in string manner. Here we 23:14:03 are passing an API token and here we are marking immutable as true. Let us create an immutable uh secret over here. Let me clear the screen. uh vim immutable hyphen uh uh secret doty yl enter and I'll paste the value escape wq let me apply the file cube cuttle apply - f immutable secret and here uh okay it is cubectl apply - f and here it says there is an issue let me just check uh it says error parsing immutable secret converting from yam normal to JSON line four pound found character and that cannot start with any token okay vim here it says metadata and then we have defined the type okay there is a spacing issue so let me correct the same here inside metadata we have defined the type and then uh after metadata we have 23:15:05 defined the type as opting in the string we have defined the string data that is nothing but API token and then we have defined the immutable as true let me apply it and this time the secret is created. Let me clear the screen and cubectl get secrets. Here you can see immutable secret of type opaque is created in front of us. So here basically the thing is when we are marking immutable as true we should not be able to edit the value right. So let us verify the same. So uh let me do cubectl edit secret immutable secret enter and here what I will do here I'll just try to change any value insert mode I'll just write ccc escape wq now since it was marked as immutable s2 you can see there is a forbidden error that it says immutable it is immutable and here we have set immutable s2 that's the reason we are not able to save it escape colon Q not here I'm marking Q not because I am not 23:16:07 trying to save it over here right because earlier when we tried to save it we got an error why because we were making use of immutable over here that is something that we have seen over here now let us go back and yeah so now there is one more thing that we need to see is earlier we have seen uh to create a generic config map is there any command line through which we can create secret through command line yeah basically we have a command pin Kubernetes to clearing the Now let's say if you want to create a generic secret, how do you create it? So basically you can just write cubectl create secret and then after that you need to pass the name of the secret. So secret name is let's say generic uh data and then here you need to pass two flags that is hyphen from - lit and then you need to pass the uh value that you're looking for. So here I will type username as shukam and that is exactly what we are trying to store over here. Enter. And here it says from literal is 23:17:09 wrong. So let me just check this from L I T E R A L. 23:17:28 Okay, got it. So basically what you have to do is you need to just type generic over here because we are trying to create a generic uh secret over here. to generic then I will say sh generic data and here the sh generic data is created. Let us verify the same cube cut secret enter and here ss generic data is present in front of us that is of type opaque and it contains one data that is nothing but the username that we have created. Now let us try to verify cube cuttle describe secret s generic data and this is the exact value that we are actually looking for. So yes that was all in this video where we learned about secrets and if you are coming from config map things will be very much similar for you because here basically we learned each and every concept that you require to get started with secret right so if you have any doubt feel free to reach out. So yes that was all in this video and I will see you in the next one. Until the next time keep learning and thank you very much. 23:18:30 Hey everyone. So in this video we are going to understand three most important concept in Kubernetes that is livveness probe, readiness probe and startup probe. Now if I put this into simpler term, it is nothing but performing a health check on your pods. Now let's imagine when you run cube cuttle get pods you see that your pod is actually running. But what does it denotes? Does it means that your application is actually running? Not necessarily because there can be multiple situations. Now situations like when you see the application your pod is actually running your application might be in starting phase right when you see the pod is actually running it means that your pod is not ready to receive the traffic. That can also be one of the thing. Now when you see that your pod is running there can be internal thing that might be happening. It might be stuck with some internal activities. Now how does Kubernetes know that these things are happening right? This is where probing comes into the picture. Now if I put probing into simpler terms, probing is nothing but performing a health check. Now here Cublet performs a periodic diagnostic on your container. 23:19:31 That diagnostic report is being shared to Kubernetes and based on that Kubernetes makes a decision to restart your container or to stop sending the traffic to the ports which is not ready. Now let us cover probing in detail in this video itself. So let's get started. Okay. Now that we are aware about the probing option, let us discuss them in detail. Right. We already have seen the problem statement. Now let us discuss about the three probing option that we discussed initially that is startup probe, readiness probe and livveness probe. Let us discuss about startup probe. If I want to understand startup probe, it is nothing but basically here we are asking Kubernetes whether your application is actually ready to serve or not. That is something that has been uh provided by start probe. So basically here there will be a health check that will be performed against your pod where we will check whether your application actually started or not. If you want to understand start pro let us take an example. So imagine that you have an application and that application requires 30 seconds to start. Right? Now here the thing is uh during that initial 30 seconds we don't want kubernetes to 23:20:33 think of it like the application is broken. Right? We simply want to give it some time to let it get started. Right? So here we define startup role. So what it does here kubernetes will keep checking the startup condition. Once that condition is met basically startup probe will success and here kubernetes will then allow it to perform the livveness and readiness probe only after this startup probe is done. Here the main condition is if you have configured startup probe. So here cubernetes will not run livveness and readiness probe until the startup is succeed. Right here a failed startup probe will cause cublet to kill the container according to the pods restart policies. Right now let us discuss about readiness probe. So what exactly readiness probe does here? It will actually tell you that your application is actually ready to receive the traffic. If you want to understand readiness probe, let us take an example. So here let us imagine that your application actually started your startup probe got success. Now here comes the next level. Here the thing is 23:21:33 uh after the start is completed it need to load few data for the application to run. It can be data it can be cached. Now it depends upon the application. So here the application is alive but it is not ready to handle the users. Right? So we don't want the uh Kubernetes to restart that application. We simply don't want to send the traffic to it. Right? That is exactly readiness tells to Kubernetes that I am running but I'm not ready to serve the traffic. Right? If a readiness probe is filled, the pod is not ready because the matching service will stop treating that pod as a ready endpoint. That is exactly what has been done in readiness probe. Now let us discuss about livveness probe. Now here basically if I put it into simpler one, it will just tell whether your application is functioning fine or not. That is something that has been told by livveness probe. Let us discuss it in detail too. So here uh it is another different situation where the application already started. It says that I am running but there is uh but internally something gone wrong right it 23:22:33 can be anything. Yeah your application might get stuck or it may be fall into a condition where dialogue might have occurred. So in this case we want kubernetes to restart the container. This is where livveness is actually present here for. So what exactly liveness probe will do in this case? Basically it will it is actually used to determine the container that should be restarted in the situation where deadlock arises right. So when the application is running but they are not able to make any progress at that time these probes comes into the picture right now we know about each probe liveness probe start probe and readiness probe. Let us create one in detail. So here what we are going to do is here we are going to create simple ports with three probes and basically I will be using busy box image for this because it will give you the understanding how does this probe mechanism works right. So here we are going to create three HTTP endpoints uh that is first is startup second is ready and third is healthy. So startup will tell the cubernetes that the application actually started uh the ready will tell the cubernetes that the application is actually ready to receive 23:23:34 the traffic and third is healthy. It will tell kubernetes that the application is healthy. Now here since we are talking about uh endpoints here is where services will also come into the picture. So in this video basically we are going to do one more experiment. Basically there will be only one manifest file that will do all the job. It will do the job for startup liveness and readiness and also here we are going to create a service and basically all thing will be integrated into one single file. Now how that can be done basically that is something we are going to see. So for that let me switch to my item. So now here I'll go to my I terminal and I hope the screen is visible to you. Now the first thing that we want to do is we want to create one pot. So how do we do it? So basically we are going to create one pod. So I'll just type vim probes doyl. I'll just mark it as probe demo. This would be the name of our pod. Enter. Now here what exactly we are trying to create? We are trying to create a pod, right? What are the four keywords that we need to remember whenever we are dealing with any sort of manifest file 23:24:35 in Kubernetes? API version, kind, metadata and spec. Let us write the same. So, insert mode, API version, then we have client, then we have meta data and lastly we have spec. Spec is nothing but configuration the setting for that pod. Now, what exactly we are trying to create that we define in the pod uh that we define into the guide. Right? Now, here what is the API version for pod? SK WQ. Now let me run the command cube cuttle API resources API resources resources and we need to do a grab on pod enter and here you can see the API version for pod is nothing but v1 let me just edit my file once again and here inside the API version I'll define the pod as v1 now here in the metadata here we'll define the name of our pod now what exactly is the name of pod here I will define probes demo Now here the next thing is since we are creating a part what exactly we are dealing with? We are dealing with 23:25:36 container. So here we'll define the settings the configuration for the container. So here I'll write containers. Now here inside this container the very first thing that we would be defining is nothing but the name of the container. So here the name of container is nothing but app. Next thing that we need to do is we need to define the image name. So here I will be making use of busy box. Lastly I will need to run few set of commands. So here for that I'll write command and here the initial thing that I will need to do is I will need to start one cell for that I will write sh and then I want to pass few text as a command line that's why we are marking as hyphen c and now this is the place where we will actually pass the command. Now since I want to run a multi-line command I will pass on pipe and now whatever I will write inside it will act as a command. First thing that I will do is I will just create one directory for a web files. So mkdir - p to mark it as a parent directory and here I will mark it as/ www. Next 23:26:37 command that I want to do is I will create I will actually remove the existing uh startup file and the readiness file. Now what exactly that means? Uh let me just tell you after the manifest file is created right so here rm - f and here what I will do I will delete two files that is /www/startup right now it is not existing here we are considering that it might get created when the application is running second thing that I want to run is rm -f and I want to delete one more file that is nothing but for readiness check so/www/ ready. Now the next thing that we want to do is we want to create a healthy file. Uh we want to create a health check over here that will actually tell that your application is up and running. So here what I will do I will create one echo and here in the echo we'll just say okay and this file will get stored in /www/ health z. Let us name it as health z. You can rename it anything as as you can rename it anything uh whatever you want. 23:27:38 Right now here we want to start the HTTPD server. Right. So here what I will do I will just write PB box PC box httpd f - f and now we need to define the port port number at80. And we want to host it into /www and we want to run it into the background. Next it next thing that we want to do is we want to take a break of 10 seconds. Now what this 10 second does basically it will simulate the 10 seconds uh of the application where we are telling that you have to wait for 10 second for the application to start. Right? Here we have defined the startup condition. Now since we have defined the startup condition now here what we will do we will just print echo startup and here this file should get stored into the startup directory that we created. So, www/ startup 23:28:39 startup. Okay. Next thing that we want to do is once it is it has waited for uh 10 seconds uh for the application startup. The next thing that it should do is it should uh again provide one more simulation for 10 second where it is marking the application as ready. So let us do the same. So here we'll wait for again 10 second and here I'll create another file echo. And here we will mark it as ready. And now here I'll store this file inside /www/ ready. Now again after this is also done then we we want now here we want to keep the application healthy for 30 seconds. So for that we'll type sleep 30 and next thing that we would be defining over here is here what we will do after 30 seconds it will be healthy for 30 secondond. Then here we are purposefully deleting the healthy healthy z file which we created initially. Right here, let me just copy the same. And here we have we are actually deleting it. Now then we want the container process to keep on running. That's the reason we 23:29:39 will type wait over here. Next we want to execute is we will actually uh define the port uh and next what we will do we will define the ports and the container port. So here here it goes the port. So here I think here just below the container it will call the ports and inside the port I'll define the container port. So port this runs on container port and the container port number is nothing but port number 80. So here port number is 8080. Now here comes the main segment where we will be defining the settings for the startup probe, readiness probe and livveness probe. Please focus over here. Right. So here the first thing that I will be doing is I will be defining the startup probe over here. I will take one space over here and it will fall inside the container. So make sure this follows the proper indentation. Right? Let us start with startup probe. So I'll just put it inside the name section either the container. Yep, I think it's in the same indentation. You can also make use of 23:30:40 visual studio code for this specific demonstration as well. Right. So now let us first uh create the startup probe here. So I'll just write start up probe. Startup startup probe and here in startup probe basically here we need to define http get and here we need to define the path for it. So path is / startup in this case this would be the endpoint that we would be referring that we are actually interested in. Then here we need to define the port number that the startup probe will be dealing with and the startup probe will is actually dealing with port number. This is the same port that we would be utilizing for all of them. Now the next thing that we would be defining is nothing but the failure threshold. So here we want it to allow 15 consecutive failures. Right? So here I will type failure threshold h fail thresholds and here in the failure threshold we are defining the value as 23:31:41 15. Now our startup probe is ready. Now what I will do I'll just copy these entire values because this is something that we would be utilizing in readiness and livveness probe right I'll just take one more space this is for livveness and this goes for readiness so here let me just configure the remaining values so and this time we are doing it for readiness probe readiness oh okay now here the path the http path is nothing but instead of slash startup it will be slash ready. Now the next thing is here the failure threshold. So basically here we want uh the pod not to be ready after one failure. Here the failure threshold I'll mark it as one. And here lastly we are defining the livveness probe. So livveness probe. Okay. Now here uh the path that we will be using is nothing but health z. Same thing that we defined earlier. So h e a l t h health z. So where I'm 23:32:41 getting this path from? So basically if you remember these are the path that I am referring to / startup/ ready and / healthy that is the same thing that I'm defining over here. Now what would be the failure threshold for this? So here we want to mark it as three. Okay that is again done. Now here the initial thing is done for us and that is how we are ending it. Now let me just correct the indentations just give just give me a moment. And now there is one more thing. Now as I mentioned in this specific manifest we won't be just creating pod we will be creating the services too. Now in order to target this pod we need something right and that is nothing but the metadata and inside that metadata we need to define the labels. Now here we will define the labels so that service will be able to select the spots based on those level right. So inside the metadata I will define the labels for the same. So here I'll write labels labels and what is the uh basic what label we can give over here is nothing but I'll mark app as 23:33:41 probes demo same thing that we have used as the pod name. Now here I'll go at the bottom make sure you are using that three hyphens so that it will give clarity that the pod manifest is finished and now we are starting with the another manifest. So here again what are the four keywords when you are dealing with any sort of manifest in Kubernetes API version kind metadata and lastly is nothing but spec. Now here inside API version now we are already aware that the API version for uh service is nothing but V1. Again if you want to correct it skw WPU just write cubectl API resources and then do a grap on service enter and here you can see the service API version is nothing but v1 right let me go back again and here we were actually editing the file for services here let me define the service the kind is nothing but service over here now let us define the metadata over here so the metadata would be nothing 23:34:43 but the name of the service so probes - service this will be the name of the service that we are giving to it and then in the specification here we will define the actual configuration for your service right so here the first thing that you need to do is you need to provide the selector because on that basis only it will select those pod which are actually creating so here I will write selector selector and inside the selector basically here we will define the labels like here selection will be done based on the labels that we have defined where do we find the label basically we have defined the label labels inside the label section inside the pod when I go over here inside the selector I have defined the labels that we are actually looking into now the last thing that we want to do is now since we are dealing with service we have to define the ports also so here I'm defining the port and here inside the port we have to define two sort of port first is the service port so it will run on port number 8080 and then we need to define the container port so target port target port it runs again on port number 880 I hope that uh 23:35:45 understandable by you because here we are telling Kubernetes that this is the service port which runs on port number 880 and then here we are telling that this is the target port where the application is running on port number ATT escape colon wq let me clear the screen and let me do a cat on probes demo this is a long file that you have seen so let me just tell you everything from scratch right again so here basically we have the API version where we are telling the cure Kubernetes API here we telling Kubernetes that we are trying to create one pod. Here in the metadata we had defined the name of this pod. The name of this pod is probe demo. And then here we have defined the label of that pod that is probe demo. Now here basically this label is why it is important because we are making use of services. And in order to target that pod we we need a tag right and that tag has been provided with this label. Now here comes the specification that settings for this specific pod that we are creating that is nothing but prompen demo. So now when you are running a pod inside a pod what exactly you run you 23:36:45 run a container right so here you have a container inside that container there the name of the container is app the image that you're using is busy box now here these are the set of commands that you are ex actually exe executing now what exactly it is doing let me explain you each and everything first thing we are starting a shell we are marking hyphen C so that whatever falls after that that text act as a Linux command here what exactly we are doing over here so basically here the first thing that we have defining is nothing but we are running rm -f/www/ startup what exactly it means basically here initially the endpoint does not exist that's what we are trying to say and then here we are deleting /ww/ ready here we are telling initially the application is not even ready right the initial thing that should happen is the application should be healthy that it's something that we are doing purposefully so here our application is initially healthy so we create that healthy endpoint now then we are creating one htt HTTP server. So here you can see busy box httpd f - port in port number 23:37:46 880 we are actually working. So here this will start a tiny http server on port number 880 and it will serve the file which is stored in /w www and then since it is we have mentioned the port number 880 it will actually run on port number 880. So if we call /www/halthz if it exist basically kubernetes can call healthy to get a successful http response. Next we have to wait for 10 seconds. Now why exactly this has been happening? Let me explain you all of these at once so that it will actually eventually make sense for you. So what exactly is happening over here is uh here we have started a tiny http server on port number 880. It will give a call to /w/halthg and then uh here we are waiting for 10 second to simulate the slow startup and then after 10 second we create/ startup endpoint and then that means that your application is now telling kubernetes that I am finished starting then we are running again another sleep command that exactly is telling that uh to wait 23:38:48 another 10 second for the application to receive the traffic then we are running sleep 30 and after that we are removing removing the LG file. So here after 30 second we are removing that endpoint that is /hell. Why? Because here we are intentionally baking the application health check. This will allow us to demonstrate all the livveness probe. Right? That is exactly what we are doing. Then after that we have defined the port. Now here you can see ports as container port port number. So this tells Kubernetes that the container application is listening on port number 880 and our HTTP servers is running on this port and our ports will actually use it. Right now let us go to the main part that is startup probe, readiness probe and livveness probe. Let me explain you the startup profile. What exactly is happening over here? So this is the most important part of the CML. So please put your focus over here. So this is nothing but your startup probe. Here we are making an HTTP request on / startup on port number 880. And if that endpoint responds successfully, Kubernetes knows that application has 23:39:49 started. Right? And there is one more thing that you have observed over here is I have defined the failure threshold as 15. So here failure threshold tells Kubernetes how many failures it should tolerate before considering that the probe actually failed overall. So here we have defined the failure threshold as 15 for that specific reason. Why? Because here we are checking every 2 seconds we are giving our application enough time to start. Now let us discuss about readiness probe. Right? So here you can see there is a change in the endpoint. Earlier we were using / startup. This time we are using / 80 rest everything remains the same. Here we are configuring the readiness probe. Here uh you can notice the change in endpoint and here we are checking that the application is ready or not ready to receive the traffic or not. Right? Then here it is pointing to / ready. So initially the endpoint does not exist. So the readiness fails but the container is not restarted because the pod is simply not considered as ready. Then after 20 second the application creates the / ready endpoint and the readiness probe succeeds. So now Kubernetes notes 23:40:51 that the pod is actually ready to receive the traffic. Now let us discuss about the last one that is nothing but liveness probe. So what exactly is happening over here? Here comes the last point because here we are dealing with the last checkpoint of the probe that is /gzy. If you remember earlier we created the LG at the beginning at that time uh initially it got success. Why? because uh like at that was the very first time where we wanted to print the impression that the application is running right but later we deliberately removed healthy because the livveness probe should get failed. So after three consecutive failure the cubernetes should do the restart of the pod that is exactly what we want to do. If you want to see here you can see we have created the healthy as okay right here it fails after three times then our container will actually restart. That's the actual thing that is happening over here. Right now comes the important part that is this three dash. This is something that in that is something new that you are seeing right now. So uh this actually separates one YL with the another. So 23:41:53 here we are defining two Kubernetes resource in one single file. So first is the part which we just saw and second is now a service. Right now again here we have the core Kubernetes API version. Here we are defining the service. We are telling Kubernetes that we are trying to create a service. Then here in the metadata we are defining the name of the service and in this spec we are defining the service configuration and here in the service configuration we are telling that select all the pod which has the labels as app colon probes demo that is exactly what we defined into the uh pods and then if you scroll down here we have defined the port so here uh this port defines the port of service and the target port basically it's the application port right I think that is enough for you And I we have literally covered the entire manifest and now it will give you the complete clarity. Now let us apply the manifest file. So we will apply it by running cube cuttle. Apply -f post demo.l enter. And here you can see error parsing probes. ML error 23:42:53 converting yl to JSON. There is an issue with line number 16. Here it say did not find expected hyphen indicator. Okay. Let us edit the file. Okay. escape colon set neu enter. Let's go directly to line number 26. Okay, I got it. Basically, what we didn't do, we need to pass one hyphen over here. So, here inside container port, we just pass one hyphen escape colon wq. Now, I think we should be good. When I apply this time, it says again in line number 26, it says hyphen indicator is expected. Fine. expected hyphen indicator did not find it. Okay, let me just go back again. Let me check the indentation for that. Look here we have defined it inside container. I think there is an issue with the indentation. I believe that's that's for sure. 23:43:54 This should fall inside your container and that is exactly what's been happening. Let's do one thing. Let us go to Visual Studio Code. that will actually give us good clarity. So now let me just switch to Visual Studio Code now. Okay. And here I will open the manifest file that we have created. This will actually help us in troubleshooting because it's a big YAML file. So we also don't know. Now see here you can see uh the emit here you can see the mapping issues there. So this we can fix over here. Right? This exactly this sort of issues can be fixed with the help of Visual Studio Code ID. Right now here you can see there is again some spacing issues that we can actually fix over here. 23:44:54 Now let me just fix the spaces for readiness. Fixing the space for liveless. Okay. Now let me switch back to my terminal. And here I'll switch back and let me just apply the manifest. And let us see what happens this time. Cube cut apply f. And here it says uh service unchange uh error while creating probes demo pod in version v1 cannot be handled as pod stick decoding error unknown field livveness probe unknown field ports unknown field readiness probe. Okay and unknown field startup probe. Okay, it is not able to identify these probes. Okay, let us check what exactly is the issue over here. 23:45:47 Okay. So the issue was nothing. It was the issue with the indentation. So here mostly our port was falling inside the spec section. That's the first thing that I fixed. Secondly I second thing I corrected the spacing with the startup probe readiness probe and livveness probe. It should fall under it should fall under the same lane as sports. That's something that is that is something that we have fixed now. Okay. Now let us move to the terminal and now let us try and apply the manifest file that we have created. So now here we go clearing the screen and then cubectl apply -f probes demo. ML and here you can see probe pod and probe service is created. So cubectl get pods and cubectl get svc enter. But here you can see it says ready 0x1 which means starting probe is in progress. For that let us keep an eye on that. I'll just add one more terminal over here. We'll keep it 23:46:49 parallelly over here and we'll just observe the behavior of it. Okay. So now let me just do it a little bit of zoom cube ctl get ports and we want to watch. So now you can see it says running 1 / one meaning everything is fine right now let us wait and understand what exactly is happening over here. Let us wait and watch what exactly is happening over here. Right? Because this will give us the clarity about the probes. Here we have defined that the initial when the application startup doesn't exist. We want it to give 10 second of time so that the startup probe will actually work and we will be able to see the actual result over in front of us. Right? So let us wait and observe the screen because this will give us the complete clarity. Now here you can see there are multiple things happening. Earlier startup pro came into the picture. Now here it is saying that 0/1 startup pro failed. Then it again starts over here right again it is trying to restart the container. Here you can see the uh live container worked. Now it 23:47:51 will again give 30 seconds of buffer then again it will start the container. So here basically what exactly is happening the application starts it will check the / startup if it doesn't exit the startup will fail and it will keep checking. Then at this point the application what exactly it is trying to say? It is saying that the application is still running but the startup hasn't occurred. Right now once the startup got successful then the next thing what exactly is happening is it will check the readiness state. Here it will check the readiness and at that time initially since we have defined the configuration the readiness will fail for sure. Here the pod will remain running but it is it won't be ready for receiving the traffic. Then it will give another 10 second for it to wait. Right now once the readiness state is also done here it will say that the pod is ready to receive the traffic. Now the third thing that here we are doing is we are removing removing the /halthd. If you remember the earlier we have mentioned that we are explicitly telling that health check is running fine. Then in 23:48:52 the last state what exactly has happened? We are explicitly deleting. We are explicitly telling that the application is not fine. So here the liveless fail and then the container gets restarted. So here the application has intentionally became unhealthy. Here live if it fails three times Kubernetes will restart the container. That is what exactly is happening over here. Here you can see initially it gets started. Here if it gets fail it is getting failed three time then it is restarting the container and again the startup script again get executed. This is the key difference between readiness and livveness. Okay. Now let us verify the restart count over here. So in the left hand side I'll type cubectl get pods. And here if I just do a little bit of zoom out here you can see the restart count is two. Let us wait and let us see one more thing over here. Right. Let us wait for more time. There is one more place where you can actually see the actual events of this and that is nothing but describe. Right? So here instead of checking restart again and again you can clear the screen 23:49:54 and you can write cubectl describe pod and this is nothing but props demo enter. If I do a little bit of zoom out this is the exact place where you can find what exactly is happening with your container here. What exactly it is saying? It pulled the image the readiness proof field initially that is something that we designed. Then here it again it pulls the busybox image again the startup pro field the readiness prof field the livveness prof field then the container got created and then here again it is performing the same action again and again and here also there is one place where you can find the restart count. Right now it says the restart count as two. Okay on the right hand side you can actually see it is still regrading the container. When I run this describe once again, this time the restart count got changed to three. And here you can see the change in log also present. Right? This is how you learn about probes. So remember what exactly probes start? It helps us in solving these problem. 23:50:54 Basically it is a health check. The first health check that we do is basically on startup. In startup probe basically here we are answering that have you finished starting. Second in readiness probe we are telling can you receive the traffic? And third is basically liveness. Basically we are telling are you still functioning fine or not. These are the thing three these are the three health checks three probes that is been defined by Kubernetes that helps us in understanding whether your application is working fine or not. So startup protects the application while it is starting. Readiness controls whether it should receive the traffic and livveness actually helps Kubernetes to recover a container that is become unhealthy. So yes that was all in this video where we wanted to learn about probe. What exactly is probe? probe is nothing but a health check mechanism which we perform on top of the boards so that our application runs healthy and this is a way where we can actually see how the application has been performing right so yes that was all in this video and I will see you in the next one thank you very much let's talk about storage now okay now 23:51:55 let's say when you run a pod how does kubernetes know how much resources should it occupy right so when I talk about resources I am referring to CPU and memory Right? Because whenever you run a pod, it will occupy some memory, right? And it will consume your CPU storage too. How does Kubernetes decide uh how much CPU and how much memory that part should utilize, right? This is where request and limits come into the picture. Right? Now, if you want to understand request and limits, now just imagine that you are driving a car, your pool got empty. Where you go? You'll go to the petrol pump. Right? Now basically based on the tank now let's say your tank can have maximum of 25 L of petrol right this is where you can request the petrol pump guy to fill in the petrol into your car right now let's say if it is 25 liter of tank basically you can ask him you can request him to fill it till 10 liter right that is your request but how much maximum you can fill the petrol inside that tank now since the capacity is of 25 L the maximum petrol that you can fill inside that petrol 23:52:57 pump tank inside that tank is just 25 L, right? It cannot be 26 L. It cannot be 25.5, right? It should be just 25 L. That's it. This is what exactly is request and limits does in Kubernetes. If you want to understand request and limits, let us talk in terms of software. Now, now let's say you are running a Java application. Now that Java application will require one core of CPU maximum to function fine and it requires 512 MB of storage. Now uh during peak season let's say it is consuming lot more of storage right and like we have no control on it. How does Kubernetes know the threshold the boundary right? This is where we will be defining that this application should only use one core of CPU and 512 MB of storage. That is the thing that we define in request and limits. Right? So now enough theory let us understand things in detail and also don't forget to check out the readme.md file because 23:53:59 that will definitely help you out in revising the concept easily. That will definitely help you out in understanding request and limits. So on that note let's get started. Okay. So now we understand about the requirement. We know why exactly it is needed. So let us directly jump into the practical. But again again wait before even we move forward with the practical there are two things that you have to clear right you have to clear the two terminologies CPU quantities and memory quantities now when I am talking about when I am referring to quantities I'm talking about the units right now here let's first cover CPU quantities then we'll move forward with memory quantities now again CPU quantities basically here we are talking about CPUs cores you might have heard one core of CPU two cores of CPU three cores of CPU octa cores of CPU right so basically These are the cores we are referring over here. So CPU whenever we are dealing with the units of CPU basically we are talking about core. When someone says I want one core of CPU you will just define one and it will just say that I require one core of CPU or the virtual CPU. Now here if you 23:55:01 want to give it a representation a unit here you can make use of M. Now here this suffix M is nothing but mill CPU right? So here basically 1,000 mill CPU is equals to one core of CPU. Right? So now you just have to remember this. Now when I say 500 m, 500 m here stands for 500 mill CPU right that is half of one core of CPU right and third unit is 250 that is quarter of 1 CPU. So that is the basic understanding of CPU that you should have. Now we have been using memory quantities but we didn't had the clarity right today we'll get that clarity but again for CPU this is the very first time we are doing this hands-on. So again you should have clarity about this units about this metrics. Now let's talk about memory quantities. What exactly is memory quantities? Basically it is nothing. Basically when we talk about 1 gabyte, 1 megabyte, 1 KB, kilobyte, right? Basically likewise same thing we have over here memory quantities. So memory quantities are nothing but the binary suffix such as KI, MI, GI this exactly 23:56:03 we have you used till now. Right? So this represent KB bytes, mebytes and GB bytes. Right? Now again GB and MB bytes both are different. There is just a slight difference and that is nothing but it's just about some MB difference but it's not the complete difference right but again the representation is not GB it is GI over here right it is GB not gigabytes it is me bytes not megabytes it is not it is not kilobytes it is gabytes just remember these three terms okay now memory here is a non-compressible resource so when a container exceeds the memory right because you define the boundary length apart from that if it goes it just say out of memory kill count that's the error that you'll get that is same thing that we are going to generate today now I think you have enough background for us to start with the hands-on so let me just switch to my terminal and this will actually help you to understand request and limits in a very next level right so now let me just uh go to my terminal and 23:57:06 here we go I hope it is visible to you all right so now what we are going to do is uh we are going to create one pod obviously but this time we are not going to create one uh random normal pod here we are going to create some boundaries for the pod that is with the help of requests and limits let's do the same but again uh just remember the units for memory gi for gabytes mi for me bytes and ki for kobytes right that's the unit that you have to keep in mind so for this video just remember that these value represent the amount of memory that we are requesting that we are telling kubernetes that these are the memory which are allowed for this container for this part to utilize. Right? So, Kubernetes will use these quantities as the uh as the boundary line so that the resource allocation can be done easily. Right? Now, here basically in Kubernetes architecture who is coming into the picture basically the scheduleuler will check based on the request and limits whatever you are setting based on that it will schedule the pods on the correct node based on the availability of this space based on the availability of your CPU. Enough 23:58:07 theory. Now, let's do the hands-on. So let us create one part. Now again like whenever we want to create any sort of resource in Kubernetes what are the four golden keywords API version kind metadata inspect. Let us do the same vim uh resource - demo. Uh let me first switch to my correct directory. So this will be going into subd directory number seven uh 27 that is request limits in kubernetes. And now let me just create uh the file resource demo. Now again the four golden keywords API version next is kind we have meta data and lastly we have nothing but spec again now since we are dealing with okay now since we are dealing with Kubernetes here we are defining the manifest we are telling Kubernetes that these are the requirement that we have right now now what exactly we are trying to create we are trying to create pod and that is something that we define in the pods how do I get the API version go to Google get it go to chat GP get it but again we are on terminal how do I get it in 23:59:08 terminal cubectl API resources. Let's do a grab on pod enter. Now here when you do enter you'll get the API version. Right now again go back to the resource file the manifest file and update the API version and again make sure of the indentation. Kubernetes is very strict with indentation because it uses YAML and YAML is again very strict with indentation that we actually saw and that we actually we are looking at initial phase just feel free to use terminal the max you can but again if you're facing challenges if you feel like you need some support do not go to chat GPT directly please switch your IDE okay make use of visual studio code okay use AI as as less as possible when you are learning okay once you have the data once you know the things then It's definitely it will be an add-on for you to learn. Now let's focus over here. We have metadata. Now what would we call this part? Let us give a name to this call. Right? So here let me call it as 24:00:10 resource. Resource resource hyphen port. This will be the name of the pod. Now again so now let us define the settings for this part. Now again what exactly runs inside a pod? It's nothing. It's nothing but containers. So here in the container let us give the name for this container. So here let me give it as app port that can be the name that you can give again which image it will be using uh you can use any image you can uh you can basically use any image that you want but here for this demo I'll use engineext um let's take a light image so l pine okay now here comes the main part here we have defined the container name as app okay and um sorry here we have defined the container name as app- pod and here we have defined the image image as engineix Pine. Now comes the main important part that is resource and request. Right here let us define the same. So here in order to define that boundary you have to define this keyword resource resources first. Okay. And here in resources what are the things that you 24:01:10 are defining? You will define basically the request what exactly we are expecting. So here request with s. Okay. And now inside request what are the things? What are the value that we are looking for? We will define CPU and memory for this specific pod. Right? So here let me define CPU. Now how much core this CPU should utilize? It should utilize 500 how much? 500 millores of CPU. Next what exactly we want? We will define the memory. M O R Y memory. Now how much memory this part should consume? For now uh since we are on mini cube we are using uh like local setup. Let us define 256 MB of storage. that will be sufficient I think because it is again an alpine image 256 megabytes remember this is not MB this is MI remember on the indentation remember on the last word the keywords the units okay now we have defined the request now let's go the limits the maximum resource the maximum capacity that it will exe that it can handle right so here I'll 24:02:12 define limits again inside limits let's again define maximum CPU units that it can actually use now how much maximum units It can use basically for uh for CPU it can be one core of CPU and now for memory m o r y memory now how much resource it will be using as a memory so we can define 512 m bytes this is the maximum that it can use escape col wq that's it we have defined the things and it was very much easier right we know how to create a part we just defined the boundary the resource that it should consume with the help of requests and limits that's it now let Let's apply the pod and verify the changes. Okay, let's do the same. Clearing the screen. I hope things are uh I hope things are making sense for you and it is very much easier for you to visualize for you to understand. Right? So now again we understood about the units. So now that's the reason it is very much easier for us to understand these things. Right? So now let us first understand one more thing that when we 24:03:14 talk about request and limit, let me first do a cat over here. Cat on Okay. So here you can see in resources we have two entities requests and limits. Let's talk about this because this is the place which we need a clarity about because uh usually people think that request is equals to uh limits but actually the thing is both are very different. Here what it says here we are defining CPU usage as 5 mill coursees right but it does not mean that it can only use 5 m of storage millores of CPU usage. Right? Now let's say there is a situation when there is a heavy traffic and it requires one core of CPU. Now since we have defined the limits this limit I'm referring to here we have defined that it can use the maximum of one core of CPU. It will be able to use it. That's the basic difference. I hope uh the difference is very clear request basically we are telling that this is something that it should utilize. Limits basically we are telling this is the maximum amount of thing the resource that it will be able to use. Right now 24:04:15 let us talk about one more thing before even we move further. Now we understood about uh the difference between request and limits. Now let us put our focus into the limits first. Right? Here we have defined the limits as one core of CPU and 512 MB of storage. Right? So here we have limits. What we are telling the maximum resource that we are allowed to use in this container is nothing but one core of CPU and 512 MB of storage. That's it. Right? Now again when we talk about uh CPU and memory. Now again there is a difference between CPU limit and memory limit. Basically the behavior of container what will happen if the container is utilizing CPU at the limit and memory at more than the limit. What will happen in that case? So what will happen when the container will utilize more CPU units and more memory units? Let us verify the same. So okay here in this case uh CPU and memory behave a little different when it comes to containers right so let's start with CPU first so if a container reaches a CPU 24:05:16 limit Kubernetes does not kill the container right CPU usage will throttle now what do I mean if I put it into simpler terms Kubernetes slows down how much CPU the container can use that is the basic thing that will happen when the CPU limit will exceed now when it comes to this gentleman that is memory with 512 MB of storage what will happen if this exist right so our application if it is consuming the memory more than the limit that has been defined then Linux will terminate the container and it will throw an error as out of memory and that's the error that we are going to generate today om killed count right om killed is a issue that you usually get when your application is consuming more memory which is defined in the request and limits right here the limit is crossed that the reason it is saying out of office out of memory right that's the thing over here Now enough theory let us apply the manifest file that we have created. So cube cuttle apply - f resource demo. And here it says the pod is created. And here it says the pod is 24:06:17 created. Let us verify the same cube cuttle get pods. Here it says container creating. All right. So now let us do one thing. Cube cuttle get pods once again. Here it says it's running. Meaning things are good. Our application is consuming the resource that we have defined. it is not going beyond that. If we have a situation where basically if it is going beyond the limit specifically for memory we will get an error out of memory and that's the thing that we are going to look next now right but again before even we move forward let us first verify now let's say if I give you a part and if I ask you to verify what is the current request and limit how will you verify without the manifest file we will make use of describe so let us do the same cube cut describe odd name is resource - pod enter. Now this is the place where you will define where you will be verifying your request and limits. Right? So here the limits is nothing but one core of CPU and 512 of space as me bytes and the request is for 24:07:20 500 mill core of CPU and memory of 256 MB of storage. That's it. This is how you verify the things. Right? So that's the thing that we learn over here. Now let's make the role of request very much clear with an example. So imagine that I have a node and basically now imagine that I have a node with one CPU available in that one in that node basically you want to schedule a pod right that pod will consume 500 MB of storage and kubernetes can schedule it because the space is available for that specific node for that specific pod that is actually is inside the capacity but if I try to schedule another pod if I try to create another pod over here uh with let's say 800 MB of storage then Kubernetes won't have that much feature right because 500 megabytes is already been consumed by PowerPoint right this is how request comes into the picture and that's the reason we are learning about it now what will happen in this case in the second case when we are telling Kubernetes we want a pod of which will consume 800 MB of storage at 24:08:22 that time we'll get a state as pending state and here it will be in pending state until it will get the storage available then it will run the pod that will happen when we'll uh when we are out of the resource over here. Right? So if you want to understand it with an example, let's take an example. So imagine that we have a Java API and we normally expect it to run around with 500 modes of CPU and 512 MB of storage. Uh so that's the request that we are making that we have defined in the manifest itself. But again uh let's say because of higher load what exactly happened is it is requesting up to one core of CPU and uh it is requesting 1 GBs of storage. Now what will happen if we don't define this request and limits right now let's say till now we have been we have been using that concept but now we are aware of request and limits but what will happen if we don't specify so basically if you don't specify request and limit consumption Kubernetes won't know how much how much resources your application will consume and it will behave differently now what will 24:09:22 happen without request and limits right now till now we were not aware of this concept so it's okay but now since we are aware of this concept we'll try to implement it but what will happen if we don't define this thing. So the basic thing is cubernetes will not know how much resource it should use. Now since we haven't defined the boundary line right we didn't have defined it the resource request that it should be consuming pod will behave very differently because especially during the pressure time right and this leads us to a new concept that is QoS classes that is quality of services. So now let us discuss about quality of services. Now again here we have three type of QoS guaranteed, bustable and best effort. Now let me switch to my visual studio code because this will give you a very good idea about how does a QoS actually works right? So Kubernetes assigns a part a quality of service QoS which is based on the users consumption of CPU and memory request and based on that it will treat your containers. Right? Let us discuss about guaranteed first. Okay. 24:10:25 pod gets guaranteed class every time when a container has CPU and memory limits equal to the CPU and memory limits that is been defined. So here the request and limits both are same. If I say in request I require one core of CPU and in limits I define one core of CPU. Basically both are matching. That's where that's something that we are talking about in guaranteed right now what happens in burst tableable class. So so now let's talk about burst tableable. Now if I put burst tableable into simpler terms basically it's nothing but whenever we are defining the request at that time we are just defining one entity that is CPU. So now let's say you are defining an definition a p manifest file and in that you are mentioning that it should request only 500 m of CPU and limits you are telling that maximum it should use is one one core. Likewise you can also define memory that it should use 512 MB of storage and limits you are telling that 1 GB of storage. So here what bust tableable exactly is happening over here is basically you are just telling only 24:11:26 one sort of resource type okay either CPU or memory or vice versa okay any one thing you are defining in request and limits now what happens in best effort so basically best efforts is the simplest one to understand because if none of the container has been defined with CPU and memory the pod is nothing but a best effort pod. Now how do we verify the quality of services classes? So basically again if you scroll down here you will find a command and that will help you to understand how do you uh investigate a pod the class let us verify the current class for the current port that we have created for that let me switch to my terminal now and now I will clear the screen cubectl get pods for listing the pods and here we have the pod let me paste the command that we have copied and here let me just go and update my pod name over here and I hope like this command is pretty much straightforward What? So like no explanation needed. But again I'll explain you once again. Uh let me just update the pod name. So okay we are getting uh we are listing the pod. The pod name is resource pod. Then we are 24:12:27 printing a JSON output. And here we are searching for quality of service classes. Enter. And here we are getting the quality of services as burst tableable. Right? That is something that we have defined over here. But again you will see that we are not uh satisfied with the answer. Right? But for that we have an explanation. Let me just tell you, let me just clear the screen first. Get on resource dot demo. Okay. Now see here you can see we have both the resource and the request that we have defined. Here we have defined the request for and here we have defined the request both with CPU and memory and we have defined the limits at CPU's memory. But again in order to make this as a guaranteed uh response as a guaranteed class basically we should match the request and limits that is the only case which through which we will mark it as a guaranteed class. But again why it is burstable? Because those two values are actually defined and those two are those two are different. Again the request is the minimum that should be consumed and the maximum that a container that a port 24:13:28 should consume is come something that comes into the limits. That's all for now. Now let us talk about an error that you will usually see into any sort of environment that is OOM killed that is out of memory killed. So now what we are going to do is we are going to create this mistake intentionally. This is a very common mistake and we are going to make this setting so that we can understand without even making things very much complicated. Right? So here basically what we are going to do is we are going to create a container which in which we are going to allow we are going to run a program. that program will actually consume lot more of storage that will be defined maximum that will be defined more than the limits right and that will actually help us to understand out of memory kill count so now let me just create a pod now clearing the screen and vim uh out of memory om killed hyphen pod this is the name of the pod whim now again four golden keywords insert more API version 24:14:28 signed metadata and spec. All right, the template is ready. Now again, what is the API version for pod? It's nothing but v1. Where do we get it from? From kubernetes doc, from google, from chat gp, from gemini, from cloud anywhere. But again, for our reference, we are getting it from API resources, from the uh terminal itself. Now again what is the kind? K kind here is nothing but the pod here metadata. What should be the name of this pod? Now since we are demonstrating for uh this out of memory let me call it as OM pod. This would be the name of the pod. Now again specification we will run a container. So container container containers. Now here let me just give it a name. So since uh we are running a pod. So basically let me give any name. Name would be nothing but app. Now here basically uh what we are going to do is we are going to run one Python program that will be capable of actually consuming the memory more than the limit that we are defining right so here let me just make use of pi make use of a python image here we are going to make 24:15:29 use of python image and now again python latest we'll make use of latest now again where you will get the image tag basically if you can go to docker hub you can find the image there itself for now I will be making use of python latest you can make use of python lpine and uh which is actually a lightweight image. Now here comes the main part. Now let me define the resources. Resources and here in the resources uh in the request basically since we are dealing with memory issue we are going to demonstrate OM killed. Basically we are going to generate that scenario. We'll just make use of memory over here. Right. So here I'll just type memory. Now how much memory it should use. Okay. Now for beginners we will just write 64 MB of storage. That's it because that will be uh the story that this part will consume. Right? Uh what I will do here instead of making use of latest I will make use of alpine image. Alpine image uh I'll do one thing. I'll open my browser and I'll search for an image in Python. Uh I think it is nothing but 24:16:29 3.12 I can see over here. Yeah. So we will be making use of 3.12 Python uh Alpine image that is a lightweight image. Now again in the request for here we are actually requesting a memory of 64 megabytes. Right. Now let me define the limits for it. So here limits in limits I'll again define the limit of the memory that it is allowed to actually use. Now how much memory it should use? It is it should use 128 MB. We are just guessing it right now. Now here comes the main part where we will be defining uh the Python program which will be responsible for creating the condition of out of memory. So here at the level of resources just write command and these are the commands that we are planning to run over here. So let me define Python. And here in the Python I want to run few commands which falls after hyper C. Then whatever we type after C that will be cons that text actually will consider as a command. So here what I will do I will allocate 200 maybe words of storage. So for that what we'll do we'll just type data equals to 24:17:31 basically you can get this uh program in charg also. So I actually took it from there all the uh so I actually took it from there itself. So byte array and uh the calculation byte array over here a byte array and here basically what we are going to do is we want 200 mgabytes of storage to 200 into 1 mgabytes is equals to 1 mgabytes is equals to 1024 right so 1024 into 1024 so this will be somewhat around uh let's say 200 or maybe 209 mabytes Right. So again we have defined the data that it should allocate the memory and then here we'll print uh this is the memory that is has occupied. So allocated memory chunks and now let me go down and here what I'll do I'll just uh import the time to print the time stamp import time. And 24:18:32 here after importing time what we'll do we'll just uh keep the process alive. So time dot sleep because this is how we will get the count and sleep 2 3 6 0 0 that is for r escape colon wq I hope this made sense clearing the screen uh let me first apply the file so cube ctl cube ctl apply I - f out of memory kill count enter here it says pod inversion v1 cannot be handled unmarshall object go to structure podspec dot containers of type v1 so there is an issue with containers. Okay, in containers, what is the issue? So, in containers, we have defined maximum things. Okay, so there is nothing that falls inside container. We have defined the name. Okay, that is again good. There is one thing that I missed that is nothing but insert mode. I need to pass on hyphen. Let me just correct the indentation. 24:19:43 Okay. Now escape colon wq and now let me apply the file. Okay. Out of memory pod is created. Now now now again clearing the screen. cubectl get pods. But this time instead of running it directly we'll run it into watch mode. Here we have successfully generated out of memory killed container. Here you can see it got killed. You can see one pod which is getting killed. Just put your focus in OM pod. Here it went into crash loop back up. Again it went to out of memory. This is exactly what happens here. We are intentionally telling the memory limit as 128 MB because and again uh in the application we are telling to consume 200 MB of storage. So this is just a demonstration that showcase what will happen when a container is uh when a what will happen when a container is asking more value of the memory which is defined in the limits right in current setup basically the limit that we have defined is 128 MB bytes but again the application is asking for more uh resource more memory right since we have 24:20:45 defined this boundary line he is not able to actually run the container we have successfully generated this issue what exactly we learned over here basically whenever your container container is requesting more than the limit you will get out of memory issue over here. So depending upon the environment and timing we should see the container terminated because of memory pressure. So this is the important thing that we have to learn. We don't have to memorize things which understand what exactly is happening over here. So memory limits can result into OM killed error which we are seeing over here right now. On a final note, memory limits can result in OM killed when a container exceeds its available memory under the memory pressure. Right? So on a final recap, let me just go to Visual Studio Code and this is where we'll see the recap. I'll go all the way to the bottom. So this will be the quick summary that we would be doing from today's session. So what exactly we learn? Basically we learn about request and limits. What exactly is request? Request tell Kubernetes that how much CPU and memory the container needs and 24:21:46 they help the scheduleuler to decide which pod is perfect for it. Limits define the maximum capacity of CPU and memory that the container is allowed to use. CPU are enforced by throttling and memory if they are overusing. If overused we will get out of memory killed error that we saw just now. And Kubernetes also uses these resource settings when uh it is assigning the quality of service classes such as guaranteed, bustable and best award. Now if you want to verify the current class of the running container, how will you verify it? Okay, that is again simple. Let me just copy this command again. I'll go back to the terminal and now let us verify the same. Ctrl C. Let me just paste the command over here. And let me update the pod name over here. What is the pod name? Name of pod is out of memory pod. Enter. Here the uh type of quality of services bus table. Right. Again there is one more thing I forgot to tell you. If you want to see what exactly is happening just run cube cuddle describe pod pod name is nothing 24:22:49 but out of memory hyphen pod enter. And here we are getting a back of error. Now if you go here in the quality of service class you can see the class as burst table. And if you scroll further upwards here you can see the limits. Limit is basically 200. And uh here the limit is basically to uh here the here the limit is basically 128 mabytes of storage and the request is nothing but 64 megabytes. That's it. I believe that was for today where we learned about requests and limits. This helps Kubernetes to assign resources in Kubernetes and scheduleuler basically will get an idea based on the request which is present in the manifest so that the application the pod doesn't consume more resource than actually which has been defined in the manifest. paste that was follow and I will see you in the next one. Thank you. We are now well versed with CPU and memory request and limits in Kubernetes. But now imagine that your application receives certain traffic. Now one pod will not be sufficient enough to serve the traffic. Right? So what one can do? 24:23:49 Basically one can just create another pod so that it can help this part to serve the traffic. That's all we can do. But here in this case we need someone who can continuously monitor that application. But wouldn't it be better that Kubernetes does this job automatically? So yes, this is the place where horizontal pod autoscaler or HPA comes into the picture. So in this video, we are going to create this scenario. We are going to create an application. We are going to generate a traffic and we are going to see live how does Kubernetes handle this sort of traffic this sort of situation with the help of the concept called horizontal pod autoscaler or HPA. So in order to understand HPA let us take an example. So now imagine that you go in a restaurant and there are only few customer who are visiting in that restaurant. So only one chef is sufficient enough to do the work. But let's say in the same restaurant multiple customers are visiting right the number of count are increasing. So in that case that single ship won't be sufficient right we need more chefs likewise in Kubernetes whenever any sudden traffic spike comes at that time 24:24:49 only single port won't be sufficient to do the work we need multiple working hands over here and that is exactly what HPA does. Now what exactly horizontal pod autoscaler does? It basically monitors the metrics. Now metrics of the CPU utilization. Now based on that it will add one more pod into the deployment and that is how it is actually making sure that the request has been served properly without any downtime. So that is the basic use of HPA. Now here there is one more thing to note that HPA is not responsible for adjusting your CPU and memory. That is actually defined. It just monitors the metrics. based on that matrix it is actually creating one more part so that the request has been sub so now enough theory let's do the hands-on now so before we jump into HPA there is one more concept that you have to be aware of and that is nothing but metric server now I mentioned earlier based on the utilization based on the consumption of CPU the Kubernetes basically will create one more pod but how does Kubernetes know that the utilization has been 24:25:50 incased in that specific pod this is where metric server comes into the picture what What it does basically it helps Kubernetes with the usage statics that is with the usage metrics right your metric servers actually collect the resource metrics from the cluster and makes them available to the Kubernetes and based on that Kubernetes will make the decision whether to create another pod or not right so for here in our setup we will be making use of mini cube and we will enable metric server as an add for this demonstration uh let me just switch to my terminal so here we go all right so Now uh in order to perform the demonstration for this specific one we are going to create another profile. So this will actually keep the work intact in a clean environment so that we will actually have a clarity what we are referring to. Again if you are coming from the previous video feel free to do the same on the same profile but here we are just defining a context because we want to do a fresh start right okay so now what we are going to do is we going to create a new profile. So for that just type mini cube start and then I 24:26:51 will write the name of the profile hyphen - profile and now since we are doing an HPA demo let me write it as HP demo and then we will need to define the driver name. So here who is the driver? Driver is nothing but docker over here. So hyphen driver equals to docker enter. So now what it will do it will actually create a new profile for us so that we can actually perform this uh def so that we can actually perform this specific demonstration easily. No problem. It will actually give us a clean environment. That's the basic use of creating profile. However, it is not mandatory. It is optional for you to perform. Feel free to skip this step. Now you can actually perform the next item that is we can enable the metric server. Now note this is an important step. Once the profile is created here we need to enable the metric server. Here we are using mini cube right. So now uh what exactly we are going to do? Now we actually create a separate profile name HP demo and now docker is the driver in this case. Now what we are going to do we are going to enable the 24:27:53 metric server extension over here. So how do we do it? First of all let me clear the screen. First of all write mini cube and then here we need to define the profile in which we need to enable the metric. So mini cube - profile profile name is nothing but hpa - demo and now we will need to define we will need to enable the add-on and the add-on name is nothing but metric server so here add-ons and the add-on name is nothing but uh and the add-on name is nothing but metric- server and here you will need to write one more thing and that is nothing but enable enable enter so what exactly it it it actually enabled that extension and the extension name is nothing but metric server. That's all we did. Now once it is done let us define the context of this specific profile because here we created a fresh profile and now we are going to switch the context. How do we switch the context? Let me define the same. So here what I'm going to do is cube cuttle config and then after 24:28:56 defining the config we will define use context and which context we are referring to? We are referring to HP - demo. Enter. And here it says we have successfully switched to the new profile to the new context that is HP demo. Clearing the screen. Now what's the next step? After doing the same. We are working on a fresh new cluster. What is the first thing we do? We check the nodes. We check the top nodes. So let me just run cube cuttle get nodes. Enter. And here you can see the node is ready. And since we are on mini cube, it will act as both worker node and a master plane. So here it defines the role as a control plane. Okay, that's exactly we need to to check. Now we are going to see whether the metrics are available or not. So how do we check whether the metrics are available or not? Because we enable the extinction metric server in the mini cube. Now how do we verify it? We need to just write cubectl top and here we need to define nodes enter. And here you can see error metrics API not available. Now why we 24:29:57 are getting this error? because we just created a fresh profile. It need so Kubernetes needs some time to gather the data. So after some time just run the same command you will get the output. So let me just pause the video for some time so that the matrix is collected and then we are going to rerun the same command so that we are getting the output. All right. So let us wait for some time. Okay. So now let me just try again and let me just rerun the same command. And now here you can see the matrix is actually started to get generated. This is what exactly we were looking for. If you're getting some error that matrix not found, matrix API not available, give metric server a little time to start. If the last command initially uh didn't reported the metric available, then wait for a moment and then run it again. You will get the output similar like this. Now our matrix is available and now we are ready to create our application. So what we are going to do? We are going to create a simple web application and then in that same application basically we will be making 24:30:58 use of deployments and we will expose it through service and then after that once both of these resources are created we will generate traffic through it from an external source. That is exactly what we are going to do. Right? For this specific demonstration, we will be referring the Kubernetes official documentation because there was one beautiful example I found which I thought like this will really add some value because that example makes life very much clear for us. But again uh you can use this documentation that I that you can see on the screen right now. This is from the official docs of Kubernetes. Can go with the official docs. But again if you feel like to continue with this video definitely there are few changes that I have did because this is specific to HPA right we don't want to learn unnecessary thing which are not required for us for now as a beginner keep things very much simpler to understand because the more complexity you will be involved with the more complex things will get first understand simply what exactly the things are you understood the topic then move forward with the complexity all right so now let's get started with the 24:31:59 deployment file and the service file for this specific demonst demonstration. So now what I will do, I will just create an basic uh deployment file along with the service file. Now again here again I will be making use of a single manifest file that will contain both deployment and service and that will actually do the job. Then again after the manifest file is created we will apply it. We will generate a traffic from an external source and then we are going to see the behavior of HPA based on the metrics provided to Kubernetes with the help of metric server. Let's get started. So now let me just create a new file clearing the screen vim. And now let me just name the file as hp- app.l. Now again what exactly we are trying to create? We are trying to create one deployment. So now before even we create any sort of manifest file in kubernetes. What are the four keywords? API version, kind, metadata and spec. Let me define the same. So here I'll go to insert mode. API version kind. Now what exactly we are trying to create? We are trying to create a deployment. So deployment and then uh API version kind meta data and now 24:33:01 lastly spec again. Now what is the API version for deployment? Well, exactly you can check into the uh documentation but now I will go to my best friend that is API resources. So cubectl API resources I'll do a grab on deploy enter. And here you can see the API version for deployment is nothing but app/v1. This is the exact value that we needed and API resources since it is our terminal friend. It actually helped us with the value. All right, let us go with the HPA file here. I'll update the API version which I got from API resources. Now in the metadata now basically here we will need to give the name of this deployment. What exactly we should give the name let us write as PHP apache. And now in this spec now what exactly this spec should contain? This spec contains the settings the configuration for that deployment. Now if you're aware about behavior of deployment, what does deployment controls? Does it control pods? Well, not exactly. Deployment 24:34:03 controls your replicas and replicas control your pods, right? Replica set actually controls your port. So here let us type how many replicas uh we want to be running. So here I will just try that replicas I just want one replica to be up and running because here we want to see uh that when a single soul application runs with a single pod what if sudden spikes come at that time what is the behavior of HPI that is something we are going to demonstrate that's the reason we are intentionally putting the replica count as one that's the reason now let us define the selector so selectors now again uh why we are defining selector ctor over here. Then basically the primary reason is how does deployment knows which ports to to target to right and how does services know which ports to target to. Basically it is acting as a key and a lock mechanism where we are providing with few values and that value will help us to locate those specific parts. Now again in the selector what exactly we are looking for? We want to match the 24:35:03 labels for the application which contains a key value pair. Right? So here let me just write match labels labels. Now what is that key value pair? Here I'll write the key as app and the value let us take the same name as deployment that is nothing but PHP apache. So here we have defined the selector and here we are targeting to those pod where the pods are been labeled as app equals to PHP apache. Now what exactly we did? We defined the configuration for the deployment. Now again we will need to define the template through which that pods will be created. So now let us define the template. Now here just below the selector I'll define the template. So template. So this template is basically for the pod. But again pod will be matched at what level? Basically here we will define the labels for those pod. So labels. So here in the labels I'll define exactly what we defined in the selector that is app colon apache uh app php 24:36:06 apache. So now we have defined the template and now let us finally define the configuration the spec for the parts. So now let me just define the spec for the parts and here this spec will exactly fall below the metadata. Here we forward one more thing uh just below the template we will need to define the metadata and inside the metadata it will fall the labels reds. So that's correct. Now let me just define the specification for the port. So spec. So in the spec here we are trying to create a container. So write container and in the container the first thing that we would be defining is nothing but the name of the container. So here let me define the name of the container that is PHP app. And now let me just take the image through each uh through it basically will be running the container. Now again uh we will be using the same example that is present in the official website of Kubernetes. So I will just copy the 24:37:08 URL from the docs and let me just get back to you on the same. So I'll just go open my browser and yes here it is registry.k8s.io/hpen example. So this is the image that we would be using. Right now coming next what is the next thing that we will define? Now again we are defining a web application but on which port it is running. So that port we are going to define. So here I'll just write ports and inside that ports we will need to define the container port. So container port container port and what is the container port for Apache PHP Apache? Basically it will run on port number 80. Here we are telling Kubernetes that the application listens on port number 80. Now we will need to define the uh resource request and limits based on that HPA will be triggered because these are the metrics that we would be providing. So now let me just define the resources and that resources will fall exactly just at the level of ports. So resources. 24:38:14 So inside resources the first thing that we would be defining is nothing but the expected requirement. So here request So inside request uh we will define the consumption of the request. So here since we are performing HPA demonstration we will request 200 m of CPU. So here CPU utilization should be nothing but 200 m of CPU. So 200 m and now I will define the limits. So limits for the CPU utilization. So what is the maximum amount of CPU utilization that can happen? So here it can be uh so it can be uh not more than 500 mores. So here we have defined the resources. In the resources we have defined the request and the limits the lower and the upper bound for the usage of the CPU. Initial thing is done. Now let us end this by typing three dash. This will give the indentation to Kubernetes that one manifest file is done. Now let us start with the another one. So now what is the second resource that we want to 24:39:14 create? We want to create a service, right? So let us define the four golden keywords API version kind is nothing but service meta data and lastly is spec again escape colq. Now why we did escape colq because we want to know what is the API version for service. How do we find it? Go to Google go to charge JP or best part go to API resources and get the values. So cube cuttle API resources and do a grap on svc for service and here we know the API version for service is nothing but v1. All right let us go update the file and here I'll update the API version for our new friend and that is nothing but v1. Now metadata what should be the name of this service? So what should we call this service as? We will just call it as PHP apache for now. uh we are giving the same name that we give to the deployment again like it just upon you whether which service name you want to use right next here comes 24:40:16 the main important section that is spec now what are the settings the configuration for this specific service now again in order to service in order to navigate the traffic basically service needs one entity and what is that entity that is nothing but the labels here we will define the selector through which it will target only to the pods where where this key value pair is matching Okay. So here let me define the selectors. So what are the selectors that we are looking for? So here we are looking for those um ports where the key is nothing but uh and the value is PHP - apache. All right we have defined the selector. Now comes the main part that is the port. Here we will define the server port. So let me just define ports and inside this port the first port that we would be defining is the port number through which the service will be exports. So here I'll write port and it service will be uh running on port number 80. And the next thing is we need to define the target port. Now what exactly this target port is basically 24:41:17 this will forward the traffic to the container port and target port we'll keep the target port also same as 80. And that's all we did. Escape colq and life is sorted. Clearing the screen and let me just list down the file. We have hp- app.yamel the file that we have created. Let me just apply the file. Enter. Now again life can be good but again we are getting error. Why? Because because of the YAML issues. Here we are saying that service got created but there is an issue with the deployment file. Now again I mentioned earlier also whenever you are typing three- kubernetes consider it as another file that's the reason service got created and right now our deployment got failed because of some yl indentation issues let us try to investigate it let us try to solve it and then we'll come to a conclusion what was the issue right I hope you are getting everything what we are doing to do but again if you feel like that creating a single manifest 24:42:18 file is creating confusion for you don't worry create a separate manifest file for service create a separate manifest file for deployment. It's just upon you on which sort of method you want to do. The main purpose for me telling this sort of mechanism is just uh like you should be aware that manifest file can be created in this method. All right. So now let us try to investigate this issue and what exactly is the issue over here is. So here it says error from server. We are getting a bad request. Error when creating this file deployment is in version v1 cannot be handled as deployment stick decoding error unknown field spec. template.spec.container. Okay. Spec.late do.spec.container. There is an issue with the template that we have defined for the I believe uh for the parts. So let me just go inside the manifest file. Okay. So here I got the issue. The issue is here it says spec. template.spec.container. So here it is not container. It should 24:43:20 be containers with this escape col. And now cube cuttle apply - f hp f. Enter. And now deployment is created. Service got unchanged. That is exactly how we solve the error. But again if we would have copied the entire the complete manifest file from internet we wouldn't have faced this error. we wouldn't have get this learning right that's the reason I explicitly say to you that try to create the manifest from your own hand that is how you will get the hands-on and that is how you will learn things in much clear depth right let me clear the screen and let us verify the resources now cubectl get svc for listing down the services and here you can see apache kafa is actually present over here cubectl get deploy and here you You can see deployment is not ready. Here it says up to date. Let us give it some time so that the pod is spin up and then we can 24:44:21 proceed further with the next step. Right? Meantime it is getting created. Let me just explain you the entire manifest file once again because I don't want you to go with any sort of doubt. This is exactly the platform that we are looking for where we can solve all the dots that you have. Okay. Clearing the screen and we'll do a cat on HPA app. ML. Let me explain you everything line by line. So what's the first thing that we have? We have API version, right? And let's go by two line API version and kind. What exactly we are tryinging here in API version app/v1 we are telling Kubernetes which API version we are using for the deployment. Next here we are telling kind deployment. So this tells Kubernetes what sort of resource we are trying to create. Next we have metadata. So what exactly metadata does? Here metadata contains the information uh that identifies our resources. Here we are naming our deployment as PHP apach. Now here comes the spec and here in the specs we have defined the replica is 24:45:22 one. What exactly spec is? Spec is the settings the configuration for that deployment. So what exactly we are trailing over here inside spec we have defined the desired number of deployment that we are looking for. So here we are starting with one replica that means we initially want one part running our application. Why? Because we want to do that testing and that is how we we are going to understand how does metric server exposes the metrics to the cubernetes and how does kubernetes behaves when a sudden spike has been observed into a pod and how does it will handle that sort of issues. Right now let us go forward with the next thing that is selector. So now let's move on to the next section that is selectors and label. So here you can see what exactly we are doing. What selector tells to the deployment. Here selector tells the deployment what p what parts it is actually managing. Then notice that we are using the same label that is app php apache in both selectors and label. What exactly it does? It will connect the deployment with the parts that it supposed to manage. Next we have 24:46:25 the specification for the containers. Now this is the configuration for the template that we have defined. So inside the pot template we are defining our container right. So we are using the sample application image and we are exposing it to the container port and that container port is port number 80. So here the image basically I got this exact image name from the official talks of Kubernetes. Feel free to check out the same. Right? Now let us move forward uh with the previous section that we learned that is nothing about request and in request we learned about request and limits. Right? In the resources we have two entities request and limits. Uh that is something that we covered in the previous video and we are utilizing the same here also. So now remember from a previous lessons HP actually require the uh CPU request to calculate the CPU utilization percentage. So here once the limit reaches to 500 mores so the container is configured with the maximum allowance of the CPU utilization once that utilization hits then what is 24:47:25 expected it should create another part right. So now that was the first section here here comes the second part that is service. So what exactly we did we defined the core Kubernetes API version as v1. Here we are telling Kubernetes what sort of resource we are trying to create. Here in the metadata we gave the name to the service that is nothing but PHP - Apache. Here it contain the specs the settings the configuration for the service and here we have defined the selector app PHP uh Apache. What exactly it does here? Basically uh service will select the ports with the label PHP - Apache and it will forward the traffic to port number 80. So here we have port number 80. This defines the port number utilization for the service. And here target port defines the port used by the application the port where the application is actually listening to. Right? So I think you are getting a complete ID of the manifest. Now let us verify the resources. So cubectl get svc 24:48:26 enter. Here you can see php apache is up and running. Let me just run deploy and check the status of deployment. Now PHP Apache deployment is up and running. Let us run cube cuddle get pods. Enter. And here you can see the pod is actually running right. So now our application is deployed. Now what we have to do is basically here the application is been run with one single pod and it is managed by the service. Right? Next what we are going to do is we are going to uh scale this deployment automatically. In order to do that we need to define the HPA value. Right? We need to define the HPA configuration. So we will tell Kubernetes three things. First is which deployment should be scaled. Second is what is the minimum and maximum number of ports and third is what CPU utilization the Kubernetes is aiming for. If you answer these three questions then you are done with the configuration for HPA file. Right. Let us create one HPA. Mamel. Clearing the screen. Vim HPA.L. Enter. Okay. Now again HPA is a 24:49:26 manifest. HP is a resource. Now what are the four keywords that we need to remember? API version, kind, metadata and spec. Let us write the same API version, kind, metadata and specs escape col. Now how do we know the API version for HPA? So let us uh find out the same. So here I'll write cube cuttle API resources. I'll do a grap on HPA enter. And here you can see the API version for HP is the API version for HP is autoscaling/v2. Let me update the same into my HPA.l file. And here I'll just update the value to autoscaling/v2 escape wq. Let me just copy the kind. So here I'll go to hpa.ml and here I am updating the kind to horizontal pod autoscaler. Now again what would be the name of this HPA? So since we are 24:50:28 working on PHP Apache so let me just write PHP Apache HPA. This would be the name of the pod autoscaler that we are going to create. Now here we need to define uh the workload that we are targeting into. So here we need to define the target. So scale target reference. So here we will pass the reference that this HP should target to. Now what it should so what sort of resource we are targeting over here we are targeting a deployment. So but before even that we need to define the API version and the kind of the same right. So what we'll do we'll just do escape colq because this is the place where we would be referring the previous manifest file. So let's do a cat on hp.l. I'll go to the top and there are few values that uh we will be needing that is nothing but API version and after that we will be copying the name of the resource. So the name of the resource is PHP - Apache. Let me copy these three 24:51:30 values. I'll go to HPA file again and now under the target reference let me just update the values. Okay, let me just fix the indentation. Here we have defined the API version app/v1. we are telling HPA board autoscaler to target the deployment and here we don't actually need uh metadata so here let me just go back here I don't require metadata so yeah next thing that we need is the name of the deployment name of the deployment is nothing but PHP apache now again we will need to define the minimum and the maximum count of replicas that this HP is supposed to manage so here let me just define the same I'll go to insert mode and here I'll just go over here and I'll define the minimum minimum replicas and minimum replicas should be one and maximum replicas replicas 24:52:30 it should manage as five. So after defining the minimum and maximum replicas for the pod autoscaler we will need to define the matrix. Now if you remember in in cubernetes in this mini cube we have defined one add-on that is metric server. This is where it will come into action. So here let me define the matrix. So here matrix will be used for the scaling purpose right based on the values where we have defined. So matrix. So here where it should get the matrix from. So here we are trying to define the sort of matrix that it is using for. So basically here it will get the matrix from the resources right. So here we will define the type of the matrix. So type resource resource and here inside the resource we will type the resource name. So resource and inside this resource we will define the resource name. Uh so what sort of resource we are targeting to? What sort of resource we are looking over here. So basically we are actually looking to CPU. So let me just write the CPU name. 24:53:31 So name is CPU that we are actually targeting to. we are actually looking for because here we are telling the pod autoscaler to monitor that specific CPU. Now here once that is done we will define the target for the same. So target and inside target we will define the actual target right so here basically we are targeting based on the type of utilization and basically we will write one condition that once it reaches 50% of utilization of CPU it should create one more pod. So now let us define the CPUmetrics utilization. So here we'll type the uh target as utilization and the utilization consumption usage should be average a v e r a g e and the average utilization is nothing but 24:54:32 nothing but 50% that's the reason I'm writing 50 over here right escape wq let me first apply the file first and then I'll explain you line by line cube cuddle apply f hpa.ml enter here it says invalid spec dometric dotresource targetype invalid value utilization okay utilize okay so I think must be either utilization there is a spelling mistake let me just go inside the file I'll update the values for both. This is not utilization. It is utilization. Insert mode. I'll update the values. The uh likewise I will update the value over here. Utilization. Here it is correct. Escape col WQ. Let me apply the file. Here it says the horizontal pod autoscaler is created. Right. Let me first explain you the file then we'll verify the resources. Okay. HPA.L. Okay. So what is the first thing 24:55:34 that we have defined? The first thing that we have defined is uh we have defined the API version and the kind. So here we are using autoscaling/v2. So what exactly we are telling is basically we are utilizing the API version as autoscaling/v2. Next is the kind. So here in the kind we are telling kubernetes what exactly we are trying to create. We are trying to create an autoscaling policy and that autoscaling policy that we are using is horizontal pod autoscaler. Right. Next. Next we have defined the metadata. What is the name of this port autoscaler? That is nothing but PHP Apache HPM. Right? And now here we have defined the spec the settings the configuration and here comes the main important section that is scale target reference. So this is a very important section in uh HPA because it tells HPA which workload it should manage. Here we are pointing to the deployment named PHP Apache that exactly we mentioned over here. So here the HP will change the deployment's desired replica count. The deployment and the replica set will then make sure 24:56:35 that the actual ports matches that specific count. Right? Next we have minimum minimum replicas and maximum replicas. So here min replicas basically is defining the minimum number of pods that we want. And then here we are telling maximum replicas. So here in maximum replicas we are telling that the pods HP is allowed to scale to. Right? So here in our case it is five. So our application can scale between one port to five ports. Finally we have the metric utilization. So here we have defined the utilization and the average utilization. What exactly it is? So here we are telling inside metric uh we are telling HP to monitor the CPU. That's the reason we have defined the name as CPU. Right? And based on the utilization what exactly we are telling here the target is 50% of the average CPU utilization. So remember uh when we created the deployment at a time the CPU request that we mentioned was 200 modes right. So what will happen in this case? So the 50% of 200 m is nothing but 100 24:57:36 m. So uh once the request is approximately 100 m CP usage per pod then what it will do HP will compare the uh metrics provided by the metric server and then based on that it will adjust the replica counts accordingly. So this is a target and this is not exactly guaranteed because uh here basically we are just telling how does the autoscaling works here we are not trying to maintain the exact 50%. That is something that you have to keep in mind. Now let us uh verify the resource. So clearing the screen cube ctl get HPA enter here you can see the HPA value is present in front of us and here you can see right now no CPU utilization has been done that's the reason we are getting uh 0% over here but again the value that we have defined the condition that we have defined is it should monitor the ports based on 50% utilization of CPU it should spin up one more port right now the current port that has been running is one and here you can see uh you can See the one 24:58:37 replicas is mentioned over here. If you want to get more detail on it, just run cube cuttle describe HPA followed by PHP Apache HPA enter. And here you can get more detail of the HPA. Right. So here you can see here we are saying that able to scale here it says true. Then here it says scaling is active. And then finally yes it say the desired count is within the acceptable range. Meaning right now life is good. There is no problem in that. Now what exactly we are going to do now we are going to create separate pod as a client which will be serving traffic. So from that specific place it will serving the traffic right. So let me just go to my visual studio code and let me actually show you uh the command that I'm talking about. If I scroll all the way to the bottom here is the command that I'm talking about. What exactly this will do? Basically this will generate a temporary uh load into the application that we have created. Now again let me just first verify the uh resource name that we have given to the 24:59:38 uh this thing. Uh let me switch to my terminal and here let me just run cubectl get deploy. Okay. So the name of the deployment is nothing but PHP apache. Clearing the screen and here let me just copy the command from my visual studio code. And uh here you can see we are running one command that is uh we are creating a load generator which is using a busy box image. And then we are trying to generate a traffic on this service that we have created. The service is basically PHP - Apache. Now let me press enter. There is one more thing that we need to do at paralle. Let me just open one more window. Basically this will be intact. And here what we are going to do we are going to actually watch the HPA to do the actual live action. So cubectl get hpa and here we are talking about php apache hpa - watch or hyphen w you can write let me just do a little bit of 25:00:39 zoom over here and let me just reduce this that screen will be intact your entire focus should be there on this screen here you can see the CP utilization is increasing that is exactly where you should actually focus on. So now here what exactly we should watch? We should watch at two place. First is the target. Here we will see the CPU utilization and second is the replica count. Now here you can see replica count increased to two. Why? Because the CPU utilization was more than 50%. 50% we have mentioned right 200 m of CPU it was utilizing per part. But then when it crossed that limit right that is 100 millores then it increased the replica count as two. That was the main purpose of using a horizontal pod autoscaler. But till how much replicas it will maintain. Basically here we defined the minimum and maximum replica count. Minimum is one and maximum is five. Let us give it some time. It will generate more load on it and let us see what will be the change into the replica count. So here what exactly happens is so HP will 25:01:39 calculate the desired number of replicas and will update the deployment. Then the deployment will create the additional ports. So depending upon the actual load how quickly the metrics are collected you may see the replica count increase over the next few minutes. So your output will definitely differ from that of mine but that is exactly very normal. Here the main thing that we are demonstrating is nothing but the behavior of HPA based on the traffic received. Now here you can see the CPU utilization is increasing and based on that the pod autoscaler is actually increasing the number of pod. That is exactly what we wanted to do, right? I hope things are making sense, right? Uh let me just tell you what exactly is happening over here. So let's just understand the flow. So here what exactly is happening? The load generator is sending the request to the service. Then the application is experiencing more load. Now that load is basically because of the CPU utilization, right? So now what exactly metric servers do? It will provide the metrics. It will tell Kubernetes that there is a resource 25:02:41 utilization happening at the CPU level for that specific pod. Now what HPA will do? HPA will compare that utilization metrics given by the metric server and based on the target that we have defined. Now what is the target? We define the target as 50%. Right? So the measured usage indicates that more replica sets are needed, more replicas are needed, HPA will increase the number of desired replica count. Then what exactly will happen? The deployment and replica set will create additional ports and that is exactly what we call horizontal pod autoscroller or what we call as HPA right so here you can see the traffic is currently going up now what will happen if that spike goes down let me just currently terminate the current session that is actually happening over here I'll press Ctrl C here you can see the command got terminated and now let me just close the screen here just focus on the replica count and the pressure on that specific CPU. Now here we saw the we saw one way where the 25:03:41 traffic was going all the way to the drop. But what will happen if there is less traffic we less uh pressure we are giving on the CPU at that time the end expectation is that the CPU utilization is going low. So the replica count should be going less as we expected. Right? So here what we did we stop generating the traffic. So here what we did after we stop sending the request the CB utilization eventually dropped HPA what it will do it will reduce the replica count but it will not happen immediately right it will actually take time so the uh so the main thing over here is uh the metric server will provide the statistics that hey right now I think the things are looking good so now let's now reduce the code because here we mentioned that the minimum replicas that it should handle is one and the maximum was five since we already reached the threshold the maximum minimum was already highlighted. Now the traffic is traffic spikes is less. Now let us reduce the replica count. So here the deployment and replica set are responsible for bringing the actual number of pods in line with 25:04:43 the with the desired replica count. Right? So the most important thing that we have to remember over here is here what exactly HP will do? HP will reduce the replica count and eventually you can see uh that it will reduce the number of pod. Right? Now here Kubernetes uses a default scale down uh mechanism to uh stabilize and actually it takes nearly about 5 minutes for the ports to quickly adapt when the matrix fluctuates. So give it some time and watch the replica count at the end and it will be basically minimum to one when there is no traffic received. So now let us take the recap of all the things that we have learned so far. So what we learned HP automatically adjust the desired number of replicas based on the metrics and metric server basically it will provide the stats uh the usage of the CPU to the Kubernetes and based on those stack HVA will basically create the number of replicas right so CPU request matters because HPA uses them to calculate the utilization and the deployment and replica sets are actually 25:05:44 responsible for bringing the actual number of parts in line with the desired replicas account. The most important thing that we should remember is HPA scales horizontally by changing the number of ports. So that was all in this video. I hope you learned a lot in this video. You just not learned, you just understood, you visualized what exactly HP is. So yes, that was all in this video and I will see you in the next one. Till then keep learning and thank you very much. We now learned about horizontal pod autoscaler or what we call as HPA. So now we know that Kubernetes is capable of increasing or decreasing the pod based on the workload received on the application. But what if adding another pod is in the solution. Now let us take an example. Let's say that your application is running inside your pod and that pod actually requires more resource consumption. Now that resource can be your CPU utilization. It can be your memory utilization. Right? So here adding another pod won't make any sense. Right? So what if there is a way where 25:06:46 Kubernetes can automatically figure out the behavior of the application consumption and it adjusts the resource consumption. So this is possible with the help of vertical pod autoscaler or what we call as VPA. So let us first understand the difference between HPA and VPA. So let us imagine that your application is running inside the port. So with HPA what Kubernetes will do it will actually adjust the number of part so that it can handle the workloads. With VPA basically it will adjust the CPU and memory usage and based on that your application will work fine. So now just remember with HPA basically it will change the number of count and with VPA it will adjust the CPU and memory resource so that your application can work fine. So now we are good to start with understanding what exactly VPA is. So let us understand how does VP actually works. So VPA here actually monitors your CPU and memory consumption of your application over the time. So here this information is needed to calculate how much CPU and memory your application should request. Now let's 25:07:47 take an example that your application was initially using just 100 m of CPU but over the time you observe the workload. Now based on that VPA will recommend that you should request high CPU usage right. So here it depends upon the configuration. So here VPA will recommend and if the configuration is different at that time VPA can be applying that changes automatically. But on what basis it is taking that decision. So here three components are involved. Recommender, updater and admission controller. Recommener basically recommends the changes based on the application usage of memory and CPU. Now updater it will decide when to update the ports and admission controller it will apply the recommendation to the ports which are created or which are restarted. Now we have the baseline set. We now understand what exactly VPA is and how does it works. Now it's time to start with the hands-on because that will actually give us the clarity. So let's get started. Okay. So before creating the VPA configuration, we need to install VPA itself because unlike HPA, VP is not 25:08:49 included into the standard Kubernetes cluster by default. So here what we'll do, we'll create a fresh new mini cube profile for our demonstration to stay separate for the other experiment. Right? So here you can follow the readme.md that you can find over here. And here we are referring to 29 subreository which you can actually check it out into my GitHub repository. All you have to do is scroll all the way to the bottom and here we are actually using this command to create a new profile. Now what exactly this profile does? Basically here we are telling mini cube to create a new profile. The name of that profile is vp demo. Then here we are specifying the driver. So here basically docker is the driver which is actually making sure that our mini cube is starting. Now here you can play with this values. So based on your PC configuration, you may change this value. Uh so here you can make use of four CPUs with 6 GB of memory and then you can specify the Kubernetes version two. Right? So I will be using the same command to uh create the mini cube cluster. Now let me just switch to my uh terminal and then we can we are actually 25:09:51 good to start with the today's demonstration. So let me just create uh the mini cube profile for today's demonstration. Now at the back end what exactly it will do? It will create the mini cube profile for us. So that we are good to start with the uh today's demonstration. Now here we are actually working on VP demo and that is the reason here we are creating a profile for VP demo. Feel free to play with this profile name because this is something that is variable that may vary over the time right but our focus here is to just learn how does vertical pod autoscaler works right because we already know that how does horizontal pod autoscaler works. This will actually give us a complete idea how does VB actually works. Right? Let us give it some time so that it is created. Once it is created then we will need to enable the metric server. Now why do we need metric server in the very first place? So see the thing is a metric server is someone who will actually help us with the metrics of CPU and memory. Now whenever I am talking about we are monitoring the resource that resource is nothing but your CPU and it can be your memory. 25:10:51 Right? So once your profile is created then what we'll do we'll just enable the metric server for us. All right. So let us wait for some time. All right. So now the profile is created. Clearing the screen. And now let me just paste the command mini cube profile vp demo. That is the name of the profile. And here we need to enable the metric server. Enter. And now here you can see the metric server is enabled. Now since we created the profile now we need to change the context to the new profile. Right? How do we do it? Just write cube cuttle config. use hyphen context vb- demo enter. And now here you can see we have switched to the new context that we have created. Right? Now how do we verify whether the cluster is actually running or not. So for that just write cubectl get nodes and here you can see the vp demo that control plane is actually ready. Now in order to check whether the metric server is up and running. So for that just write cubectl top nodes and if you're getting the value right here you here we are getting an error that matrix is not yet available. So give it some 25:11:53 time now once the time is given then the metric server will actually help us with the values and the matrixes will be available over here. So let us wait so that the metric server is actually populating the value over here. So metric server here is an important uh component because VBA needs a resource uses metric to make that recommendation. So wait until cube cutle top pods works before continuing further right. So let us wait further more and here you can see the metrics are available now. Now what exactly we need to do? We need to install VPA into the system. How do we do that? So basically let me switch back to my visual studio code and here in the documentation itself you will find the entire commands that we are using in this video. So here basically the cubernetes autoscaler repository it will contain the VP installation scripts. Right? So these commands are helpful for us to set uh the VP installation into our mini cube cluster. Right? I will be using these exact commands that will be 25:12:53 helping us to install the VPA script. Right? So what this script does it will set up the uh VPA uh into your Kubernetes as a resource and it will include its custom resource definition it will include it permission the controller components. So based on the size of the repository it might take some time but yeah once it is ready then we are good to start with the end zone right so let me switch back to my terminal once again here we go. So let me just create a directory by writing mkdir - p k8svp demo. Now let us go inside this repository. So I'll just type / k8svp demo. Now here you can see the path has changed. Now the next thing that we need to do is we need to clone the autoscaler repository. So just write get clone http github.com kubernetes/autoscaler.git. And here you can see in my case autoscaler uh that repository already exit. So I don't have to worry about it. Now what I'll do, I'll just go inside 25:13:55 autoscaler repository and inside autoscaler I need to search for vertical pod autoscaler and here you can see I am inside the vertical pod autoscaler. Now there is a script that I need to run over here which is by name hack and here we need to run vpsha up.sh this is the exact script that you have to execute once you are inside that repository. Enter. All right. So once it is executed, you have to just wait for some time so that the VP components are ready. Right now uh once this is done then we will verify the installation. How do we verify it? So basically since we installed a VP component we can just list it into the name space called cube system. Right? So clearing the screen just type cubectl get pods in the name space cube - system enter. So basically here you can see three important components that we were discussing earlier VP 25:14:56 admission controller VP recommener and VP updator along with there is an CD for VP demo and that is exactly what we were looking for. So now the basic setup is ready. There is one more thing that we need to check that is we need to check the uh CRD whether that is that is present or not. So what we will do we'll just write clear and just type cubectl get CRD. Now what exactly CRD is? CRD is nothing but custom resource definition. So there are a few definitions that you can write based on your requirement. Here we are looking for vertical scale autoscaler and here just type autoscaling vertical pod autoscaler and here we are looking for this specific value autoscaling k8s.io IO. Okay, let me just uh rewrite it again. Okay, enter. And here you can see the VPA checkpoint is present. Meaning the custom resource definition that we were actually looking for is actually present over here. So the important thing that we have to 25:15:56 understand over here is when we install VPA then it will give Kubernetes the ability to make vertical scaling recommendation and then it will help it to apply them according to the configuration. So now enough theory done. Let us deploy the application that consumes the CPU and VPA has something to observe right. So what we are going to do now we are going to create a deployment with two ports and each will initially request 100 m of CPU and 15 MB of memory. So here in our sample application uh basically it will repeatedly perform CPU intensive work and then this will give VPA resource usage to observe and help us to identify the recommendation changes. Right? So now let us create a manifest file. Clearing the screen. So now let me just go to my directory. So I'll just go inside desktop. And here we have Kubernetes tutorial. We are on directory number 29. Okay. And here we have one readme.md present in front of us. Clearing the screen. And now let us create a new file. Vim vp app.yamel. 25:17:00 Enter. Now again whenever we are creating any sort of manifest file in Kubernetes, what are the four keywords that we need to remember? It is nothing but API version time metadata and spec. Now again what sort of resource we are trying to create over here? We are trying to create a deployment over here. So I'll just type deployment. Now again what is the API version for deployment? Now again since we have been doing it from so far we know that the API version is app/v1. But again if you want to verify where exactly we can verify you can actually verify the values in Google Chrome chat GPT any AI model or cubernetes documentation or the last thing that you can do is you can just run cubectl get resources API resources resources and do a grap on deployment enter and here you can see the API version is nothing but app/v1 okay let me go back and here let me update the 25:18:00 API version. Insert mode and here you can see I have updated the API version. Now here in the metadata I will define the name of the deployment. Now what is the name of this deployment? I would love to call this deployment as VP demo. Now here it contains the spec. Now what exactly spec contains? Spec contains the settings for this deployment. Now again when we are dealing with deployment basically here we are dealing with uh replicas, right? So here we need to define the replica set. How many replicas do we want to run every time? So here I will define the replicas. So replicas the count should be maintained is two. Now again after replica on which basis it will define which port to target to. So here comes the important section of labels and selectors. So let me just define the selector over here. So selector and selector I will define as the matching labels. labels and the label should be nothing but app colon I will give the same name as the deployment that is uh vpen demo so we 25:19:02 have defined the selector over here now let us define the template now template for what template we are going to define it for the uh container that the deployment will is so here we are going to define the template for the part that the deployment is supposed to manage right let me define the template now so template now again in that template Again what I what all things will come again since we are defining the template here we need to define the metadata for the template right so here I will write metadata and metadata will contain the name so basically here u and and metadata will contain the labels so labels now again what would be the label in this case again you can make use of the same label that you have used over here make sure that this label actually matches with the selector so here basically we won't be facing ing any issue later on. Right? So here what we did we defined a template and that inside the template we uh define the metadata and inside the metadata we define the labels. Right? Now let us define the specification for the part 25:20:03 that we would love to create. So spec and inside the spec what are the things that will come right first thing uh inside a pod basically what exactly we run we run the container. So I'll just write containers. Now again what would be the name of that container? So here I'll just write the name of that container is nothing but app. Which image are we using in this case? So the image that you can use over here is any sort of slime image. But here in our use case I will make use of registry registry.ks.io/ubuntu slim view and Ubuntu slim and the tag that I would be using over here is 0.14 0.14. So this is the exact image that I will be using for the specific demonstration. Now again you can make use of Ubuntu slim image. Now it again depends upon the u use case that you're using for again here I will define the resources. Now again whenever I'm talking about resources what exactly I'm referring to? I'm referring to the usage consumption of CPU and memory. So resources 25:21:05 now inside resources what are the two values that we would be defining? Again here we need to define the request and limits. But again here we are dealing with VPA. So I'll just define request. So in the request basically what all values should I define. So basically here we're telling what is the minimum value that it should request. So here I'll define the value for CPU. Now initially we'll just give it as 100 m. Now what is exactly 100 m? 100 m is nothing but 100 m of CPU. And now let me define the uh request that this application should raise for the memory. So here I will type memory and here it should request for 50 MB of storage. Right? That's why I'm writing MI over here. Resources section also done. Now there are few set of commands that I want to run over here when the container starts. So here let me just define the command. So here just below the resources I will write command. Now which command do we wish to run over here? That is exactly we are going to define over here. So first thing that I want to do is I want to run one shell. So that's the reason I'm writing /bin/bar. 25:22:07 Next thing that we want to do is we know we actually want to pass few argument to this shell. So for that let me just pass the argument. So args. Now inside this arc come the important section. So here we'll pass the uh command string. So for that the first thing that you will need to do is you will need to just pass hyphen C. Remember there was earlier method where we were just directly passing hyphen C and it was actually doing the change. And this is the another method which you can actually follow so that you can get a appropriate result. Basically there are two ways of writing this manifest. Right? So here we are following the argument method. Now here comes the important section because this is the important point which will actually generate the load in your CPU. So what exactly I will do? I will just pass this command which will be responsible for generating load into the CPU. So while do time out 0.5 second guess and then it will fill it will generate the load into the CPU. That is exactly what exactly we are doing over here. So here it will generate the load into the CPU repeatedly. Here initial things it done there is few thing that we need to define. Now since 25:23:08 uh here we are dealing with the container. We need to define the security context. Now what exactly security context is let me cover it later but for now just uh uh understand that security uh context is something that will help us to configure the port security setting. So let me just define the same. So security inside that just write context security context and inside security context you need to define few more values. Now what are those few values? You need to define that do you want to run this container as a root user or as a non-root user. So here I will just write run as nonroot and here mark it as. So here we want to run this application this container as a non-root user and here just write run as run as user u in caps and then here just type 6534. So here it will just mention 6534. So what exactly this means here we are telling that use the unprivileged user ID that is nothing but C534 right 25:24:12 escape colq clearing this screen let me just do a CAD on VP enter now let me explain you everything step by step here what exactly we have we have the API version so here we are telling that Kubernetes uh that we are trying to create a resource which falls under app/v1 API version. What exactly resource we are trying to create? We are trying to create a deployment. What is the name of that deployment? The name of the deployment is VBA demo. Now again what are the settings for that deployment? Basically here the deployment will manage two replicas on the basis of the selectors and it should match the labels where the key is app and the value is VP demo. Then we have defined the template. So the template basically here we defining the matching labels it should target to. Then again comes the spec. So in this specification we have defined the uh port configuration that it should actually do. So here the name of the application is uh app. Here we have defined the image. The image that we are using is registry.ks.io Ubuntu happens. You can make use of any 25:25:14 Ubuntu slim image over here. Then here we are defining the resource. Inside resource we have defined the request and this application should request initially 100 mgores of CPU along with 50 MB of storage and it should run one command that is capable of uh creating a CPU load. Then here there is an important uh thing that you have seen that you are actually seeing over here which is actually new. Let us understand the same. So here what exactly we are doing is here we are actually configuring the port security setting and here we are telling the uh container to run it as a non-root user and then lastly what we have done is we are telling that run it as a non-privileged user where the ID is 6534 that's it that exactly we have done now instead of moving and directly applying it uh instantly let us create another manifest file now why do we need another manifest file now if you remember when we were working on HPA we were We defined an another HPA file, right? So here for vertical pod autoscaler also we need to define another manip file right. So now 25:26:14 let us create another VPA that should manage and it should tell us how should I apply the recommended resource. Right? So let us create the second YL for us. So whim VPA - policy dot ML enter. Now again uh since VBA is also a resource type in Kubernetes what are the four keywords that we need to make sure that whenever we are working with Kubernetes so those are API version kind metadata and spec let me write the same so API version kind metadata and lastly we have spec okay now what exactly we are trying to create over here we are trying to create a vertical pod autoscaler so I'll just type vertical pod autocaler autocal a all right now again in the API version I don't know what is the API version for VPM so let me just do escape wq and here I'll just write cubectl API resources and I'll do a grab on vertical pod autoscaler and here you can see you 25:27:15 get the API version for vertical pod autoscaler that is nothing but autoscaling k8s.io/p1 io/p1. Let me update the same value into my manifest file. I'll again open my manifest file and here I'm updating my API version and I'm updating it to autoscaling.k.io/v1. Now here we have defined the API version. We have defined the kind. Now let us move forward with the metadata. So what should we call this VPA configuration? So since we are dealing with a verypical pod autoscaler, let me just give this uh resource name as nothing but VPA demo. VP- demo. All right. Now let's come to the specification section. So this is the actually important section where we are defining the VPA configuration. So uh how does the VPA know that which resource it should target to? So for that we are going to define over here is target reference. Right? And how do we define the target reference? First of all quit from this file. And now open your policy file. So cat open your 25:28:16 application file. So VPA - app. And here just go all the way to the bottom. Copy the initial four line. And now let me explain you what exactly we are doing. I'll again open my VPA policy file. And here in the target reference if you remember when we were working on HP at that time also we have defined the reference. Right? So here exactly we are doing the same. Here we're telling that you should target the API version where the app where the API version is nothing but app/ V1. Here you have to target a value and that is nothing but a deployment. Uh don't worry on the metadata section. So let me remove it. So escape colon wq and let me open it again. And here let me just delete metadata. And again here what exactly we are defining into the target reference. Here we are saying that the target uses the app/v1 API. Then what exactly we did? We telling that the target is nothing but deployment. And then here we are telling that the deployment name is nothing but VPI happen demo. That is exactly VPA will know what uh what what what 25:29:17 and that is how VPA will know what resource to target to. Now let us define how VP applies the recommendation. So for that we need to define one more entity and that is nothing but update policy. So update policy. Now inside update policy what are the values that can fall? So basically first of all we need to define uh one more thing that is update mode. Now there are two values in update policy. So let us learn about recreate. Now so here I will write update mode and here update mode is nothing but recreate. Okay. Now the next thing that we need to do is we need to define the resource policy. So here we are defining the boundaries for the resource recommendation. Right. So here let me just write resource policy. And now let us define the boundaries for it. Now since here we are doing the configuration for individual containers, we need to configure the policies for that individual container. So for that here we'll type container policy 25:30:18 policies and here inside the container policies we need to define the name of the container. Now what exactly is the container name so that we can get it from our deployment file. So container name. Now what is the container name? Escape WQ. And now let me do a vim on vimvp app. Here the name of the container is nothing but app. So I'll update the same into my policy file. I'll go all the way to the bottom and here I will update the container name. So the container name that we are looking for is nothing but app. Okay. Make sure that this container this C is in lower case. All right. Now we are good. Now let's move forward with the next section. So here we have defined the configuration policy for the individual container and the name of the container is nothing but app. Now here we need to define the minimum allowed resource values right and how do we do that for that you just have to write min allowed resource and resource that we are allowing for minimum usage for CPU the minimum usage 25:31:20 that we are uh telling that that do not recommend the resource uses less than 100 m of CPU and likewise we will define the same for the memory And here we are telling that in memory do not uh recommend less than 50 m bytes of storage. So here we have defined the minimum allowed uh recommend resource. Now likewise we will define the maximum allow allowed resource recommendation. So maximum allowed resource recommendation for CPU. So now what can be the uh maximum allowed value. So basically we can just mention that do not recommend more than one core of CPU and when it comes to memory. So likewise let me just type memory. So for memory instead of 50 MB just type 500 MB. So it should not recommend more than 500 MB of storage. Right now again here we have defined that uh it should 25:32:21 uh not suggest the values the minimum threshold and the maximum threshold. But what exactly are we trying to control? So for that you need to define control resources for so so from that it will get in clarity what are the things that it it falls under the scope. So I'll write controlled resources and in the control resources I will define two values that you should take care of that is CPU and second thing that you should take care of is nothing but memory. All right. So we have defined uh the VPA to manage the CPU request and we have defined the CPU to uh manage the memory request and here we want to update the request with the managing uh managing limit. So for that we will define the control values as request only request only. All right. So I think this is done. Let me just do escape colon wq. And now let me clear the screen. Let me do a cat on vpa - policy. The policy is 25:33:24 ready. Now let me explain it to you from line by line. Okay. So here we have defined the API version. Then we have defined the kind. We are telling Kubernetes that we are trying to create a vertical pod autoscaler. And here in the metadata we have defined the name. The name of the vertical pod autoscaler is nothing but VP- demo. And here we are defining the settings the configuration for VPA vertical pod autoscaler. And in the specification we have defined the target reference. So here we are telling vertical pod autoscaler that you have to manage this deployment. The name of the deployment is VP demo. And here we have defined the update policy. So here in the update policy you can see we have selected a regret. So that means when a VPA decides a resource change is needed, it can evict the pod the deployment will create a replacement and VPA will apply that updated resource request when that uh replacement pod is created. So this can interrupt the workload. So it needs to be considered. So this needs to be considered uh carefully when it comes to production. Right? Now then what we have done we have defined the container policies and here in the container 25:34:25 policies we have defined two values that is minimum allowed and here we have defined the maximum allowed. So here we have given the minimum and maximum threshold uh that is the suggestion uh that the VPA should supposed to tell us right. So finally in the control resources we are telling uh VPA that what are the resources that it should manage. So here we are telling that you are supposed to manage the CPU and memory. And lastly what we have done we have defined the control values. So here we have mentioned the control values as request only which means that VPA manages the request not the limits. So this settings keep our demonstration focused on how VPA adjust the resource request. I hope that made sense. Now let me clear the screen and let me list down the file. Here we have created two files. One is VPA app and second is VP policy. Let me first apply the first file that is vp which contains the deployment cube apply - f va app.tamel html enter here we are getting an error here it says error from 25:35:27 server bad request error when creating VP- app deployment in version v1 cannot be handled as deployment stick decoding error unknown field spec spec template dot metadata dot labels oh there is a spelling mistake here you can see I'll update it immediately vim on vpa - app so here I need to go to labels it is l a b e ls This insert mode l a p e ls now it should be good escape wq applying cube cuttle apply hyphen f vp- app.l ML and here you can see deployment is created. Let me clear the screen. Let me just apply the another manifest file. So cube cuttle apply -f vp - policy.ml. Again we got an error into the policy file 2. So here what we are getting? We are getting a med request. Here it says vertical pod autoscaler in version v1 cannot be handled as vpa strict decoding error meaning another uh spelling 25:36:27 mistake or indentation issue. Unknown field spec. resource policy container policies and here we are getting control values. Okay. So here I think I made the mistake with the u values. So here I think this should be in lower case and that should solve the issue. Again I'll fix the uh manifest file. So VP policy. Now here I'll go all the way to the bottom and here I'll go to insert mode. I'll fix it. Escape colon wq. Okay. Now this upper character C is moved to lower character. Now let me just apply the file cube cuttle. apply - f v- policy.ml enter and here we are getting an error the vertical pod autoscaler vpa is invalid spec dot resource policy control values unsupported value request only supported values are request and limits and second is request only okay now see here in the error itself it is telling us the correct answer so the first thing that we need to fix is the request only section let me first fix that and let us 25:37:27 come with the second one I'll go to the insert mode here. This is not a request only. This should be request with s. So again I fixed it escape wq. All right let me just apply it. Clearing the screen cube cuttle apply half an vpa policy. ML and with that we have fixed the policy file too. Now let us verify the resources that we have created. So first thing that we will verify is nothing but the deployment. So cubectl get deploy. And here you can see the VP- demo is created for us. Next thing that we would be deploying is nothing but the VPA. So cubectl get VPA enter. And here you can see VPA - demo is created for us. And here you can see the mode is nothing but truly that is exactly what we have said right now. Let us verify the pods that has been associated with this deployment. So cubectl get ports and here uh if you remember we gave the label as app colon 25:38:28 u vp- demo right so I'll just write hyphen l for the labels and here I'll define the labels app equals to uh and here in the app I will write vpa - demo enter and here you can see the two pods are actually in front of us and both are actually running so here basically our application is running with two pods and VPA resource is now configured to manage manage those ports. So initially each container will request 100 mores of CPU and 50 MB of memory that we have defined in the manifest file. Now what exactly VPA will do? VPA will now start collecting and evaluating the resource uses. So this does not happen instantly. We need to give it some time to observe the workload and calculate its recommendation. So uh let us wait for some time because it should uh we should give some time for VPA to collect the metrics because based on that it will help us to take the recommendation right now uh let us inspect the VPA recommendation. So here it is the interesting part. So after we 25:39:30 allow few minutes of resource usages to be observed let us inspect the VPA configuration. How do we inspect that? So basically what we'll do we'll just write cubectl describe VPA and the name of the VPA is nothing but VP demo enter here just focus on this container recommendation section. So here you can see three values present in front of us lower bound kept target upper bound. So what are these? Let us discuss about this because this is the important thing that we are actually interested in right. So what are these values? So let us discuss on it. So VPA provides a target recommendation along with the lower and upper bounds. So that target is suggested resource request based on the usage it has been observed. The lower and the upper bond shows a range around that recommendation. So because our application is generating the CPU load. Now remember the command that we were running earlier, we may see a recommended CPU request higher than the 25:40:30 original 100 mill coursees. So earlier if you remember uh when we were defining the manifest file. So let me just do a cat on VP- app. Here you can see here we have defined the request as 100 m and memor and memory as 50 MB of storage. If you go over here the lower bound that it is suggesting is it should consume 198 m of CPU and 250 MB of storage. And the upper bound should be one core of CPU along with 500 MB of storage. That is exactly what it is trying to suggest. So the exact number depends upon the U resource usage and the cluster. So uh do not accept uh do not expect uh every environment to produce identical recommendation. This may differ from environment to environment. The main thing the key point over here is that the VPA is observe the VPA is observing the application behavior rather than it is relying on you know initial yes right so uh if you remember that we selected recreate mode. So now let us watch while 25:41:32 VP applies the recommendation. So let me just run let me just clear the screen and let me type cube cuttle get pods - watch. So here you can see the pods are actually running over here and here you can see this pod actually was changed to 118 second right because VP is using recreate mode it can evict a pod when its current resource request differs significantly from the recommendation. So here what deployment will do? deployment will create another replacement pod. Then VPS admission controller will apply the changes to the updated resource request to the new pod. And if you look at the container resource request section, this is where we verify the resource request assigned to the actual pod. So one important detail over here is a VP doesn't necessarily update the original resource value in the deployment template. It can apply the recommendation to the newly created pod through the admission controller. And that is the reason I 25:42:32 mentioned in the initial video itself. Uh there are three components in involved in a VPA that is recommener, updater and admission controller. So here if the recommendation isn't sufficient direct from the existing resource VPA may not recreate the port immediately give the system time to observe the workload and compare the recommendation with the actual pot resource. Right? So I think that was all and before we finish there are two modes I want you to remember let me just switch to my visual studio code so that you will get a clarity what I'm referring to. I'll scroll all the way to the bottom. Okay. So before we finish there are two modes I want you to remember. First is off. So in this mode VPA calculates the recommendation but it does not automatically apply them. Now if you remember initially when I was talking about uh VPA basically I told you based on the configuration it will apply the changes or it will recommend it right. So here basically it does not automatically apply the recommendation. This is useful when you want to inspect 25:43:32 the recommendation before making any sort of changes and the second is recre which we actually saw in this demo. So in this mode VPI can actually apply the changed resource request by recreating the pods whenever necessary. So if you want to study uh resource recommendation without automatically changing the workloads you can start with off uh and if you want to apply the resource changes uh using the pod recreation recreate is the available option that you can see. So uh that's the recap. So here let us understand about HPA. HPA changes the number of ports to respond the application demand and when it comes to VPA it recommends and change and it adjusts the CPU and memory request assigned to the port. Right? And that's it about vertical pod autoscaler. Here we learned about VPA. How does it observe the CPU and memory usage? It calculates the resource recommendations and can apply those recommendation to the ports. So remember HPA scales the number of ports. VP adjust the resource assigned to the port. So with these two concept we now understand the two main 25:44:34 important approaches to scale application in Kubernetes. So yes, that was all and I will see you in the next one. Thank you. Now imagine you're working in a company which has multiple departments. There is a dev department, there is an operations department, there is a devops department, right? And you are a administrator who is actually controlling all the access for all of them. Right? Now someone from the dev team comes and say hey I want the access to view the pods. So as an administrator will you give the entire cluster access to that developer? Well not because he will be able to delete the ports and who will be responsible for that? We need a mechanism in Kubernetes which will help us to defining the permission for a specific department for a specific group. So this is where role based access control arbback comes into the picture in Kubernetes. And in this video we are going to understand the same. Now what exactly is the purpose of rolebased access control basically here we will define the roles specifically scoped to that user scoped to that group scoped to 25:45:35 that service account. And that is exactly what we are going to learn today. Let's take an example that will help you to visualize archive. Let's say you are working in an office and as an regular employee you can take your workstation and you can work anywhere in the office but that does not necessarily mean that you can go to the server room and you can see the confidential data now remember one thing based on your roles and responsibility your access will be changed right likewise in Kubernetes let's say if a developer just want to view the pod here we can provide him that access but here we can also do additional thing that he should not be able to delete the parts he should not be able to see the password he should not able to see the secrets and that is exactly can be achieved with the help of arpac that is something that we call as role-based access control now I believe you have the clarity what does arpac does in cubernetes so before you begin with role-based access control there are three things that you have to keep in mind whenever you are assigning any sort of permission to a user right first is who need the access second is what sort 25:46:35 of permissions they required third is how will you connect them in this demonstration we will make use of service account for our identity We will define the rules into the roles and we will make use of role binding to connect both of them. Right now again if you have a very little amount of knowledge on service account don't worry we are going to cover that later in depth in the next video but for now put your complete focus into roles and role binding. Right? So let's get started on that note. Okay. So before even we start with the actual hands-on there are four important keywords four important concept that you should be aware of before you actually start with the hands-on for arbback right that is rule role binding cluster rule and cluster role binding these are the four keywords four important terms that you should be aware of what exactly it is and what it does right so what I'll do I'll just scroll a little bit over here by the way this documentation is already be pushed to GitHub repository feel free to check out the same the sub repository number 30 this This is where you find all the YML file or the documentation for this 25:47:35 specific section. Right? So let me scroll down and let us first discuss about role. Right? We understood the basic the base foundation. Now it is ready for us. Now let us do a deep dive into role. So first of all let us understand what exactly is a role. So a role defines that what actions are allowed on which Kubernetes resource within a specific name space. Now again whenever we are referring to role and role binding just keep your mind very clear that here we are referring to roles and role has a complete relation to do whatever sort of activities that you want to do within a nameace right here the keyword is namespace and you have to remember whenever we are talking about role and role bounding here we are talking in terms of name spaces right okay let's take an example so let's say we might need to create a role that allows someone to view the pod but we don't want that rule to allow them to delete the pod or to see the secrets. Right? So we explicitly will define which resource they can access by uh and 25:48:36 which actions they can perform on that pod. Right? So here if I put it into simpler terms, let us visualize this. So basically here we will define a role and that role will be able to do the operations in pod. Now here you can define that operation at a deployment level and also at pod level. For now just imagine we are keeping things at very basic so that you'll get an clarity what exactly arbback does. So here what we'll do let us imagine that we want to give someone the permission to view the part to watch the pod to list the part but we don't want that specific person that specific gentleman to view the secret or to delete the part right so what we can do we can define a rule where he is able to list the pod he's able to watch the part right but he is not able to delete the part or he is not able to view the secret so think of role as a permission document it defines what someone is allowed to do however Creating a role alone does not give person a permission or the identity to perform that sort of action. We need another object to connect the permission 25:49:36 to that identity. And this is where role binding comes into the picture. Right? So let us discuss about role binding. So what exactly is the role of role binding over here. So a role binding connects a role with an identity such as a user, it can be a group or it can be a service account. Right? So let's use our office example that we used initially. So here a role describes what sort of permission a employees requires right and role binding basically it assigns that permission to that specific person so that he can perform the appropriate action for that he is hired for right in Kubernetes role defines the permission and role binding actually assigns those permission to the specific identity here the important thing is role binding is namespace scooped right if we create a role binding in a namespace called let's say RBback-en demo the permission that it will grant will only apply to that specific name space right that's exactly what we are going to demonstrate today but before even that there is one more 25:50:38 clarity that we should be having over here is like see here we are talking about four terms rules uh rules role binding cluster rules and cluster role binding but what is the difference between a role and a cluster rule let us have a clarification on that right because uh before we start with the hands-on there are these two specific names that you should recog recognize every time that is uh nothing but cluster role and cluster role binding. So uh let's say uh rule defines the permission within a name space right it is namespace scoped. So a cluster role defines the reusable set of permission. It also defines the permission for cluster scoped resources and what are cluster scoped resources in this sense it is nothing but node right. So a role binding basically what it does it grants the permission within the name space. It can reference either the role in that name space or a cluster role. Now what exactly a cluster role binding does basically it will grant the permission across the cluster based on the permissions defined in the cluster role. So for our demo here we will be making 25:51:39 use of role and role binding. Here we will be granting the permission at namespace level because roles are very much specific to namespace scoped and cluster role and cluster role binding are specific to cluster scope. Right? That's the basic difference. If you want to understand this in detail here we have a dedicated charge that will give you a specific idea a complete idea what is object what are the definition what is the scope of that object. So here you can see a rule it defines the verbs on the resources. Now what are verbs over here? Now there are multiple operation that you can perform in any resource right such as you can list the pod you can delete the pod. But when we are defining a role here with the help of verbs we will tell that what sort of operation that specific role is supposed to do. Now when it comes to role binding here we are granting role or a cluster role uh to the user group or the service account. Third we have a cluster role. So here we are defining the verbs on the resources at cluster level. Now we already know what exactly verbs are. Verbs are the operation that one could 25:52:40 do on a specific service on a specific resource. Now it can be a name space. It can be a node. Now based on your use case you will define a role or you can define a cluster role. Now likewise we have cluster role binding here. It will grant cluster roles to the users to the group or to the service account. That's the basic difference and I hope you have the complete clarity on what exactly each one of these does. Right? Okay. Now, uh it's time to do the hands-on because now we have the clarity on all these four important objects, all these four important keywords that we will be using throughout the video. This specific section is dedicated to roles and role binding. Why? Because it will give a complete idea, a complete visualization how does things are working. Right? So now let me switch to my terminal. And now let's actually start with the hands-on. So yeah for this specific demonstration what we are going to do is we are again going to create a new profile. Why new profile? This will give a complete new environment so that we can understand what exactly is happening over here. Right? Again if you wish to continue with the previous environment feel free 25:53:41 to do the same. This is an optional step that is supposed to be done. For our demonstration let us create a new profile in mini cube. So how do we create a new profile? Basically we will just write mini cube start mini cube start and here we will define the name of the profile that we want to create. So hyphen - profile what is the name of the profile? It is rback rolebased access control demo and then we will need to define the driver through which it will create the profile. So hyphen driver equals to in our case the driver is nothing but docker enter. Now here what mini cube will do it will create a fresh new profile so that all the operation that we are going to do over here will be dedicated to this specific profile. So here we are defining the context. On the context is defined we'll switch to that context and then we are good to start with today's demonstration. So let us give some time for mini cube to start and create this profile. Once the profile is created then we should be good with that. 25:54:48 Okay, so the profile is created. Now let us switch to the context by typing cube cuttle config get- context. Context name is basically here we define arbback demo. So the context name is arbback demo. Enter. Here it says unknown command get context is there is an error. Oh sorry. So instead of get context it is use context. So use context. Enter. Now here it says switch to the context named arbback demo. That is exactly what we created. Clearing the screen. Now once the context is clear uh now once the context is clear it. Now once the context is created let us verify the cluster node. So for that just drive cube cuttle get nodes enter. And here you can see arbback demo is ready. And here it is nothing but a control plane. Now since we are using mini cube here it will act both as a control plane and a worker node. Okay. Now for performing today's demonstration we will make use of namespace. Now what exactly is a namespace? Namespace is something that 25:55:50 will give complete isolation to the resource. Now if I put it into simpler terms just imagine that you are in an office and in an office there are multiple cubicles multiple departments. So HR department sits in a specific row, development team sits in a specific row and devops team sits in a specific row. Likewise in Kubernetes you can create the departments do compartments and that is something what we call as a namespace. If you want to learn more about namespace there is a dedicated section which you can follow along which we actually covered in the initial level itself. Now let us create a name space for this specific demonstration. So how do we create it? Basically two methods. You can create one file for the name space itself or you can go with the command line method. This time we are going to go with the command line method. Clearing the screen. So just write cubectl create namespace name space name. So rback demo this is the namespace that we are supposed to create. Enter. And here you can see the namespace is created. How do you list a namespace? Just write cubectl get namespace or ns. Here you can see rback demo is created over here. Now 25:56:52 when we are dealing with namespace in terms of role basically role works at namespace level. That is the reason why we created a namespace. Right now the basic thing is ready. We have created a namespace called arbback demo. And this name space will help us to organize the Kubernetes resource. Also it is very much important for restricting the permission that we are going to demonstrate today. Now our setup is ready. Now we can start with rolebased access control demonstration. For this specific demonstration we will need to create four resources. First will be the service account. Now here service account represent our identity. Second, we will create a service called pod. Now that pod will be something that we would be performing the operations. Now remember earlier I mentioned about a term called verb. Right? Now in order to perform any sort of action in that specific resource, we need to have one resource itself. Right? So here we are going to create a pod in which we are going to try the operations and we are going to access it after the rules and role binding implementation. Third, we will create a role that will help us in uh defining the allowed actions that we 25:57:53 are supposed to do in that specific resource. And finally we will create a role binding that will actually connect the identity to the role. Let us create each resource one by one. Now again you can create a single YAML for each one of them or you can create individual YAML files too. For this demonstration let us keep things very much simpler because if you create uh if you create the YAML file at once it might create confusion and we don't want to keep any space for the confusion. Let's create four individual YAML files that will help us to understand our back in detail. So let us create the service account first. So uh again when we are talking about service account it is again a resource in Kubernetes. So let me just type brim sa.l enter. Now what are the four keywords that you need to remember API version kind metadata inspect. Now here when we are talking about service account here just three keywords will be implemented API version kind and metadata. And inside the metadata there is an important thing that you need to mention what exactly it is. Remember when we set when we were setting up the environment at that time we defined a 25:58:53 name space. So don't forget to mention the name space in all the resources that we are going to learn that we are going to create today. Okay. So let us create the service account now. So API version kind now kind is service account meta data and we don't need spec uh and we don't need spec over here. And we know need spec over here right but what exactly is the API version for service account okay you can go to Google chrome you can go to chat JPT you can go through any model but we will go to the command line itself escape wq cubectl api- resources and we'll do a grab on service account enter uh Okay, I think there is a spelling mistake. Let me correct the spelling mistake over here. It is resources. Enter. And here you can see the API 25:59:55 version for service account is nothing but v1. Let me copy it. I'll go inside my manifest file and I will update the value accordingly. And here the API version for service account is nothing but uh v1. Now in the metadata I am defining the name for that service account. So what should be that service account called? Now here we will name it as pod reader because here we will be granting it the permission here we will be performing the operation the verb operation at pod level. So I'll just name it as pod reader. Then the important segment here that is nothing but namespace. You need to define the name space that you have created. So name space colon. Now what is the name space that we created? We created rback demo escape wq. Let me verify the name space first. Clearing the screen. cubectl get NS and yeah this is the exact name space that we have created and just note it somewhere this is something that we will be utilizing in all the manifest that we are going to create today okay arbback demo is the some arbback demo is 26:00:56 the name space that we have created let me do a cat on s.ml and here is our service account is created where we explicitly define the name space in front of us let me tell you everything from starting so in this service account yl uh there are only few five lines that actually define the entire resource over here. So let us go through it line by line. So first is API version. Here API version v1 what exactly tells it tells Kubernetes that we are trying to use the core API version. Then we are defining kind. So here kind that is service account. It tells Kubernetes what sort of resource we are trying to create. So here we are trying to create a service account. Next we have the metadata and in that metadata we have given a name. The name of that service account is nothing but pod reader. So here it is in reference to the kind that we have created. Lastly, we have namespace. Here we have defined the name space that we have created. That is nothing but rback demo. For now, think of service account as the identity that will receive our permissions. And creating it does not automatically mean that we are allowing the access to the pods or secrets. Here 26:01:58 we will grant the permissions separately. Right? So the service account is created. Now let us create the resource that is nothing but pod. So clearing the screen and now let me just create the pod. to vim s- pod dot yamel again now whenever we are creating any sort of manifest in kubernetes what are the four three words API version kind metadata inspect let us define the same API version kind metadata and here goes the spec okay now what exactly we are trying to create we are trying to create a pod now what is the API version for pod now since we have been doing from so long we know that the API version for pod sv1. I don't want you to believe on me. I want you to check it yourself. So escape wq just write cubectl api- resources and do a grab on pod. Enter. And here you can see the API version for pod is nothing but v1. Hence proved. Let me go back to my uh manifest file. Here we 26:02:58 have defined the API version. Here we have defined the kind. And now here it's time to name that pod. Now what can be the name of that pod? Here you can give the name to this pod anything. I will uh give it as demo pod. Now here in the metadata itself one more important entity which you should not forget that is nothing but name space. So name space arbback demo. So this is the name space that we have created. Now again when you are creating a pod what sort of thing you are running inside a pod? We are running an application and that application is run with the help of containers. Right. Here we will define the settings, the configuration for the pod and here we will define the container specification. So containers. Now again here we will give the specification for the container. First thing that we will define over here is the name of the container. So name name of the container can be anything. For now I'll just give it as app. Now next thing that you need to give is yeah I forgot one dash. Okay. Now next thing that you need to do is you need to 26:03:59 provide the image name. So I'll just write busy box. It is a lightweight uh Linux image. Thirdly is once the pod is created. Thirdly is once the container is created I want few sets of command that it should run. And what are those command? Basically first thing that I want to do is I want it to start the shell. So /bin/s. Second I need to uh uh you know I want to execute the command that follows after this line that is nothing but we want to keep this container alike for 1 hour. So what I will do hyphen C and here I will just type slave 43 6000 escape colon wq and that's it we are done clearing the screen and let me just apply the file Q cuttle apply - f senp.ml here the pod is created let me just do a cat on sa sa- pod.mml and let me explain it to you line by line so here what exactly we are doing we are creating a simple pod by the name demo pod and here in The specification we have defined the specification for the container and here 26:05:00 we are telling that we are making use of busy box image. So here we are telling that we are going to make use of busy box image and there is a small container image that we want to make use of for the demonstration and here in that we are going to run few commands. Now this command is basically used for running the container for 1 hour. So here the pod is a sample resource. Here we will use it to check whether our identity has the permission to view the pods and then we'll test the identity permission separately. Now we have defined the service account. We have defined the pods. Now let us define the role itself. So here let me clear the screen and before even that let us verify whether the pod actually created or not. Cube ctl get pods. Oh here you can see there is no resource present. But why? Remember that important keyword we have created that pod inside a dedicated namespace. And what is the dedicated namespace name? It is nothing but rbback demo. So cube puddle get pods in the name space rback demo. Enter. And here you can see the demo pod 26:06:01 is up and running. Right now again whenever you are validating any sort of resource make sure that you make sure that you're making use of namespace RPG demo because that is the exact place where you will find all the employees of your department. Clearing the screen. Now let us define the role for this specific resource. So whim ro.ml again whenever we are creating any sort of resource four keywords API version kind metadata inspect. But here in this case we will just define three keywords API version kind and metadata. And inside that metadata editor we will define the rules the verbs that we were talking about right because here we are defining the definition of the rpack. So again let me define the same API version which we don't know what exactly is right now here we know the here we are only aware of one thing that is nothing but kind. What is the kind? K kind is nothing but role. Okay next is we have metadata. Okay. And that's the basic template that we have created. Now, now first thing that we need to identify what is the API version for RO. Okay, we'll just go to 26:07:02 cube cuttle API resource and let me press escape colon wq. I will type cubectl API resources and here I'll do a grap on roll. When I do a grab on roll here I'll get the API version for roles. And here you can see let me just copy it entirely. Don't worry I'll explain you each and everything line by line. So just follow along this thing. Once the manifest is created, I will explain you each and everything line by line and that's a promise from my end. Okay, clearing this screen and I'll go to my role manifest. Again, first thing that I will be updating over here is nothing but the API version. API version for role is arbback.authorization.k.io/v1 which we don't have to memorize because this is something that we will get from our best friend that is API resource. Okay. Now let us give the name to this role because that is exactly very important when we are creating role binding and when we are defining the permission. So here I'll just write pod uh reader and since we are defining the 26:08:04 role I'll just give it the name as role. Second most important thing that you should not forget we should not ignore that is nothing but the name space nameace. Now why we are focusing too much on namespace? Because from the definition itself it is very much clear that roles and role binding are namespace scope. That's the reason we are putting so much of focus into namespace. What is the namespace name? Arbback demo. Okay namespace is defined. Now what? Now namespace is defined. Now what next? We need to define the rules. Rules for basically here we are defining the rules that should be done on that specific resource. Right? So first of all let me just define the rules. Now again when we are defining the rules we need to define the API group right. So here I'll just write API group. Now in that API group what will I define? First thing I will just write an empty quote over here. It is not API group. It is API groups. Okay. Next is now what exactly API groups define over here. It refers to 26:09:05 core Kubernetes API group. Second is we need to define the resource on which the permission should be applied. Right? So here I'll just write a resource. Now inside this resource we will define the permission that will be applied. Now since here we are performing the operation on pod. Inside the resource I define the I will define the pods over here. Right? So here I will just define the pod over here. Here it is in lower case and here it's pods with s. Next thing that we need to define is the verbs. Basically here we will define the rules basically what sort of operation can be done can be performed on that specific resource that we are trying to create. So basically here we should allow that he should list it he should watch it and he should view it right but he should not be able to view the secret he should not be able to delete this resource that is something that we will be defining over here. So here I will define the verbs. Verbs basically is what basically the action that will be performed over here. So here let me just define the actions. 26:10:06 First thing that he or she should be able to do is he should be able to list it, get it, list it and after that he should be able to watch it wh escape colon wq. Now the role manifest is ready. Let me just apply the file first. Cube cuttle apply f ro.ml here we are getting an error. Here it says cannot be handled as rules. Stick decoding error. Unknown field rules dotresource. Okay, it should not be rules dot resource. It should be resources. Insert mode. I'll just type an s escape colq. Applying the file again. This time the role for the body is created. Clearing the screen. Let me just explain you the file line by line. Roll. Okay, just focus on this because this is the highlight of today's video because this is actually the place where we have defined what sort of operation can be performed on the resource that we have 26:11:07 created and here that that and here the resource that we have created is nothing but the pod. Okay, let us start from the starting. So here we are trying to create a role right. So here you can see the API version is very different from the ones that we have been doing so far. It was app/v1, it was v1, here it is something different. So what exactly this API version is telling here the API version is different because the resource here is a arbback resource. Second here we have the kind here we are telling Kubernetes that here we are trying to create a resource type roles that defines the permission. Then here the name of that role is nothing but pod reader role and it should fall in the name space called rbback demo. That is the basic thing that we have defined. Now here comes the important section that is rules right because in the rules we have defined the verbs the action that should be performed inside it. So rules is where we define what actions are allowed. So the first thing that we have defined in the rules is nothing but API groups. Here you can see the empty string right that empty string means that it is the core Kubernetes API group 26:12:08 which includes the resource such as pods or secrets. Now next thing that we have defined is the resource and in the resource we have defined pods. So this tells Kubernetes that our permission applies to the parts. And finally the most important section of this entire manifest is nothing but verbs. So verbs basically what sort of actions has been allowed over here. Here verbs are the action that can be performed by a person by an identity. So we are allowing three actions over here. So let us retrive an individual pod. Second let us list all the pods. Third, let us observe the pod changes. So that's all what exactly this role manifest is doing. It does not grant permission to delete the part. It does not grant the permission to read the secret. We deliberately have kept this permission very much limited and that is something that we would be validating at the very end. Now we have the service account, we have the roles in place. Now it's finally the time to define the role binding. Okay, let us create the role binding. Now clearing the screen whim ra a - binding 26:13:10 dot camel enter. Now again four keywords API version, kind, metadata and spec. Now here we are defining the rules. So only three keywords are applicable API version, kind and metadata. Let us define the same over here. So insert mode API version. We don't know what is the API version for role binding kind. Now what exactly the resource we are trying to create? We are trying to create a role binding. So role binding. Make sure the initials of each word is in upper case that is from role R is in upper case from binding B is in upper case. There shouldn't be any space in between them. Next is metadata. Now what should be the name of this role binding? Let us give a good name to it. So here we are going to perform the operation on the resource called pod. So what I will do? I will just name it as pod reader binding. Okay. This is the name of the role uh this is the name of the role binder that we are giving. Then again in which name space it will fall. Basically name space is nothing but arbback demo. Okay. Initial template is 26:14:12 ready. Now let us define the subject uh who will receive the permission for this. So here if you remember we created the service account at the very initial. So here we will define the subject for it. So subjects. Now what are the subjects in this case? Basically here we will need to define the client for it and it is nothing but service accounts. Make sure the initial for service account is also in upper case. And now let us define the next level of information that is nothing but the name of the service account. What is the name of service account? Let me just verify the same. And let me just write cubectl get service account. Okay. Here you can see only default is present. Maybe we haven't applied it. So cube kit apply fa.l service account is created. Then let me get the name of the service account. in the name space arbback - demo. Okay, here the name of the uh service account is nothing but pod hyphen reader. Okay, 26:15:14 let me go back to my binding manifest and here I will define insert mode the name of my service account that is nothing but pod hyphen reader. Make sure that you are using the exact value because if that is mismatched then you won't get the appropriate result. So just focus on the correct name don't make it very much complex make things very much simpler right now the last thing that we need to verify is the place where we got confused that is nothing but the important keyword from the starting of this video I am telling that is nothing but namespace so here just define the name space where the subject has been present name space arvback demo okay now the subject is created now let us provide the reference for the role binding where it will be granting the permission So here let me just write role ref and inside the role reference let us define let us share the API version let us share the kind and let us share the name of the role that we have created where do we get it from escape wq clear 26:16:15 the screen and do a cat on ro file that we have created and copy the initials till the name now go back to array - binding and here in the role reference paste all the items that you have copied. Okay. Now here in the ro uh now here in the role reference just give some indentation because ZAML is very stick with the indentation. Ess let me just fix it again. In the role reference I'll just paste it and here let me just give the spaces over here. API version we need kind we don't need metadata. So here I'll delete it. So let me just delete metadata over here. And here we have defined the name of the role that we have created. Escape colon wq. The role binding is also created. Now let me clear the screen. cubectl apply - half and ra - binding. That's the name of the manifest we have created. Here we are getting an error. Let us validate. Let us validate the 26:17:15 same error validating rabbinding. And here it's saying API version is not set. If you choose to ignore this error, turn the validation off with validate equal to false. Let me just do a cat on rabbinding. Okay, here we forgot to write the API version. So that is something uh because of that we are getting that error. Let us write the API version for role binding. How do we get the API version for role binding? Clear the screen. Just write cubectl API resources. Do a grab on ro binding. Enter. And here you can see for role binding this is the API version which was same as that of roles. I will again go to my manifest file. And here I will update my API version. Then things should be good and life will be easy. Escape WQ applying the file again. Cubectl apply - f api- resources uh sorry apply fra 26:18:17 binding. And here we are getting another error. Here it says rule binding version cannot be handled as rule binding stick decoding error and here it says unknown field API version rule reference API version. Let me just fix that too. Okay, so here in ro reference uh here it says API version. Okay, here this is not API version. This should be API groups colon. Let me just go to insert mode. Okay. And now in the insert mode, I'll just define this as group colon and one single space escape colq. Let me apply the file again. Now again we are getting one more error. Rule binding pod reader binding is invalid. Role dot reference API group unsupported value. RPA authorization supported value is rback authorization k.io. Now let us validate this same as well. Let me just do a vim over here. Here it 26:19:18 says API group. Okay, here I think we don't need to share vub1. And I'll share you why that uh and I'll share you why that and I'll share you why exactly we're removing / v1 from here. Escape wq from the error itself. It is saying that the supported value is arbback.authorization.ks.io. We don't need to provide /v1. That's the reason we just removed it. Applying the manifest file again and this time finally the role binding is created. Clearing the screen. Now let us validate the same uh where the role binding is whether the role binding is present or not. So cube cuttle get role binding in the name space are back demo enter. This should be cubectl. Enter. And here you can see pod reader binding is present in front of us. Let me just explain you the entire manifest file for role binding that we have created because that is again important thing that you should be clear about. 26:20:19 Okay, let us start from the starting itself. Here we are trying to create a rule binding. Here we have defined the API version as arbback.auorization.k.io/v1 which is exactly same as rules. Here we are telling Kubernetes that we are trying to create a resource name role binding. In the metadata we have given the name of the role binding as porder reader binding and then we have defined the name space because role binding is name space scoped and then here we have defined this subject. So basically this subject section tells kubernetes who should receive the permission. Here in our case the subject is nothing but a service account. Right? We have defined the name of the service account. We have also provide the name space where the service account falls. Right? Now we are selecting the identity we created uh at the beginning. Now finally in the role reference we have defined. So here in the role reference we are telling Kubernetes which role to grant right. So role name is pod reader role and then this connects the role binding to the role that we have created earlier. So here the relationship looks like that we 26:21:21 have a service account that is the identity. Here is the role that defines the permission. Here we have the role binding that connects both of these two. So that's the heart of our back. Now we have applied the manifest file. We have verified each individual resource. Now our resource is created. Now the final thing that is pending over here is to test the resource. Are able to view the parts or whether we are able to delete the parts based on the role definition. We should be able to view the post. We should be able to list the part. We should be able to watch the pod. But we should not be able to view the secret. We should not be able to delete the part. Those are all the things that we need to verify. So here in order to test the permission we need to make use of a very wonderful utility in cubernetes that is nothing but cube cutle or can I basically it is very simple to understand o can I basically here we are asking cubernetes with the help of cube cuttle that can I view this resource can I list this resource so that is exactly we can perform over here with the help of this wonderful cubernetes command. So here we are going to ask cubernetes with 26:22:22 the help of cube cutle can I that is this identity allowed to perform this action. Second things we are going to make use of hyphen apps because here we are making use of a service account. So here we are going to check the uh permissions in uh with terms of service account. Thirdly for mini cube demonstration we are using the cluster administrator context. So the current identity which is permitted uh will be impersonate to the service account that we have created. Right? So let us run this o can I command which will give us the clarity. So how do we do it? Clearing the screen. So just write cube cuttle o can hyphen i can hyphen i list pods. Basically it is very simple to understand. Here we are saying cube cuddle uh whether I will be able to list the ports. Now again here where exactly that pod is present that pod is present in the name space rback 26:23:25 demo rbc demo and then last thing that you need to define is - s. Now what exactly this keyword denotes here? Basically we are telling that we are impersonating as a service account right. So here you need to define that value too. So here just write system colon. Next thing that you need to define is the service service account. And let me just correct the spelling account. And here in this service account we are referring to. 26:24:02 So here in the service account we are referring to our backy demo because that is the name space where the service account is lying. And lastly, what is the name of the service account? Name of the service account is nothing but name of the service account is nothing but pod- name. Name of the service account is nothing but pod- reader. Reader enter. And here you can see it replied us with the answer yes. Here basically we are just asking a query whether we are able to list down the pods which is present in the service account. That service account falls into the name space called arbback demo. And the name of the service account is nothing but pod-reader. So here it replied us with the answer that yes you are able to perform that action. Right now why we are getting yes because in the manifest file we have defined the rules and that role defines that we should be able to list the pods which is present in this name space. That's the reason we were mentioning from the starting itself that rule defines the definitions and role binding clubs them. And lastly both of 26:25:04 them are namespace code. That's the reason name space is something that we are highlighting every time. Now let us perform another operation. Now instead of asking whether can I list the pod here we'll just write can I delete the ports. Enter. Here it says no. Why? Because in the manifest file of uh rule we haven't mentioned that the person should be able to delete the uh part right. So here a rule does not include the delete action. So having the permission to view the pod does not necessarily mean that you should be able to delete them. Right? Now let us try to ask Kubernetes whether are we able to uh view the secrets. So let me just rerun the same command here. The only thing that I will change is instead of delete pods I will just write can I get these secrets because that is something that we would be using for listing the secret. Secret again no. Why? because uh the rule grants uh the access only to the pods. We haven't granted the access to the secrets which may contain the sensitive 26:26:06 information such as passwords, such as tokens, such as API keys. Now let us test one more thing that is the highlight over here that can I list the part from another name because right now we are listing all the things which are present in the current name space but will I be able to list the resources in another namespace? Right now we have allowed the permission for listing the pods in the current name space. Right? That is nothing but rback demo. But are we able to list the pods in another name space? Let us test the same. So cube cuttle o can I list pods in the default name space. Enter. Here it says no. Why? Because the identity cannot list the paused in the default name space through the role binding that we have created. That's because our role binding is in arbback demo. So the permission granted by this binding applies within that name space and that name space is nothing but 26:27:07 arbback demo. So let us bring everything together. Let me switch to my visual studio code. Okay. So I'll scroll all the way to the bottom. Okay, so let us take a summary whatever we have learned so far. So let's bring everything together. We created a service account to represent the identity. Then we created a role that defined the allowed action. We created a role binding to connect the identity to the role. And then we tested the permission with the command called cube cut o can I. And then uh we verified the result that we wanted and now we can actually view the pods in the targeted name space that is nothing but rbback demo. That is the basic idea of arbback that is nothing but role based access control. Before we close, there are three things that I want you to remember. First is a role defines the permission but it does not assigns them to an identity by itself. Second is we need a role binding that defines uh a role permission to the identity within the name space. That is we should follow 26:28:08 the principle of list privilege. So let us recap everything. RBback stands for rolebased access control. Second is a role defines the permission within the name space. The role binding connects those permission to the user to the groups to the service account. Here we saw with the help of service account cluster role defines the reusable permission at cluster level. Cluster role binding can grant the permission at cluster level. Then the most important thing that we should remember is back basically control what sort of permission to be given to which sort of individual and instead of giving admin access to everyone we can just define the scope with the help of roles. So that only the required permission are needed to that specific user that specific identity and that is exactly what we call as arpac. So that's it for today's video where we learn about rolebased access control. In the next video we are going to do a deep dive into service account. So stay tuned for that. Till then keep learning and thank you very much. Today we are going to learn about service account. In the previous video of arbback we already have covered essay but today we are going to do a deep dive 26:29:08 on it. So now let us take an example. Let's say there is an application that collects metrics of the pods inside your Kubernetes cluster. But here the question is how does the Kubernetes identifies this application and how does Kubernetes know what sort of action it is allowed to do inside that cluster. This is exactly where service account comes into the picture. In this video we are going to start with the default service account. We are going to see how does token works. We are going to create our own service account and then we are going to map it with the pod. So that is how we are going to get the clarity what exactly service account is and what exactly it is supposed to do. Now let us discuss what exactly is a service account. For that let us discuss about two sort of identities that Kubernetes offer. First is the normal user and second is the service account. What do I mean by normal user? Normal user as in it can be your developer, it can be the administrator. Service account basically it is a sort of identities that has been provided to your application to the running process inside the pod. Now let us take an example that will actually make things very much clear when it 26:30:06 comes to service account. Let's say that you have developed an application. It is a monitoring application that tries to fetch the logs of the pod and it will give you the visualization that your pods are actually running healthy. For that it will send the request to the Kubernetes API server. Now when the request from your application goes to the Kubernetes API server, first thing that it will check is the identity. It will first recognize it. That recognition is been provided to your pod by the service account because at the end back end it is the pod and at the same time that recognition that identity is been provided by service account itself. Right? But when I say it is identifying it does that automatically mean that will it be able to perform any sort of action in the cluster? Well definitely no because here we are talking about two separate concepts identification and authorization. Right? So identification has been done by service account. Authorization basically what sort of operation it will allow to do inside that cluster that thing will be taken by the arbback itself right so here there are two concept identification has been provided by the 26:31:08 service account and authorization is been performed by the rolebased access control so when they both together work this is how we will be able to make sure that this sort of application is actually able to do or perform this sort of action in the actual cluster yes now I believe you have the base for service account so now let's just do the hands-on Now, so before creating the service account, let us create a very basic pod and let us see what does Kubernetes does automatically. So here we are going to create a pod by the name let's say my pod and here we are going to create it with the help of imperative method. Now you are already aware that there are two methods to create any sort of resource in Kubernetes that is imperative method and second is with the YAML manifest. So here we are going to do it with the imperative method. So let me just create a pod by the image engineext. So here I will just write cubectl run and here I will uh write the name of the pod that is my pod and here I will pass the image and what image should we use. We will make use of our favorite image that is engineext enter. Here you can see my pod is created. Now let me 26:32:09 just list it cubectl get pods and here you can see my pod is actually up and running. Now you can see the application is actually running. Now let us inspect it. How do we inspect any sort of resource in Kubernetes? We will make use of describe over here. So I'll write cubectl describe pod followed by the name of the pod that is my pod. Enter. Now here there are two values that you have to see. First is if you scroll up here you will find the service account. Now if you if you remember right now we didn't even created any sort of service account right we just created one resource and that resource is nothing but a pod. But here you can see we have a service account which is saying that it is a default service account that we are creating. Now why does it say default? Because we didn't specify a custom service account when we are creating the pod. So whenever we create a pod without specifying a service account, Kubernetes normally assigns a default service account from that nameace. So this isn't limited to the default namespace. Every 26:33:11 namespace has its own default service account. So we can also verify the same. But again there is one more thing that I want you to check that is this mount path. Now what is this mount path consisting of? This mount path consist of the token through which the authentication happens. Let me just clear the screen now. And here let us verify all the service account which are present in the name space. So for that I will just write cubectl get service account - a so that it will print all the service account which are present throughout the cluster. Now here you can see we have a default service account for cube node list there is again a default service account present. So these are all the service account that we can see over here. Now here if you remember I typed SA right in the command you can see I just typed SA. SA is a short abbreviation for service account right. So uh and hyphen a basically here it means that we want to inspect all the namespace right. So if you look at the output you will see service account listed along with the respective name 26:34:12 space and you'll notice that uh the different namespace have their different default service account right. So remember if you do not specify service account in the pod configuration Kubernetes will normally use the default one that is present in the name space. Now let us understand how Kubernetes makes the service account token available to the pod. Now here if you remember earlier when I described the pod I told you about a mouth part right here is something that we are going to see now. Now we have seen Kubernetes assigned the default service account to the pod but how can an application use that identity when it needs to communicate with the Kubernetes API server. Right? So for that Kubernetes can provide a service account token to that specific pod. So let us go inside the pod that we have created by running the command cube cuttle exact and then we are going to actually see what exactly is present inside that pod. So let us go inside that pod. Let me first copy the part that we just described. Clearing the screen and let me just describe the pod once again. And here I 26:35:14 am searching this mount path. Okay. And I'll copy it till here. Okay. Done. Clearing the screen. Now let us go inside the port. How do we go inside the pod? We will make use of cube cut exact right. So here I will write cubectdl exac. I want to have an interactive terminal that's why hyphen it here I will pass the name of the pod that is uh my pod and then finally I will pass sh because we want to go inside the shell. Enter. Now here you can see this changed to hash meaning we are inside the pod. Now the next thing that we need to do is we need to see what exactly is present inside the mount path that directory that was mentioned in the describe right. So now what I will do I will just do a cd and I will paste that uh path that we have copied. I'm pasting it. Okay we are not able to see that. No worries we are going to type it once again. So I will just write let me just get the path once again. Let me just exit over here first. Uh I'll just do a describe again. And here it is storing 26:36:15 that variable in here it is storing that value in where/unces kubernetes.io service account. I will copy this once again. Now clearing the screen. I'll go inside my pod once again. Now here I will go inside that pod. Let me just paste the value. And here is the path that we just copied from the mount when we just described the pod. Right? So the path over here is /ware/run/ secret/cubernetes.io/service io/service account. So if you remember we didn't specify service account when we were creating the resource. We just said hey Kubernetes we need to run a pod and the image should be engineext and give the name of that pod as my pod. That's it. That's the thing that we just defined. Now here we are getting that path. Now what exactly is present inside that path? Let us check. Now when I go inside that pod, I will just run a list command. Here you can see there are three files which are present. CA do.Rert ert name space and third is token. Let us understand what these files are used for. So ca dosert let me 26:37:17 just do a cat on ca crt. Enter. Now here you can see it is a certificate. So ca do.ert contains a certificate information which is used to verify the cubernetes API server. Second what exactly we have? Namespace. Now again in which namespace we have created this resource. Now since we haven't defined any namespace, it will go to the default name space. Let me do a cat on name space also. Name space. Enter. Here you can see the name space that it is displaying in front of us is nothing but default name space. So here name space contain the name space associated to that part. Now here the last thing that we have present over here is token. Let me just clear the screen first and do a cat on token. Enter. Now here we have this token. What exactly this token consists? Though this token contains the service account token that can be used to authenticate to the Kubernetes API server. Exact detail may vary based on the Kubernetes configuration but this is a very typical location used for automatically mounting 26:38:17 the service account credential. So now you might be wondering with this information what does this token contain. So let us now understand what sort of information this token carries right. So a service account token is a credential that an application used to authenticate to the Kubernetes API server. Many modern Kubernetes token are formatted with JWTs which stand for JSON web tokens. A JSON web token consists the information that can be decoded to inspect its claim. So for example depending upon the token and the Kubernetes version that you are using the claim can include the information such as the service account its name space its validity period and sometimes the port to which this token is bound to right. So there is also one more very important thing to remember that decoding a token is not same as verifying the token is valid. Also JWT token are not necessarily encrypted. So you should actually pay some attention to it and you should treat the entire token as a sensitive credential. So now 26:39:17 what we are going to do we'll just copy this entire token and we are going to decrypt it. Now why as I mentioned it is a sensitive information but we need to verify what sort of information it may consist right but again uh on a side note please do not perform this sort of action on your production cluster on your staging cluster and also replaying using it on the live environments because this is just for studying what exactly this value can stop right let me just copy this entirely and here let me switch to my browser now okay now I am on my Chrome browser and here I am in the website JW wt.io that website which will decode the token that we have copied right so here basically this is just specific for learning purpose to understand what exactly are the values that that token may carry right please refrain using that I'm saying it once again okay so now for the learning purpose let me just delete the existing value which is present on the website and let me paste the token that we have copied now here you can see decoded header started to load let us wait for some time and let us observe 26:40:18 what sort of values it may show us right but For our demonstration, this consist of some sensitive information. Right? So the important takeaway from this is that Kubernetes will provide you the token so that the application can prove its identity for communicating with the API server. Right? Now let us wait for some time and here you can see the actual value is coming down. Now what sort of now what sort of value does it contains? So if you scroll down after the decode there are few information that you can see. First is the name space. The name space that it is using is default. Now what sort of node you are using? We are using mini cube cluster. That is something that we are getting over here. What's the name of the pod? We are getting my pod. That's the exact same thing that we used. And again service account. We are using a default service account. That also is the information that we can find over here. That is something that you can see into jwt.io. And again please refrain using this in your office environment. This is just for learning purpose. If you are learning, if you're doing it in your own environment, in your own setup, feel free explore the same verify the values 26:41:19 and you will get the confidence of the concept. Now let us go back to the terminal. Since we verified what sort of values does that token contain, let us go outside from that part. So for that, let me just type exit and we should be outside from our port. Clearing the screen. So here we verified what sort of information does a default uh pod contains and again we didn't even mention uh what sort of service account we would be using. Here we came to a conclusion that whenever you don't specify any sort of service account while creation of the resource it will give it a default uh service account. Right now suppose we have an application that does not need to communicate with the Kubernetes API server. So do we need to make a service account token available to that application? Not exactly. So Kubernetes allow us to disable automatic service account token mounting. Now how can we do that? It is again very simple. So for that we need to create a source. For that let me just delete the current resource that is currently present. So cube cut get pods. Here I will delete uh my pod which is currently running. Cube cuttle delete 26:42:21 pod my pod. And now we are going to create a new pod with the help of the manifest. Now clearing the screen whim my pod doml. Now again whenever we are creating any sort of resource in Kubernetes what are the four keywords API version kind metadata and spec let us define the same API version kind metadata and here we have spec now again uh what now again what sort of resource we are trying to create here we are trying to create a pod now again in the API version what's the API version for uh this specific resource API version for this resource is nothing but v1 right now again metadata what should be what Should we call this uh pod right after it is created? So we will call it as my pod. The same name which we have given earlier. Now again in the specification in the specification it will contain the settings for that specific resource. Now here when we talk about that resource we are talking about pod. Now here inside a pod what exactly runs a container. Here we will define the settings the 26:43:21 configuration for uh the pod that we have creating and the name of that pod is nothing but my pod. So here I will define containers and here in the containers I will need to define the name name of that container we can write anything. So for now I will just give it as engineext or you can also give it the name as uh app. Now again through which image the container will be running here I will just type engineextable stable engine stable. So this will be the image that we would be utilizing. Now again we were actually verifying if we don't want to create the service account for this specific one. We don't want the service account token to be created for this specific resource. How do we do that? So for that you just need to define one more keyword over here and that is nothing but automount service account token. It should be false. So let me just define the same automount service account token and this should be marked as false. Now when you define this keyword when 26:44:21 you define this keyword basically this is an important line because this will tell Kubernetes to not automatically mount the service account token to this specific part. So here if you notice that we haven't specified the custom service account. So Kubernetes will normally associate it with the uh default service account that comes along with the name space. So however token mounting is disabled in this case. Right? So let us go outside this manifest file and let us apply the file now. cube cuttle apply - f my pod.l L enter my pod is created. Now let us verify it and let us do a describe for the same cubectl get pods. Okay, the pod is running cubectl describe the pod my pod and when I press enter the first thing that we will check is now see again here we haven't defined the service account here it is taking the default service account which is present in the name space. Second thing that we need to verify over here is the mount. Now here you can see the mount as none. Earlier if you remember when we copied that token and we pasted into 26:45:22 jwt.io IO we were able to get tons of information but since for this specific source we didn't want to get the token we defined in the manifest file itself that we don't want that token that's the reason we are getting mounts as none right so you should still see the service account associated with the pod but the automatically mounted service account token should be false over here right this demonstrate an important difference that a pod can have a service account assigned without automatically receiving a mounted token so this setting is useful when we want an application to not to connect with the Kubernetes API access. Now we understand the default behavior. Now let us create our own service account. Let me first clear the screen clear. Okay. Now let us clean the environment for our demonstration. So for that what I will do? I will just clean the I will just delete the pod which is currently running. Cube cuttle delete pod my pod. Enter. Now the pod is deleted. Right. Now let us create a brand new service account. How do we create it? Basically you can create it with the 26:46:22 help of manifest file which we saw in the previous video but this time we are going to do it with an imperative manner. How you can do that? Just write the command cubectl create service account and followed by you have to define the service account name. So here I will write my SA that is the name of the service account. Here it says service account/my SA is created. Let us verify the same. So ctl get essay. SA is the short form for service account. And here you can see my essay is created. My service account is created. Right? Now if you want to inspect it, how will you do that? Again simple command cubectl describe the service account. So service account and here the service account name is nothing but my when you press enter here you'll get few information. So now here you can see few set of information such as the name of your service account and the name space in which the service account is created. Right now we haven't specified the name space. So it is taking the name space as default. Right? Clearing the screen. 26:47:24 There is one more thing that I wanted to discuss is like in the older version of Kubernetes you might see the instruction for creating permanent secret token manually. But in modern Kubernetes uh generally use a short leave service account token instead. Right? If you want to request a token explicitly how can you do that? Just write cubectl create token and you can just write the name of the token that is my essay for now. Enter. Here you can see the token is present in front of us. This is how you can create a token manually but again it is not required when you are using when you are dealing with modern kubernetes architecture. So this command requests a token for uh the my service account and it prints to the terminal. So again you have to be careful that this output is sensitive credential material and do not share it with public repository and also remember one more thing that requesting the token through the command line is very much different from configuring a pod and automatically projecting the tokens. Right. So for our demonstration we will assign my service account to the pod so that Kubernetes 26:48:25 can handle the normal token handling so that it will receive the token automatically. But before even that we need to assign service account the permission required for that example. And this is where the previous uh video will come handy that is nothing but rolebased access control. So we already covered in rolebased access control that how you can define the rules in the roles and how you can bind your service account uh with your roles with the help of role binding. Right. So for this demonstration imagine that your application needs to retrive the information from the pods which are present in the default name space. We want it to be able to get the pod, list the pod and watch the pod. And we also don't want that it should be able to delete the port and it should be able to view the secret. So to achieve this we will define role and role binding now right. So let us create the role for it. Now what exactly role is role is nothing but a definition file where we'll define what sort of access will be provided to this specific resource right for the associated service account. So now let us define the role file for now. So vim ro.myl again now whenever we are dealing 26:49:26 with any sort of manifest file in kubernetes in this case specifically here we will just define API version kind and metadata. So let me define the same insert mode API version kind. Now client is nothing but role metadata. Now inside the metadata let me just give this metadata a name. Now what is the name of this role? We will just give it as pod reader. Why? First we just want to give it read permission. So pod - reader. Now again there is one more special value one more important keyword that we need to define in the metadata that is nothing but the name space. Now again here we haven't created a dedicated nameace but we need to explicitly define which name space this role will be applicable to. So here I will write namespace. The name space that we would be using for this demonstration is nothing but default. Now the next things comes is the rules. So here I will define the rules. So inside the rules we will define the API groups. Now here let me define the API groups. So here I will write API groups. 26:50:28 And here since we want it to work into the core Kubernetes API we will just pass empty strings inside the square brackets. Now what is the next thing that you will need to define inside that you will need to define the resource on which it should perform the action. So for which we are defining the rule. So resource. So inside resources we will define the resources where these rules will be applicable and this will be applicable on all the parts which are present inside the name space which is default over here. Now what sort of action this should be able to perform. So for that we need to define the verbs. So here I will type verbs and inside this verbs we will define all the action that it is allowed to do. Let me just write the same. So here the formatting is done. Okay. What is the first action that it should be allowed to do? It should be able to get the bot. Then it should be able to list the bot and then it should be able to watch the bot. Escape colon wq. Let me apply the file cubectl apply - f roll.l enter. 26:51:32 Here it says there is an issue. If you are choosing to ignore these error, turn the validation false. Here it says validation error because API version is not set. Okay. If I do a cat on this ro.l here you can see we didn't define the API version. Where do we get the API version from? Shall we go to Chrome and find the API version in the cubernetes documentation where that is the standard approach. You can follow along with that. But here since we are into the command line we will make use of our best friend that is API resource. So cubectl API resources and I'll do a grab on enter. Uh here you can see we have found the API version for the roles. Let me go back to the manifest file and here I'll update my value inside API version. This is the exact value that we are looking for. Now let me apply the file clearing the screen. cubectl apply - f rule.l and here you can see ro.pec.auorization 8s.io rule reader which was the name of 26:52:34 the rule that we wanted to create is actually created now. Right now let me just list it cubectl get ro and here you can see pod reader is actually created. Now let me just explain you what exactly we were doing. Let me just do a cat on the ro file that we have created. Okay. So what exactly we were doing here we are trying to create a role by the name pod hyphen reader and here there are these sort of rules that we wanted to apply and here you have to put your focus into the verbs right. So what are the three action that we are going to do over here? Get basically it is used to retype the individual part. List it is used to retype the list of pod. Watch it is basically used to receive the updates on that specific parts. Now we need to associate this role with the service account. So for that we need one more resource. What is that resource? It is role binding. Role binding basically will associate your roles along with the service account so that both will be intact. Now let us create the role binding manifest for it. So clearing the screen uh vim ro find binder doml again three keywords 26:53:36 API version kind metadata now again in the kind basically here what exactly we are trying to create we are trying to create a role binder so ro binding and in the API version the exact value that we copied earlier okay uh I need to copy it once again no worries we'll do it later but for now let's define the metadata what should be the name of this role binder. So since we are creating the uh rules for reading the ports, I'll just write a read- pod. Now here I need to define the name space and name space is default. Next thing is what exactly is the next thing that we need to define? We need to define the subject. Now what is that subject? Your subject is your service account. So here I'll define the subject. Inside subject I will need to define the kind of the subject. So kind is nothing but service account and inside that service account you will need to give the name of that service account. Name of that service account is my - SA. Let me just verify the same and uh cube CDL 26:54:40 get SA and yeah the name is my SA. Let me just copy the API version to cubectl API happen resources uh and I will do a grab on ro and when I press enter for role binding this is again the same API version. Now I will go and update my manifest file with the correct value. So here in the API version I am updating it with the correct value for the API version. Second here in the kind I have defined the sort of resource that I want to create. In the metadata I have defined the name of the role binding. Then in in the metadata itself I have defined the name space in which these rules will be applicable. In the subject I have defined the service account and I have given the name for that service account. Now the last thing that I will need to define is the name space for where that service account lies. Name space is nothing but default. Now after that next thing that we need to define is we need to define the role reference for the same. So here let me just write the role reference for it. to roll 26:55:41 ref escape colon wq and let me do a cat on my ro.myl I'll copy the initial key values and now I will go again to my role binder and inside this role reference I will pass all the values okay now here there are few changes that you need to make right first thing is to correct the indentation and remove the metadata so here let me just delete it. So first thing is I will just give some spaces over here. So the indentation is correct. Second is this is not API version. This is API group. So here we are telling which group it falls under. And lastly you need to remove /v1 because this is the place where we got the error last time. Now here we have defined the kind. The kind is nothing but role and we have defined the name of that role. Name of the role is nothing but pod reader. Here basically the role binder is by the name read pod which connects to the pod reader role to the service account that is my essay. So let's connect both the file and let us 26:56:42 apply the manifest file now. So escape wq cubectl. Let me first clear the screen and let me apply the file cubectl apply f rolebinder.l. Here you can see robbinder file got created and it got applied. Now our service account has the necessary permissions subject to the application configuration. We won't do a deep dive into RPA because that is something that we have already covered. Here let's attach the service account to that part. So uh first of all we will need to create our service account and configure the required permission. Now we need to tell Kubernetes which service account or pot should you right? So for that we will need to create a new port. Right? But again here we will use the same manifest file that we created earlier that is myot.l. Here the only thing that we need to define is the service account name right so here I'll just remove the automount thing and here I'll go to insert mode and here I will just add one single line and that will actually attach our service account with this resource right so here I will just pass my service account 26:57:45 name and the service account name is my sa that's it now make sure that service s is in lower case account a is in upper case and name n is in upper is escape colon wq let me apply the manifest file now ubectl apply - f my pod.myl enter here it says forbidden making service uh here it says forbidden error from server error when creating my pod my pod is forbidden error looking up service default service account service account not found I believe there is an mistake with the value so here I have typed my sq but the service account that we have created is my essay I will update my manifest file. So whim my pot.l here it is a typo. I need to correct this. So here instead of sq this is sk wq and let me apply the file once again. And here the port is created. Now the basic thing is done. Now here you have to just focus on the main line. If I do a cat on my pod.ml the main important 26:58:47 change that we did over here is the service account name. We provided the service account name inside that resource file. Right? So this will actually connect our pod with the service account that we have created. We are telling Kubernetes to run the engineix pod using the service account that is my SA instead of using the default service account. So now let us validate the resource. So let me just clear the screen. cubectl get pods. Here you can see pod is up and running. Let me just describe it. Cubectl describe the pod by the name my pod. Enter. And here if I scroll all the way to the top here you can see the service account is nothing but my - SE that is exactly what we did. So that single line basically it attached the service account with the resource that we wanted to create. Right now this actually confirms that the pod is configured to use the custom service account. Now if you inspect the pod volume which you can find the value over here. Here when you inspect it and when you decode it you will find the value from this specific service account because this is something that happens automatically. We didn't do anything for 26:59:48 that. Right now since we have created the service account, we have validated it with the resources. Now let us verify the permission scope for the same. And how we can do that? We can actually make use of cube cut or can I right? So now let us verify the service account has the permission that we actually assigned or not. Right? We gave the three permission. First issued get issued list issued watch. Right? So now let us verify the same video. We already saw how we can verify the permission with the help of cube cuttle o can. Right now we are assuming the same command over here. Now let us create the same for my service account for the default name space. So now let me just clear the screen. Now how you can actually type the command over here. Basically just type cubectl o cany-en i. Here you need to define the action that you want to do. First of all, you need to check whether can I get the parts and for that you need to define one more thing that is hyphen as a system user where we have a service 27:00:49 account and the name of the service account is nothing but uh service account. Now I will need to pass the name space name. So default. Now in the default name space what is the name of my service account? That is nothing but my s and then post that you need to define the name space explicitly. So name space default. Enter. Here it says yes. Here it says yes. Why? Because we explicitly gave it the permission that it can actually get the pod. It can list the pod and it can watch the pod. Now let us verify the other permissions too. So now let me rerun the same command but instead of getting the pod we want to see whether are we able to list the pod with the service account that we have created. Enter. Here it again says yes. Right. Let us do a negative testing over here. If I run cube cutter can I delete pods. Basically this is something that we didn't define in the rule book itself. Right? So when I press enter here it says no. Why? Because we haven't gave that permission to the ports to the rules. Right? So these results confirm 27:01:50 that the service account have the permission granted by the role binding assuming no additional authorization or configuration changes need from our site. Now let us do the recap. Let me go to my visual studio code. All right. So here you can find the entire documentation for whatever things that we have covered so far today. Let me just go all the way to the bottom for the quick recap for the quick summary that we have learned today. So today we have learned what exactly service account is and what role does it plays into Kubernetes. So now let us revise what exactly we learned. So first Kubernetes assign a default service account when we do not specify explicitly. Second Kubernetes can make the service account token available to a part so that the application can do the authentication with the API server. Third, we can disable the automatically mounting of the token with the help of uh service account automount off. And then fourth, we can also create our own service account by assigning the permission with the help of RPAC. Finally, we can attach service account to the part with the help of service account name. And you will need to pass 27:02:50 the name of the service account. And the most important thing just remember that service account means identity, token means credential for authentication and rback defines the permission. So if you haven't watched the previous video, please watch the previous video because this is actually based on the previous one. But again if you have watched till now so thank you very much and I hope you have got plenty much of learning in today's video. So yes that was all in this video and I will see you in the next one. Till that keep learning and thank you very much. Okay. So today we are going to talk about taints and tolerations in Kubernetes. So let's imagine that you have a Kubernetes cluster with multiple nodes and in some of the nodes you are running your regular application but you wish to reserve a specific node for running a dedicated application. Right? Let's take an example that you have an expensive hardware and on that node you wish to run a dedicated application but here the question is how will you make sure that only few specific pods are allowed to schedule on that specific node and how will you prevent other part 27:03:50 to being scheduled on that specific node. This is where taints and tolerations comes into the picture. So in order to understand taints and toleration let's take an example. Let's say you're working in an office and in that office there is a restricted room and basically only few set of employees are allowed to go inside that room. Now again even if you try to punch in your card and try to access that room you won't be able to go inside that room. Why? Because there is a restriction which is imposed on top of it. Right? If you connect the dots with Kubernetes likewise the similar thing has been happening in the node with the help of taints and toleration. So basically what taint is actually doing over here is taint is basically restricting the room and toleration basically it will allow us to go inside that room but on what mechanism toleration is actually allowing us to go inside that room. Basically here on your pod we will mention that if the taint is matching the toleration then that specific pod is actually allowed to go inside that room. Right? I hope you got the understanding what exactly taint is doing. Taint is actually putting the restriction. 27:04:52 Toleration is basically acting as a key lock mechanism it will try to match the taint and the toleration. If both of these value matches then it will allow the schedulation on that job. But here the question is before even we start the actual hands-on one thing we want to make clear that is toleration is not someone who will make the decision for scheduling the pod on the node. That decision is still with the scheduleuler based on the scheduling requirement. It will check the resource utilization and based on that it will schedule the pod on the node. Right. But what toleration is actually doing over here. So toleration is basically checking whether the pod is having the matching taint. Right? Based on that it will say that okay these are the people who will be allowed to go inside the room. So I hope things are clear now. So now let's get started with the hands-on. Now that we have a good understanding about tens and tolerance in Kubernetes. Let's start with the hands on. But before even we move into the hands-on, let us first discuss how you can mark a node as a tainted node. Right? So for that just scroll down and this is the syntax that you may follow right. Uh this specific 27:05:52 documentation you can find into the GitHub repository and you can find it specifically under sub repository number 32 ts and tolerance in cubernetes right and all the manifest that we would be working on today will be pushed into this specific directory. Right. So now let us discuss about this specific syntax what exactly it is saying cube cuttle taint node node name key value and effect. What exactly we are trying to say? So here we are trying to say Kubernetes hey Kubernetes we want to mark a node as tainted node because we want to schedule a dedicated part for this one right because this is a special uh node for us right now let me just explain you what exactly this command does over here right so basically here what exactly you can see there are few new keywords that you can find first of all we are seeing the node name so basically node name basically the one that you want to reserve right here is the place where you will specify the name of the node second you You can see uh we have key and value. So what exactly the key over here is key is the name of the tint that you want to apply and second is the value. So basically 27:06:53 this will be the value associated to that tint. Right? Now it can be anything here. You can just specify the cluster name. So cluster equals to dev cluster equals to prod. This is how you will do the differentiation. For our uh demonstration we will create something very much similar like this or even you can just play it along like you can just experiment with some random values too. Right? So for our case we will make use of dedicated demo that would be the key value that we would be using. Lastly you can see there is a lastly apart from key value you can see there is an effect. Now what exactly is the effect? So basically here we are trying to say what sort of effect should be applied on that specific node right in order to understand effect let us discuss about it. So in Kubernetes in basically we have three sort of effects right so let me just scroll down. So here you can see we have three sort of effects. First is no schedule second is prefer no schedule and third is no execute. So what is the meaning of this? Let us discuss now. Let's first discuss about node schedule because that is something that we would be discussing today, right? Node 27:07:49 schedule. So basically if you want to understand node schedule, imagine that you have a room and that room is nothing but your node and we want to put a sign in the door and we are saying that that entry is only allowed to the people who have the permission. Right? So if a pod doesn't have the required toleration, Kubernetes will not allow it to schedule on that specific node. But uh if a pod is already running inside that room, it will continue to running. It will not uh delete it. It will not stop it. Right? Now next comes the prefer no schedule. So what exactly prefer no schedule does. So here you have to just imagine the same room but this time the sign board we are changing is in the sign node we are saying that please avoid using this room. If other rooms are available feel free to use that. So Kubernetes will try to schedule the ports on other suitable node first. If those are already occupied then it will consider this node. Right? So prefer node schedule is a preference and it is not a strict rule. Right? Last that you can see here is no execute. This one is slightly very 27:08:49 different from the other two because here we are putting a sign in the door saying that people without permission cannot enter. But the condition over here is and anyone who is already running inside it should be eliminated should be removed. Right? So that is how no execute effect works. So new pods without a matching toleration cannot be scheduled on that node. And also if a pod which is already running on that node will be removed from the kubernetes. If I put everything into simpler terms. So basically no schedule will say don't allow the new parts with the matching uh toleration. No schedule what it will say it will try to avoid placing the pods on the node. And third is no execute. It will not allow the new pods and it will delete the existing pod which are running on that node. Right? So that's it. Now we understand the effect of stains on the nodes. Now here let's move forward with the tolerations. Uh here there are few prerequisite. Now if you're using mini cube cluster you will have to create three new nodes for this specific demonstration. You may find the command over here. But that is 27:09:49 exactly that I will show you over here so that you have the complete hands-on and you have the complete environment to get started with it. Right? But before even we move forward with that let us first discuss about dollaration. So now let's go downward and under the fifth point you will find what exactly is a toleration. Before even jumping into the direct hands-on let us first understand the key concept. Now we are aware about the taints what are effects that it carries. Now let us do a deep discussion into the tolerance because this is the exact thing that will apply the rule that will make sure that the pod is scheduled on that dedicated node. Right? So what exactly is a toleration? So toleration is configured inside the pod specification. when you will define the manifest at that time you will have to define the toleration inside it right so let's take an example that the effect that has been applied on your dedicated node is no scheduled now based on that we will uh create a toleration so that it will make sure that this specific pod get scheduled on the dedicated node right suppose we want to tolerate a particular pod into this stain so we can 27:10:48 add these following configuration into the manifest file right now let us discuss what exactly this mean right so here we are saying one thing that the key should be dedicated, operator should be equal and value should be demo and the effect should be node schedule. If I go back, if I scroll all the way to the top here, you can see the same taint we have defined was in the same pattern. Here what we said here the key should be equals to value. And here you can see the operator present as well. And here lastly you can see the effect. What exactly toleration is doing here? It is matching the toleration with the T. So that it is acting as a K value pair mechanism, lock and key mechanism. So that if I scroll all the way to the bottom, you can see things will make sense now, right? Because in the toleration, we are just saying that it should find the node where the taint is already applied and here the taint value should be dedicated, the operation should be equal and the value should be demo. And the effect that should be applied on that specific node should be node scheduled. Now I 27:11:48 think things will make sense for you. But remember one more thing that tolerating a tin doesn't guarantee that the pod will run on that specific node if you want to ensure if you want to get 100% guarantee that this specific port should run on the dedicated node. For that we will make use of node selector which we already know right in this specific demonstration we will make use of node selector so that it will assure 100% guarantee that the pod gets scheduled on the dedicated node right now let us move to the terminal and now let's start with the actual hands-on. So now here I'll switch to my item. Okay. So the very first thing that we would be doing is we need to create one profile like we have been creating earlier as well. Right. So uh why we are creating a profile because here we will need that context. We want three specific node. Right? Now we are working on a mini cube cluster. It consist of single worker and master node. Right? We want three specific node so that we can perform the operation. So here we'll just keep initial two nodes reserved for scheduling the parts. We'll see what exactly is the behavior when you're scheduling the pods normally and what 27:12:49 exactly is the behavior when you do it with taints and toleration. Right? So for that let us create a mini cube cluster with three nodes. How you can create it? Just type mini cube start and then after that you have to define - nodes and here basically we want three node. Now we need to define the profile. So here I'll just write hyphen p and write the name of the profile. So here I'll just write taint- demo. Enter. Here I need to correct my spelling. So it is mini cube. Enter. Here it is trying to create a mini cube cluster with three nodes. Now again I am repeating the initial two nodes. We will make sure that we are going to use it for regular application deployment. And the last node basically we will apply the team to it and we'll see what exactly is the behavior because whenever we were creating the deployment at that time we were not specifying which node it should apply which node it should create the port to right so here we are going to apply a taint on the third node and we are going to see whether the deployment is allowed to schedule the pod on that specific node or not right 27:13:51 so here let us give it some time once the node is prepared then we will start creating the deployment file over here okay now you can see the mini cube start command is completed meaning that three nodes are created right let us verify whether the node got created or not so for that let me clear the screen and I'll just type cubectl get nodes and here you can see we have three nodes present in front of us first is taint- demo second you can see taint- demo m02 third we have taint- demo m03 these are the three nodes that are present over here for our demonstration we will apply the taint effect on the third uh node so that we can actually observe what exactly is the behavior when we apply the deployment manifest file and how we are able to schedule a port on this tinted node right uh again there is one more thing that you can see like before we apply the taint on the third node let us first do o wide we'll get a complete detail of we will get a complete detail of it yes clearing the screen so here 27:14:54 you can see we have the complete detail about all the nodes which are present in front of us Right. So now for our demonstration we need to switch to the context. Uh what is the context? Basically the profile that you have created. Right. So for that just write cubectl context. And here you will need to write the profile name. So here I'll just write use context and the profile name is nothing but - demo. Enter context. This should be use context. Okay. This should be config cut config context 10 demo. Enter. Now here you can see we have switched to the context. Clearing the screen. Initial things are done. Let me do a zoom in over here. Now let us verify the nodes. Cube cuttle get nodes. Again we have the three nodes present. Tint demo m02 and m03. We will perform the taint effect on the third node that 27:15:55 is m3. Right? So now let us apply the tint. How you can apply the tint? Now we will follow the same syntax that we have seen earlier that is nothing but cubectl taints. And here you will need to cube kit taint nodes and here you will need to pass the name of the node. I'll copy the name of the node which is taint- demo 0 taint- demo m03. And here you will need to define the key value pair. So for now I'll just write dedicated and I'll just write the value as demo. Feel free to write any value that you want. And now lastly what is the effect that you want? I want the effect that it should not schedule anything apart from the uh part that we want to schedule with the help of toleration. So no schedule. Enter. Here you can see it says node / taint- demo m03 tainted meaning the rule is applied here. The only thing that you have to remember is the key value pair. Here we mentioned the key as dedicated. 27:16:57 The operator is equal and the value is demo. And the effect that we are applying is not scheduled. Right? Clear the screen. Now let us start with the actual hands-on. Let us create a deployment file that will help us to demonstrate if we are not specifying the toleration whether deployment is allowed to to schedule the pod on that specific third node. Right? So let me create a deployment file now. So, Vim Engine X - deployment ML enter. Now, again four keywords API version, kind, metadata and spec. So, here I'll start with those API version kind metadata and lastly we'll write the specification the configuration for it. Now again what is the API version for deployment? It is nothing but app/v1. This value we are going to take with the help of API resources or again you can take this value from cubernetes documentation or you can search it into stack orflow or maybe you can search it into the Google group. Okay. Now here the second thing that I will need to write is the kind here we are telling kubernetes what sort of resource we are 27:17:57 trying to create. So here I want to create a deployment and then what's the metadata what would be the name of this specific deployment. So here I'll just write engine demo. Next thing that we need to defi define is the settings the configuration for this specific deployment. Now again in this deployment basically we will be actually handling the replica set. We will need to tell how much replica you want to create. So here I will define the replicas. Uh for now we'll create three replicas so that it will schedule one pod per node. But right now the third node is already tainted. So the expectation is it should adjust the resource in such way that it is scheduling the pods on the initial two nodes. Right? Next we need to define is the selector. Now why selector? Because uh this is the way through which the deployment will know which pods it has to manage. Right? So selector. So inside selector you will need to define the labels. So selector should search for the pods which matches the labels. Now here you need to define the label. So here I'll just type app colon enginex 27:18:59 - demo. Now again selector is defined. The next thing that you need to define is the template because that is something that the replica will create the replicas for right. So here I'll just type template. Now here the template will again consist of the metadata. So metadata this metadata is basically for the ports. Now again that metadata should has one important value that is nothing but label. So here labels inside label you need to define the actual label that you are searching for. The label that we are searching for is app engine demo. This is basics that we have already covered in the previous video. So now let us move forward uh with the uh specification for the containers. So inside metadata I'll define the spec for the containers. Now let us give the name to the container. So I'll just call it as app. And then here the image that I want to use is nothing but enginex colon latest. That's it. We have defined the deployment and this was very quick because this this is something that we have already covered here. What exactly we are doing here? We are defining the 27:20:00 API version. Let me just get the API version. So cubectl API resources and I'll do a grab on deploy so that I'll get the API version on deployment. So this is deploy uh the API version is app/v1. Let me update the manifest file now. Okay. So here we are telling Kubernetes the API version that we are using is app/v1. Then second in kind we are defining what sort of resource we wish to create. Thirdly in the metadata we are defining the name of the deployment that is nothing but engine demo. Then here it contains the spec. This spec is for the deployment. The settings the configuration for deployment. In the specification we are telling that we want to manage three replicas. And here for that specific uh replicas we are defining what sort of labels we should search for the pod that it should manage. Then here we are defining the template. So deployment basically will manage the replica set and replica set will make will actually make sure that the parts with these settings with the same configuration should be created. Now what exactly is the configuration in 27:21:00 the metadata? We have defined the labels and in this specs. So here we are telling the configuration for the containers. The name of the container should be application and the image that it should use is nothing but engineix col. This is not images. This should be image escape wq. Let me apply the manifest file cubectl apply f engine deployment. Enter. And here you can see deployment. Engineix is created. Let me verify the pods. Cube cuttle get pods. And here you can see it says pod is uh container is getting created. Let me uh let me just verify the deployment to cube cuttle get deploy. Okay. Now here it says that all the pods that we created are actually up and running. Here the thing that we need to verify is on which node these pod got scheduled. So for that what I will do I will just type cube cut get pods white enter. If I do a little bit of zoom out, I'll clear the screen so that it is at the top. And yep, here you can 27:22:03 see on which specific node this part got scheduled. Just put your focus into nodes. Here you can see the first part got scheduled into demo m03. Here you can see the second part got scheduled into the first node that is taint- demo. And here you can see the third part got scheduled into M02. If you remember, we created three nodes. So ideally if there would have been a normal situation where our third M03 node was not tainted in that case it would have scheduled the pod on that specific node too but since it is a tainted node it didn't actually applied it didn't actually created the pod inside that specific node. I hope now you got the clarification what role does taint actually plays into kubernetes right now let us create a pod so that we can schedule a resource into the tainted node right so for that let me create a manifest file for the pod itself so here we are going to create a separate pod with the matching toleration the values key and value pairs so that it will be very much easier for us to verify whether the pod 27:23:05 got created in m03 or not right so let us create a new file create clearing bring the screen vim toleration pod do.l AML. Now again here the pattern remains the same. We need to define the four important keywords. API version, client, metadata and spec. So here I'll go to insert mode. API version, client, metadata. And lastly I'll define the specification. Now again what is the API version for pod? So the API version for pod is nothing but v1. We can verify it with the uh cube cut api resources. Next we need to define what sort of resource we are trying to create. We are trying to create a pod. again. Now let us define the metadata. So here in the metadata I'll just give the name of the pod. So here I'll just name this pod as engineix toleration pod. This would be the name of the pod that we are trying to create. Now here in this specification let us define the specification for the containers. Right? So here I will just define the specification for the container. So 27:24:06 containers here let us first define the name of the container. This is toleration - container. And now the image that it will be utilizing is nothing but enginex - latest. Okay. Engineix col. This would be the image that we would be defining. Now if you remember when we were going through the documentation there we saw there are few set of values that you need to define into the manifest file so that your resource will be considered into the toleration group. Right? So here let us define the specification for the same. Here the first thing that you will need to define is the toleration. So here I'll just type toleration and here I'll just do a little bit of zoom in better. So here inside toleration what all values will come. Now if you remember when we were marking the node as tainted node we passed the key value pair and then we pass the effect. The effect here is no schedule. Second is what are what was the key value pair. So the key that we defined earlier was dedicated and the operator that we used was equal and lastly the value was nothing but demo. That is exactly what we will be pasting over 27:25:08 here. So here I'll just write key. Key was nothing but dedicated operator. Operator was nothing but equals. And lastly the value. Value was nothing but demo. And lastly the last and the important thing that you need to define is the effect. So effect was nothing but node schedule. No schedule. Okay. This is the exact thing that will make sure that the toleration will match the taint and it will make sure that the scheduling happens on that specific node. But again I mentioned that we can make use of node selector so that we can have a 100% guarantee that this specific part this specific resource will get scheduled on that specific node. So here what I'll do under the specification itself I will need to define the node selector so that uh this part guarantees that it will get scheduled on that specific node. So here I'll just write node selectors. Make sure the S is in upper case. And then here I will just write cuber.io/host 27:26:09 name. Kubernetes.io/host name. And here I will need to pass the name of the node. SK WQ. Let me just get the node cube cuttle get nodes. Enter. And here I'll copy the node name from here. I'll go back to my manifest file. And in cubernetes.io/host name I will paste the node name. That's it. So here what exactly we did? We define the node selector that guarantees that the resource that we are trying to create will be created into the node that we want to. Second in the toleration we define the values. We define the key. We define the operator. We define the value. Also we define the effect that will actually match the t that has been applied on that node. Then lastly we have given the settings the configuration for the for the container that should run on that specific port. Right? So we have everything in place in front of us. Now let me just do escape colq and let us apply this file. So cubectl apply - f toleration port dotl. Here you can see the toleration port is created. Let me just verify the port cube cut ports. Enter. Here you can see 27:27:11 it says uh container is creating. Let us wait for some time. Let us give it some time and then we'll verify the values. Right. Okay. Okay. Now it should be good. Let me just uh run the command once again. And here it says the pod is actually running. Okay. Okay, let us describe it. cubectl describe describe pod followed by the pod name. And here you can see uh successfully assigned to the tainted pod that we have created. Again there is one more thing that you can verify is when you want to know what exactly is the key and the value present for that specific node. You can also do the same. So here first run cubectl get nodes and here we want to verify what is the taint key and value that has been used on this specific node. For that you can just run cubectl describe node followed by the node name. Here if you scroll upwards at the top you will find the value that you're looking for. So here you can see the section for taints and here in the taint you can see the key is dedicated the value is demo the 27:28:11 operator is equals and the effect is node schedule. That is how you can verify what sort of tainted value it is actually consuming for that specific node. I hope this video made sense. Now if I just do clear, if I run cube ctl get pods - o white enter here comes the verification that the node toleration pod got scheduled on the node named taint- demo m03. That is how we have proved that node selector helps us with 100% guarantee that the resource that we want to create on the tainted node gets created for sure. And then here we made use of tolerations and taint. Now we have a complete understanding that whenever we want to run a dedicated pod on a selected nodes. This is the thing that you should look for. Right? So remember one more thing toleration does not force a pod into a node. It only allows pod to be scheduled on the node which has the matching tint. So that is why node selector comes into the picture. That is exactly what we have used. Right? So let me just go to my 27:29:13 visual studio code. And now let's wrap up. Let us take the summary whatever we have learned so far. So now what exactly we learned today? Basically we learned about taint. Tint is applied on a node so that it is repelling all the part so that it can preserve the space for the dedicated application that you wish to run on it. On what sort of application it is allowing those port to come into that node. Basically here we are making use of toleration. So toleration is added to the pot to allow to allow it to tolerate on the matching t. Then we learned about three t effects. First is no schedule, prefer no schedule and no execute. No schedule is something that we saw just now. It prevents uh new non- tolerating pods from being scheduled on the node. Then we learned about prefer node schedule. It tells Kubernetes to avoid the pods scheduling on that specific node. If the space is not available on the remaining two nodes then you can actually schedule the pod on the specific one. But the third option is very much interesting that is no execute because here it is explicitly saying that go out from the room here there is 27:30:14 no space for you even there is something which is currently running inside that node it will eliminate them right then remember one final thing that toleration doesn't force a pod into a particular node to target a specific node here we can make use of node selector which we actually did so if you remember this concept then your life with teams and tolerations will be very much easy so yes That was all in this video and I will see you in the next one. Until the next time, keep learning and thank you very much. Okay. So, we are well aware about taints and tolerance in Kubernetes and in today's video we are going to learn another scheduling option that Kubernetes offer that is node affinity and node entinity. Right? Let's take an example. Let's say you have a Kubernetes cluster with multiple nodes. One has high CPU capacity, another has high memory capacity, one is of type SSD and another is of type HDD. Now let's say you have an application that requires an SD. How will you make sure that that specific application is running on a node that is of type SSD. Now here we can make use of node selector right and 27:31:15 that is a correct approach. But what if I say that we need to define other scheduling options too? For example, let's say we want that application to run either on SSD or HDT. How we can define that specific rule? How we can make sure that a node of specific label should be ignored while scheduling the pod? Well, basically this can be achieved with the help of node affinity and in this video we are going to learn the same. Now let us understand what exactly node affinity is, right? Node affinity is basically a set of scheduling rules that helps cubernetes in identifying the nodes that are good for your parts. Right? Let's say you have multiple nodes. One has high CPU capacity, one has high memory capacity. One is of type SSD, another is of type HDD. Your applications require SSD and we don't want Kubernetes to randomly schedule the pods on random nodes right here we'll need to define that rule and here we can define that rule with the help of node affinity here we can make use of label so basically we can mark your node with the label this type equals to SST so that it will be helpful for Kubernetes to identify which node we 27:32:16 are targeting to right now based on that we can define the scheduling rules on node affinity with the help of node affinity so that Kubernetes will be able to identify the node for our specific pod. So remember node affinity is basically a set of scheduling rules that helps kubernetes in identifying the node for your pod. So before we jump into n affinity let us discuss the two important option that node affinity offers that is required during scheduling and ignore during execution and second is preferred during scheduling and ignored during execution. These terms are very big but the concept is very much simpler. Let me explain you the first one that is required during scheduling and ignored during execution. What happens in this case? So here basically we are defining a condition for Kubernetes that it should satisfy before scheduling the pod. Right? Let's take an example. Let's say your application require the node of type SSD. Right? So here basically we are defining a condition for Kubernetes for scheduling the pod on the node where it is of type SSD. Right? But what will happen if it fails to find the node of type SSD. Here your pod will be in 27:33:17 pending state. Now what is the meaning of the second term that is ignored during execution. Let's say your pod got scheduled and later someone changed the label from dig type SSD to something else. What will happen in this case? So here we are making sure that the pods which are already running should not get evicted should not be deleted. That is the meaning of ignored during execution. Right now let us discuss about the second option of node affinity that is preferred during scheduling and ignored during execution. So here we are just telling a preference from our side that it should schedule the pod on the node that is of type SSD. But again if it fails to find node of type SST feel free to assign the pod on the similar node. Right? That is the meaning of preferred during scheduling. Now again ignore during execution it remains the same. Let's say your pod got scheduled on that node and someone later changed the label type from dict type SSD to something else. Then here it will make sure that your pods are not evicted and your pods are actually running. So here node affinity offers two sort of type. First is required during scheduling, ignore 27:34:15 during execution and second is preferred during scheduling and ignore during execution. In required during scheduling we are mentioning that it should find the nodes of type SSD. In preferred during scheduling we are actually telling that should it should actually give the first preference to SSD type node. If not found then you can feel free to assign it to another nodes. Right? So these are the two options in node affinity. So now let us discuss about ND affinity. Right? So affinity means that we want to place something on a particular location and anti-affffinity is basically the opposite of it. Basically here we are telling that it should not schedule something on a particular location. Right? So here we have two concept to understand. First is let's say if you don't want to schedule something on a particular node. So with the help of node affinity and the labels you can make sure that the pods are not been scheduled where the label let's say it's this type equals to SSD with the help of not in operator you can make sure that the pods are not scheduled on that specific node. Second is let's say you have three replicas that is actually running your application and all those 27:35:14 replicas are present in a node. What will happen if that node is down? It will impact the application and it will lead to downtime. Right? So here with the help of pod anti- affinity rule what will happen? It will make sure that a single node does not contain the pod that have similar labels. So here basically your pod will get distributed to multiple nodes. So that even if one pod is down then your application is not experiencing the downtime. That is the basic use of anti- affinity group. Right now you have a clear understanding about affinity and anti-affffinity. So now let's start with the hands-on. So for this specific demonstration we will need to create a three node mini cube cluster. So let us create the same. So I'll just type mini cube start - nodes. Uh now since we want three nodes I'll type three over here. Then we need to define the profile. Now since here we are demonstrating affinity. So I'll just write f - demo. Enter. Now here at the back end what it will do? It will create a three node mini cube cluster for me. And then later once it is created the next thing that we would be doing is we will mark 27:36:15 the two of the node as SSD and another one as HDD. So here we would be defining the label as stitch type as based on the earlier example so that it would be easier for us to follow. Let us give mini cube some time so that it is creating the nodes for us. Once it is created then we'll start with the labeling part. Okay. So now you can see the nodes are created. Let us verify the same clearing the screen. Cubectl get nodes. So now you can see we have three nodes present in front of us. First is affinity demo. Second is affinity demo m02 and third is affinity demo m03. Now what we'll do? We'll just mark labels in two of the node so that it would be easier for us to identify. We'll mark the labels such as that we are specifying the disc type as sddd or this type as hddd. So here I'll just write ubectl label and here I'll just write the name of the node. The name of the node here is affinity demo and here the label that I want to pass as disk type. So we'll mark this one as SSD. Enter. And here you can see node affinity has been labeled. Now the same thing we'll 27:37:17 do with the second one. Here with the node affinity demo m03 - m 02 I'll just mark m02 as hddd. Enter. And here m02 is also been labeled as hdddd. So now let us verify the label. So cubectl and here I will list down all the labels. So cube cut get nodes with the label for disk type that is the one that we defined and here you can see uh for affinity demo we are marking the disc type as std and sec SSD and secondly for affinity demo m02 we have defined the disc type as HTD right clearing the screen so the initial thing is done now let us demonstrate node affinity with the help of a pod example let us create a manifest for the same so vim podamel now again four keywords API version signed meta data and lastly the spec. Okay. Now the first thing that we are aware of that the API version for pod is nothing 27:38:17 but v1. This value you can get from cube cut api resource or you can go to the cubernetes documentation and basically we are trying we are trying to tell kubernetes what sort of resource we want to create. So here we are telling cubernetes that the resource that we are trying to create is nothing but a pod. So here in the metadata next thing we have to define the name of the pod. So here I will just write it as affinity pod and next we have spec. So in the spec basically we will define what sort of thing that we want to run. Here in the pod we want to run a container. So here I will write containers and inside container I will name the container as uh demo pod and here I will define the image. So here you can make use of any image. So for this one I will make use of engineext. So enginex colone. Now here uh since we are talking about node affinity we will need to define the affinity rules. How we can do that? So here just write affinity and here inside the affinity you need to define the affinity rule. This time we want to define the rule for node affinity. So I'll just write node affinity and inside node affinity you need to define the uh 27:39:20 type of node affinity rule. Right? So if you remember earlier we learned about two node affinity rules. First is required during scheduling, ignored during execution and second what preferred during scheduling and ignore during execution. This time we'll make use of required during scheduling and ignore during execution. So I'll just write required during during ignored during execution and here basically we will need to pass one more value that is node selector terms right but on what terms we are selecting the node. output selector term. So here in the node selector terms basically we need to pass the matching expression that is exactly what we'll pass now. So expression expressions and the expression that we need to pass is basically the labels that we have defined in the node right here. Basically we want to schedule this part on that node where the key is of 27:40:21 this hyphen type. Next thing that you will need to define over here is the operator. Operator here in this case is n. And last thing that you will need to define is the values. So values here in this case the value is nothing but ssd escape col wq. So let me just verify the value too. Cube cuttle get uh nodes and hyphen lore disk type enter. Here we are using this type as SSD. So basically the end thing that we want is whatever pod we are creating it should get scheduled in affinity demo node right so I'll go back to my pod and here I'll just verify my value. So here the value is SSD the key is test type operator we have made use as in. So now we are good. SK WQ. Let me just apply the file cubectl apply - f port.l enter. Here it says there is an error. Uh bad 27:41:23 request error when creating port.l port in version v1 cannot handle as part stick decoding error. There is an unknown field. It says spec. Affinity. Node affinity required during scheduling ignore during execution. Node selector terms. Okay. Let me go back. Here it says the issue is with the node selector terms. So I'll just need to check these spellings. Node selector. So here there is a typo. I need to remove this node selector escape wq. Let me apply the file once again. This time the pod is created. Let me clear the screen. cubectl get pods. And here you can see it says container creating. Let let us give it some time. So now here you can see the pod is actually running. Let us verify on which node it is running. So cube cut gets - oite enter. And here as you can verify as per our expectation it is running in affinity demo. That was the first validation that was the first check that 27:42:23 we wanted to do. Right now again if you want to describe the part again you can get the detail again there also. So cubectl describe describe pod name of the pod is nothing but affinity pod. Enter. And here if you scroll all the way to the top here you can see the node that it selected is affinity hyphen demo right. So the first thing that we wanted to demonstrate has been done. So here basically what we did we just added the labels to the nodes and here the end thing that we wanted is the part that we are creating it should get scheduled on the node where the disk type is SSD right now. So now let us demonstrate node avoidance with the help of node affinity. Right. So for that uh we need to assume that we don't want to provide a pod uh to the SSD nodes want Kubernetes to schedule or a pods to an eligible node that does not have this type equals to SSD right so here we will make use of not in operator in this specific one we made use of operator in right clearing the screen and let us create another file so vim node - avoid 27:43:26 uh let me just copy the context uh from the previous manifest so cpod.ml and We should copy everything to avoid.yamel and yep. Now here we should be good. Vim node avoid.yamel. Here we have the entire thing whatever we want. The only thing that we would be changing over here is uh the name of the pod. So here avoid affinity pod and then here in the affinity rules we have we are using the same option required during scheduling ignore during execution. And here in the uh node selector terms we are using the same thing. The only thing that we would be changing over here is the operator. And instead of in we are making use of not in. Okay. And here the values again it could be SSD that we would be utilizing. And the container name here let us change this to demo pod one. Escape wq. Let me apply the file cube ctl apply f node avoid. Enter. Here you 27:44:26 can see that this part is created. Now our end expectation is that this bot should not get scheduled on the previous bot that has the disc type is equals to SSD. So the end expectation is now if I run cubectl get nodes - l disk - type. So here you can see uh this bot should get scheduled to either affinity demo m02 or affinity demo m03 instead of affinity demo sd because here in the operator itself we said that we don't want want to schedule our pod in this specific right so now let us verify the same so cubectl get pods o wide enter and here you can see avoid affinity pod is scheduled to affinity demo m02 where the d type is hddd Okay, that was another demonstration that we need to do. So in the previous one we made use of in operator because we wanted to select the node where the type is equal to SSD. This time we made use of not in that means that node must not have the label value SSD for this 27:45:27 specific condition match. Right? So that's all that we have checked over here. So yeah that's it for this specific demonstration. But again there is one more thing. Let's say if you want to remove the label from either one of the part how you can do that. So that can be done with the help of cubectl label and here you need to pass uh and here you need to pass the name of the node. So let's say I want to remove the label from f1 demo m02 and here uh I'll just type the key value that is disk type and just pass one minus over here and when you press enter the label will be removed. Now the next time when you run cube cuttle get nodes hyphen analytics type the label won't be present there. So this is how you remove the label on a specific node. Right? So that was the demonstration. I hope in this video you learned a lot. So let us take a recap. Let me just go to my visual studio code that will help us for the summary. Now again this uh specific demonstration, the specific uh documentation you can find into the GitHub repository. And for this specific demonstration you can follow subreository number 33. The manifest 27:46:27 file and the readme. MD will be pushed to the GitHub repository. Let us go all the way to the bottom and let's take the quick takeaways from this video. So, uh here basically we learned about node affinity that allows us to control the part placement based on the node labels. Second, we learned about uh the type of node scheduling options that we have in node affinity that is required during scheduling, ignored during execution. And second is preferred during scheduling and ignored during execution. Thirdly, we understood about the operators in and not in and actually we performed the hand job that gave us the clarity how the scheduling conditions works over here. So this concepts are really really helpful when you want to perform when you want to schedule something into Kubernetes node and you want to specify few condition from your end. So yes that was all in this video and I will see you in the next one. Until the next time keep learning and thank you very much. Hey everyone, in this video we are going to learn about network policies in Kubernetes. Now let's say you have a Kubernetes cluster and there are multiple applications which are running. 27:47:28 Now let us categorize them into front end application, back end application and your database. Right? So here we want complete control over the database where we want to set a rule into the database that it should not accept any traffic from the front end and it should be allowed to accept the traffic only from the back end. Uh how this can be possible? So this is possible with the help of network policies in Kubernetes. Now in order to understand network policies there are two concept that you should be aware of that is ingress and aggress. So today we are going to understand about network policies ingress and agress in this specific video. So now let's get started. So now what exactly is a network policy? In order to understand network policy let's take an example. Let's say you have a Kubernetes cluster. In that cluster you have a front-end application, your back end application and you have a database. So now the communication will look like your front end will send the request to the back end and your back end will communicate that request to the database. Right? Now here we don't want our database and your back end to accept the request from any random part apart 27:48:28 from the front end. Now how we can control this traffic rules here? We can define that rule into the network policy resource. So here basically what we'll do with the help of labels we will tell database and we will define the rule in the back end such that they are aware from which place they are actually allowed to take the request from that is how we will make sure that the incoming traffic and outgoing traffic is actually been defined at the pod level. Now here if you remember I mentioned about one word that is rule. So what are the rules in network policies? Here we have two sort of rules in network policies that is ingress and aggress. So if I put it into simpler terms, ingress is basically the incoming traffic and aggress is basically the outgoing traffic. Right? So now in order to understand network policies, let us first understand ingress and aggress. And that is actually something that will give us a clarity how does network policies work in cubernetes. So now let's get started with the ingress and all right. So uh before writing our very first network policy uh let us understand two most important term that 27:49:29 is ingress and right because that will literally give us the complete idea what exactly networking in kubernetes looks like right let's discuss about the first terminology that is ingress right ingress means incoming network traffic to a pod so for example imagine that you have a client uh that sends the HTTP request to the backend pod that incoming request is ingress traffic to the back end. Right? So using ingress network policy we can control which boards are allowed to send the traffic to the back end. Right? Now let's discuss about agress. What exactly is agress? So agress means outward uh or outgoing network traffic from a board. For example, imagine that our backend application sends the same request to the database port, right? So that outgoing request is address traffic for the backend pod, right? So using aggress network policy, we can control 27:50:29 which destination uh of a pod is allowed to communicate with, right? So here uh it's a easy way to remember the difference. Ingress basically means that the traffic which is entering to a selected pod and aggress basically means the traffic that is leaving a selected pod. Right? So you have to keep this mind uh because these rules are evaluated from the perspective of the pod selected by the network policy. So now let us put all the concept together practically. So let us go to the terminal. Let me switch to my item now. So here is the place where we would be performing today's hands-on. So the first thing that we would be doing is let us create a new profile. And here there is one more thing that we would be doing is we will make use of Calico as a CNI plugin. Right? So let me create a new profile. So here I type mini cube start driver and the driver for mini cube that we are using is nothing but docker. And here I need to define the CNI plug-in 27:51:29 over here. The CNI plug-in that we would be using is Calico. Okay. And last thing that we need to define over here is nothing but the profile where we would be working. Here we would be working on network policy -. So this is the profile that we have designed. Pressing enter. Clear the screen once again. All right. So network policy demo. And here what exactly is happening here? We are creating a mini profile by the name network policy demo. Okay. I think there is a typo mistake and I think I need to correct that. So let me just clear the screen and here this is one second and here this is not work. Okay. Now what exactly mini cube will do? It will create a profile by the name of network policy de and that profile we will be using for doing today's demonstration and here we are using 27:52:30 calug as a CNI plugin right what exactly calico will do calico will provide the networking functionality and it will support kubernetes uh network policy enforcement right and once it is successful uh let us see the cluster and let us see what uh sort of nodes that we get by default. Clearing the screen. The first and the foremost thing that we should do is once it is done, we need to switch the context. How do you switch the context in mini cube? Just write cubectl config context use context followed by the name of the profile that we have created. The name of the profile is network policy - demo. Enter. And here we have switched to the uh policy that we have created to the profile that we have created. Name of the profile is network policy demo. Right? Now let us verify whether the cluster is running or not. For that just type cube cuttle get nodes enter. And here you can see it says not ready. Let 27:53:32 us give it some time so that the control plane is actually ready for us. Now since we are using mini cube here it acts as both control and worker node. So let us give it some time so that it is ready. Once it is ready then we should be good to start with today's hands on. Let me clear the screen and let us wait for some time. Once it is ready I'll just from here and one more thing if you feel like why it is taking that much of time it's because like we are installing that Caliggo network plugin right that is the reason why it is taking that much of time. Right? If you want to verify the same just write cubectl get pods - a and here you can see there are few pods which are still once all of these are ready then our worker node will be ready and then we should start with the actual hands on let me clear the screen and let us give it some time once it is ready once it is move from pending to running then things would be good for us then we should actually start with the hands on so I'm clearing the screen and let us 27:54:33 wait for some so finally After 10 minutes the cluster is ready. Let me just verify the same. So cubectl get nodes and here you can see the node is ready now. And now let me verify the individual components. So cube cuttle get pods - a and here you can see all the components are ready. Here it will take nearly about 5 to 10 minutes. So here mostly it will be uh delaying with because of this component from calico. Now once it is ready it will be actually good for us. It is a green signal for us so that we can actually start with the hands-on. Once it is done, the very first thing that we would be doing is we will create a separate name space for our demonstration. How do we create a name space? So basically two methods. One is via command line, another with the manifest. So now let us do with the command line method. So cubectl create a nameace and the nameace name. So since we are doing the demonstration for network policy, let us create the name space as network policy - demo. So this would be the name 27:55:35 space where we would be working. Right? Now uh after creation of this name space, let us define the context. So cubectl config set context and here I will need to define uh the current context that we will be using. So - current and now I will need to define the name space. So name space and what is the name space name? So we just created it. The name of the name space is nothing but network policy demo. And here you can see the context that we have been selecting right now is network policy demo. That is exactly what we did. Now why we are doing this? Because it allows us to run the commands such as cube cuts without even specifying the name space again and again. So this is the exact thing if you remember uh whenever we were creating the manifest file we were explicitly telling that we want to create the resource in this specific uh name space. So here it makes very clear for the name space that uh which specific resource 27:56:37 that it is actually belonging to. Right. So let us verify the current context uh in which we are currently logged into. So cubectl config view - mini by enter and here you can see the current context where we are actually working is nothing but network policy demo right this is the exact place where you can verify clearing the screen now you should see the network policy demo configured in the current name space and we are good with this right so uh there is one more important thing that you should remember that the name space must exist before you apply uh the ML files uh so that it can reference to it. Right? So now let us create the very first uh application that we would be demonstrating today. So first we'll create the back end application using the engineext image. Right? So for that I'll create a manifest file. So bim back end dot camel enter. Now again what are the four keywords whenever we are 27:57:38 dealing with any sort of resourcing. So that is nothing but API version signed meta data and lastly we need to define is the spec. Now what is the resource that we want to create? We are going to create a deployment. Okay. Nextly what could be the name of that deployment. So the name of the deployment. Now since we are creating a backend application I will type it as back end. Now again the next thing that you need to define over here is the name space. So right now we just created the name space. The name space name is network- policy - demo. Okay, so this is also done. Lastly, what we will do is we will need to define the labels, right? So here uh I will define the labels where the deployment would be working around. So here it should target the pods where the label is app and the value is back end. In this specification, we need to type how many replicas this deployment should maintain. So replica count is 27:58:39 nothing but we just want to make sure that only one replica is actually doing the job and here we need to define the selectors. So since we define labels here we need to define the selectors. So in the selector we are targeting to those part which matches the labels and the label value should be app colon back end. So now we have defined the selector as well. Now let us actually define uh the template for the same. So here we are defining the template for the pod right. So inside the template the first thing that you will need to define is the metadata. Metadata for this metadata will be basically for the pod that it is supposed to run right. So here we have defined the replica count as one. But again what is the template that it would be that it would be using. So this is the place that we would be defining inside the metadata. We will define the labels that it is supposed to take care of. So here I will copy the label section from here and then here I need to define the labels that it is supposed to take care of that is app colon back end right. So this is the initial thing 27:59:41 done. We have defined the configuration for the replicas and this belongs for the deployment and then here we have defined the template for the pod that it is supposed to again for this part what exactly we would be running inside that pod. Here basically inside this pod we would be running the container. So for that container we will need we need to define the specification. So here in the specification I will define the containers and inside the containers I will need to define the name. So the very first thing that we have defined over here is the name of the container that is nothing but engineext. Now again which image it is utilizing. So that is something that we will be defining over here. So the name of the image would be engineext. You can use anything. So right now I can make use of engine latest or let us do some experiment. So I will make use of engineix table image. Right. Again lastly engineix runs on port number 80. So port here the container port is is nothing but port number 80. That's it. So the manifest file for the deployment is created. Let 28:00:41 us verify the same cubectl apply f backend.l. Here it says there is an error because we haven't defined the API version. Now what is the API version for deployment. so that we can check it onto the cubernetes documentation or we can actually verify into the API resource. Let us do the same into API resource. So cubectl API - resources and we'll do a grap on deploy and this is how we'll get the API version for deployment. Let me just edit my backend file and here under API version I'll go to insert mode and I'll update the API version to app/v1 escape wq. Let me just apply the file once more. And here it says that deployment back end is created. Clearing the screen. Let me explain you the file once again. So vim back end. So here what exactly we did? We created a deployment. Okay. So here the first thing is we defined the API version app/v1. Here we are telling kubernetes that we are 28:01:42 creating the deployment file. Inside the metadata we defined the name of the deployment that is nothing but back end. And here we want to create this resource in the name space called network policy demo. Right? Then we have defined the labels for this uh uh deployment right and here the label is app and the value is back end. Now again after this we have defined the specification for this deployment. Now deployment actually make sure that this sort of replicas are been maintained. So here we are passing the replica count that is one and again that replica count will be managing your pods based on the selector. So here we have defined the selector the criteria through which it will target the dedicated pod that is exactly we have mentioned and again here the label that we are utilizing is the key equals to app and the value equals to back end. Now again we are defining the template for this replicat so that it is able to create the port. So just for that template also you will need to define the metadata and inside that metadata we have utilized the same labels that we 28:02:42 were utilizing earlier. Right. Lastly, what we did, we defined the specification for this specific template. Now, again, this template is for what? This template is for your pod and what exactly runs inside your pod. Basically, it's the container, right? So, here we have given the name to the container as engineext. Lastly, we have defined the image through which that container will be created. And at the very end, we have defined the container code that is port number 18. Let me first verify the resource. So, cubectl get deployment. And here that deployment is present in network policy demo. Enter. And here you can see that deployment back end is actually up and running. Uh now the next thing is once we are done with creation of the backend application, we have created the deployment. But how do we access it? We need a proper service for it. Right? So let us create a service manifest file for it. Right? We have again two approach. We can either create a new service file or we can append it into this single backend file too. So we are 28:03:43 going to append it into the same backend file. But again there are already context written in it. How will Kubernetes identify that this manifest contain the service as well. So again the idea is very simple. Just type three dash. This gives Kubernetes the indication that this manifest file consists of two resources. One would be the initial one that is deployment and another one whatever falls below it. So here we would be creating the uh manifest for the service. So API version API version for service is nothing but v1. Then kind. So kind is nothing but service. Then API version kind. Next is metadata. Inside metadata, we will give a name to the service. What is the name of the service? So since we are creating the service for back end, I will name it as back end service. And lastly, we will need to define the name space. we will use the exact name space that the deployment is utilizing so that all the resources are falling under one scope. Next we need to define the specification the settings the configuration for this 28:04:44 specific service right. So again uh we will define the service type. So here we have already learned about services and for this specific de demonstration we will make use of the service type as cluster IP. Next thing that we need to define is we need to define the selector. selector. Now again selector will be again the same thing that we have defined earlier. Here it should target the pods where the label is app back end. And lastly we need to define the port on which that service will run. So port for this specific services. This service will actually run on port number 80. And again the target port where the application is actually running is port number 80 itself. Escape wq. Let us clear the screen and apply the file cube cuttle apply - f pack backend. Mamel. Now again here since deployment was already existing there it says that deployment is actually unchanged. But since you have added a new resource that is the service that service is actually 28:05:45 created. Let us verify the service too. So cube ctl get svc for service in the name space network policy demo. Enter. And here you can see the backend service is actually up and running. Right. So here uh we have created everything. Now the last thing that we need to do for performing this hands-on is we need to create a client pod right. So here this client pod will actually send a request to the back end and here we will make use of busy box because it provides a lightweight command line networking tool for our demonstration. So how do we create it? So basically it will be very much easier. This time we would be doing it with the help of the cube cut command line commands. So let us create the client pod. So cubectl run here you need to provide the name of the pod that is nothing but client. Okay. Next thing that you need to provide is the image. So okay now for the pod you have given the name as client. Now what image it should utilize. So image is nothing but vy box. So hyphen image image equals to 28:06:48 vy box. So here you can make use of any tag that you wish to uh here you can even make use of busy box latest. I will make use of busy box 1.36. Then you need to pass the label that it should be like then you need to pass the label that will act as a metadata for this one. So hyphen labels label is what basically here I will pass the key as app and the value for this specific one would be client. And next thing we need to pass the restart behavior. So hyphen - restart and restart equals to never. And lastly we need to pass few commands. So command and here it should actually start a shell where it is actually making sure that the container is up and running for 3 6 0 seconds that is 1 hour. Okay. Now enter. And here it says there is an unknown flag. Let me just verify the same. So here we have passed hyphen 28:07:49 edge. There should be one space over here that I missed. And now it says that client pod is actually created. So here uh what exactly we are doing? Um basically we created a pod by the name called client. We made the use of the image called busybox 1.36. We assigned the label as app equal to client. We added the restart behavior. And we are making sure that this container is up and running for 1 hour. That is exactly what we did. So here uh because we set the default name space earlier this time we didn't have to specify the name space. Right? So let me just verify the resource. So cubectl get pods. Again when you run over here you'll get the uh pod which is present over here. Now again here we are not using the default name space. If I do hyphen o wide. Okay. clearing the screen. Uh let me just run cube cuttle get pods - a. And when you run cube cuttle get pods - a you can see that the 28:08:51 client is actually created in network policy demo name space and the back end uh pod which is managed by the deployment is also created in network policy demo. Right. Clearing the screen. Now the initial thing is done and we are actually good to start with the actual hands-on where we would be testing the communication uh before the network policies are imposed. Right now uh what is the first thing that we would be doing over here right so let's send an HTTP request from the client port to the backend service. So for that uh what we would be doing uh let us run cubectl exact uh name of the pod that is nothing but client and here uh I will just run hyphen - wget and here - qo now here you will need to pass the name of the service http/ what is the name of the service that we are using that is nothing but back end service enter and here we are getting an 28:09:52 error again I need to pass on space after hyphen. Now it should be good. Here it says uh busy box 1.36 multicol binary. There is an error that I'm getting. Let us verify the same- o for the file. Uh okay, I need to pass one dash after it. So after qo I will pass one dash and now we should be good. So here what exactly we are getting? We are able to see the engineext welcome page in the output. Right? So what exactly this confirms? This confirms that the client can communicate with the back end through the service that we have created. Now why we are using backend service instead of the pod IP? Because service provides a stable name for accessing the back end uh for the specific pod. Why? Because even if the pod is dead, the deployment will make sure that another pod has been responded. But again on what basis we would be doing the communication 28:10:53 basically it's the service because that's the main purpose why service was actually created why it was designed at this point we haven't created any network policies. So therefore the test connection is actually established and that was the basic thing that we want to check before even we implement the network policies. Right? So now since we have demonstrated this specific section, let us create the ingress deny policy. Right? So now we are assuming that our backend application should not accept incoming connections from the other part unless we are explicitly allowing them. Right? So for that we are going to create a network policy that isolates the back end from the income traffic. So clearing this screen. So here uh what we'll do uh so here what we'll do we'll create a network policy that will isolate our backend deployment backend service from the incoming traffic. So for that I will create a file. So vim deny - 28:11:54 back end press dot camel enter. Again here we would be using the four golden keywords that we have been using so far that is inter mode API version kind metadata and lastly we need to define the spec. Now again API version we are not aware but we are aware about the resource that we want to create that is nothing but network policy. So network policy now again in the metadata let us define the name of this network policy. So what will be the name? So here since we want to define the rule where it is not allowing the incoming traffic. So here I'll type deny - back end ingress. This would be the name of the network policy that we are actually creating. Correct. This this is not this supposed to be net w. Okay. Now the next thing that I will be doing is I will need to define the name space. So name space is the place where this resource will created. What is the name space 28:12:55 name? What is the name space name? It is network policy - demo. Now in this specification I will need to define the configuration for this specific network policy. Here we will need to define the pod selector. Now why pod selector? Because because of this specific section we will tell them that on which specific port it is allowed to accept the traffic from. Okay. So in the port selector I will define it should search for the matching labels. So match labels and here the concept of labels and selectors actually comes handy because if you have a good idea of what exactly labels are and what exactly selectors are things will eventually make sense. Right now here I will define the policy type and inside the policy type here we are dealing with ingress. So hyphen ingress after that you will need to define 28:13:55 as the label ingress with the square brackets. So here let us understand the configuration. So here the first configuration that we are making is the policy type is ingress. So this tells kubernetes that the policy is applying to the incoming traffic because here the policy type is ingress. Later for the specific demonstration we are using ingress. Later we would be doing the same with the aggress also. So here we are defining the ingress as the policy type. So here what exactly we are denoting this will tell cubernetes that the policy is actually been applied to the incoming drop. Then uh here next thing what we have done we have defined an empty square bracket. This defined an empty list that is allowed in ingress. So in under the so if I put it into simpler terms this policy does not allow any incoming connection by itself to the selected ports right let me clear the screen and the initial thing that we need to define over here is in the deny backend ingress we want uh we haven't 28:14:57 specified the API version so let me just find the API version for network policy so cubectl API resources and I'll do a gra on network policy enter and Here you can see for network policy we have the API version as network. A8s.io/v1. So this is the place where we get the network policy API version. Yep. This is the exact place that we were looking for. Copying the same. Let me go back to my deny back end. And here I will update my API version. SK WQ. Let us apply the file. So let me just type cubectl. apply - f cli back ending.ml here there is an error what exactly it is here it says in the network policy there is an invalid value that we are getting here here it says unsupported value okay I got the issue here basically we were supposed to write the ingress with I caps and we 28:15:59 wrote it in lower case right so here this is the value that it is expected okay no worries we'll again go back to the manifest file that is deny back end ingress and here this is the exact page where it is asking us to update the value for I'll remove the existing values I'll update it with the one that has been suggested by the error itself now I think things should be good and let us verify the file and just apply it so cubectl apply - f deny backend ingress enter here you can see network policy networking k-io/deny backend and service ingress is actuallyed we should be good. Let us list the policy that we have created. So cubectl get network polytor and here you can see that the policy is created and here we have defined the port selector app equals to back end. Right now once this policy is created uh 28:17:00 uh we are good to start with the test connection. How we can perform the same? Basically we will again make use of the client that we have created. So cubectl exact uh client and in the client we will run hyphen wget and inside that I want to run - t 3 - qo again don't forget to pass this dash and then pass this service name http/ backend service enter here you can see uh the request is been stuck and now it got failed why because the back and ingress does not allow the incoming traffic. So previously if you remember we were able to do so. Why? Because at that time we haven't defined any network policy right. So that is our first practical demonstration of network policy enforcement. But uh here there is a question uh let's say we have a requirement and what if we want to allow the trusted client application to communicate with the back end and it 28:18:02 should actually block the other application which is trying to communicate. How we can do that? So for that uh we can create another network policy. So here what we'll do we'll create another uh network policy where it will allow the traffic from a trusted client. Right? So uh I hope you got the initial thing where we we were actually defining a condition where it should create the uh application as an isolation and it should not accept traffic from any pod. Now what we want it should continue doing the same but it should actually leave a pod where it is uh where we are saying that it is an authorized one. So clearing the screen and let's create a policy that allows the incoming HTTP traffic from the pod which have a dedicated label. So here we will mark that pod the label as app equals to client. So when allow - client - ingress dot camel again I will define the four golden keywords. Before even that what I will do I will just copy the 28:19:04 file. Copy the deny ingress file to the allow client ingress file. And now here we would be making the changes. So now here we have the API version. We have the uh kind. We have the metadata here. Instead of deny, I will replace it with allow. Allow backend ingress uh back end ingress. Allow client ingress and the name space would be the same. Now here in the port selection uh we will be matching the labels where it can app equals to back end. Then here we have defined the policy type as ingress. Now here we need to define the rules. Earlier we kept is empty but here we want to define uh which pods are actually allowed the traffic from. So here ingress basically in ingress you will need to define hyphen dash and it should allow the traffic from those pods right where the uh where we would be making use of port selector and here that port selection 28:20:04 would be done with the help of the labels. So it should match the labels where the value is nothing but app colon client. Then lastly we need to define the port. So here I will define the port here ports. The protocol should be TCP and the actual port number. Okay. Escape colon. Let me just apply the file first. cubectl apply - f allow client ingress and here it says the ingress is created. Now let us understand what exactly this file does. I'll do a cat over here. The basic thing is we made the changes from policy types to this specific section. Let us understand what this specific policy does. So here you can see the pod selectors. What exactly it does? It will select the backend ports where the label is equals to client. So 28:21:05 here we are allowing the ports with the label. Right? The port selection restrict the allow traffic to port number 80 because we haven't specified the nameace selector. This port selector basically matches the pods in the same name space as the policy. So uh now we have uh so now we have the clarity about this specific manifest. So now there is one more important concept that you should keep in mind when you're dealing with network policies that is network policies are addictive. So what do I mean with this? Basically all policy doesn't override the cancel allow policy. The deny policy basically contributes to no allowed ingress while the new policies allows the connection from the pods which is coming from the port number. Right? So now let us verify that the trusted client here now can actually connect or not. Clearing the screen. Uh now let us run the same command cubectl exact name of the plot 28:22:05 is nothing but client. And here I will run the command hyphen f get -o along with a dash http col // the service name is back and hyphen server the rv enter and again now here you are able to see the engine welcome page this is great why because the client now can communicate with the back end because it is matching the label that is specified in the allow policy right so now let us check whether the another application can also access the same back end. Why? Because initially we wanted a condition that it should uh deny the traffic from all the existing pod except this specific one. So here we are actually able to uh view the page. Now let us try it with another pod. So here uh let us create one more pod. So cube cuttle run untrusted client. We will use the same image that is hyphen image equals to busy box. Uh the 28:23:09 version will be again same 1.36 I think you will need to define this time we would be using different label right that is app. So here uh we were uh earlier we were using different label this time we will use um unfiltered so or untrusted so untrusted. Now we will need to define the restart policy. So restart equals to number and then you will need to define the command that it should run. So - command - sh - c then this is the command that will make sure that our pod is actually running 6,000 and here the unrusted client is actually created. Now what was the purpose? We want to actually check whether this client is able to access the pod like or trusted client right. So how do we verify the same? So just run cubectl exact untrusted client then hyphen -q get - 28:24:12 t because we want to try this three time hyphen qo then name of the service http col// back and hyphen service enter here it will try three times and here it is actually failing why because our ingress policy allows the traffic from the label LED resource and that labelled resource was nothing but app equals to client. Here the label that we are using over here is nothing but app equals to understood. That's the reason we are not able to connect to the connect to the pod. So now we have demonstrated an important security principle that we can allow communication from the selected pods while blocking the other sources. So far uh we have been focusing on the incoming traffic on the back end. Now let us discuss and demonstrate about the network policy that is the second option that is nothing but aggress. So now uh before we start with the agress uh let 28:25:12 us uh revisit the difference between ingress and aggress right you remember the documentation that I showed earlier that it was pretty much clear what is the difference. Let us discuss about it. Right. So our previous policies controlled which part could send the traffic to the back end. uh those were the ingress rule because we were controlling the incoming traffic to the back end. Right now we'll control the outgoing traffic from a pod. So for this specific demonstration we'll use the existing client port that we have created and the extra thing that we would be doing in this case is we will create a very small TCP server that will represent a database endpoint and it should listen on port number 5432. Right? Then what we are going to do, we are going to configure a address network policy that allows the client port to communicate uh with the database endpoint uh to the TCP port that is 5432 while blocking its connection to the back end. So there is one more clarification that I want to do is uh 28:26:12 we'll use a lightweight Python to demonstrate this network connectivity and this is not a real database right. So let's actually implement it right now. Uh let us create a manifest file for the same. So clearing the screen. This time we would be creating a port. So I'll just type them uh database. Now again four keywords API version. Next is kind metadata. And lastly we have this spec. Now what exactly we are trying to create? We are trying to create a port. What is the API version for pod? that is this we can get from API resource get it from cub is method document now again what would be the name of the specific part uh now since we are dealing with database I'll just type database this will be the name of the port that we would be uh interested in and the name space so name space uh here it should fall under network policy - demo okay and now we will need 28:27:14 to define the labels so here the label would be app colon data database. So the initial thing for the metadata is clear. We have given the name for this part as database name space where it will create the resources network policy. We have defined the label for this big resource. Now let us define the configuration for it. So this pod will run the containers. The name of the container would be nothing but database server. So name database - server. Now here next thing that I will need to pass is the image. So which image it should use for creating that uh specific server. So here we will make use python of python alpine image. So python col 3.12 - lpine. Now there are few set of commands that we need to run. So now what are those command? Basically those are the python command that will actually help us to create the TCP server. Right. uh let me go to my manifest uh to my document where we have 28:28:16 everything present. Let me just take the argument from here because that will actually save some time and don't worry I will explain you each and so these are the arguments that I'm referring okay and let us update this let me just do a move here and we are good now skip two now let us apply the file cubectl apply f database here you can see the pod is actually created and the pod that we are creating is a database Right now uh once this is done uh the next thing that we would be doing is we will be verifying the ctl get pods enter here it says that it is in container creation phase now let us give it some time wait until the database pod is running and then we will check the logs of the database right so let us wait okay so now let me clear the screen let me run cubectl get pods - o white enter and here you can See the database pod is 28:29:18 also running over right now. Uh let us check the logs for this database. How we can check the same? Just write cubectl logs database. And here you can see that demo TCP server is on port number 5432. The exact message that we wanted to print. Now let us test the connectivity before applying the agress rule. Right? So before restricting the outgoing rule, let us establish the baseline. So first we are going to get the IP address for the database port. We can get that. So basically we are going to uh store that into the variable. So let me just define the variable as DB IP. This is the variable where we would be storing the IP address for the database. Right here for that I will need to run the command. How we can get that? the same cube ctl get pod in the uh and the pod name that is database and here oen put in JSON here I will pass the JSON path and here 28:30:21 inside that pass the status pod ip single quotes that is I will need to pass the confus dot pod ip let me just run this command manually before we store it into cuz that will eventually let me paste it over here. Right. So cube cut get pods JSON path status.pod ip I need to close the code close here. Okay. And we are getting the output over here. But we are actually interested in basically getting the pod id here command. What exactly we ran? U get pod name of the pod is database. Then output for the JSON path. Here we are checking for the dot status dot pod ip. Enter. Here we are getting the IP that we want. 28:31:21 Now what we'll do? We'll just store it inside the uh variable that is database id here password dollar and we are going to run this command exactly the same format that we have right now what will uh this do this will actually help us in storing the IP address into a variable uh for this backend port. So now uh once this press enter now when you do an echo on dollar db IP you will get the database and this is how exactly you can get right likewise we are going to get the IP address for the back end how you can get it. So basically the uh information remain. So here instead of uh db ip we will make use of back end ip as the variable where we would be storing the uh variable for so here let me just copy this entirely here the only change that we need to make is I will just run get mod and here we will 28:32:24 list that p with the uh label that is app equals to 10 and then we are going to print the IP address with the help of dot item. So into the zero element dot status dot enter. Let me just do an echo into the variable that we have created so that we can verify whether the IP address of the back printed or not or stored or not. Right now we can see the IP address for the backend service for the back end port the IP for the database that we have created that is 10.244 244.934. Right? So this initial thing is done. Now once this is done, let us test the database like a TCP server from the client port. We can test the same just type ql exact name of the client port is nothing but so here we will need to uh you know pass the uh database IP that we are. So hyphen - network count and here 28:33:26 - w3 because we want to try three times pass the IP address that we have stored where is the IP address for DB stored in DB inside that we need to pass the port number 543 that's it I press enter you are seeing that we are getting a message as database TCP right so this actually confirms that the client can connect to the TCP server on the port that is nothing but 54 that is nothing but 5432 right now uh let us test the back end directly using the pods icon right so here just run cubectl exact client pod and here inside that we run at - then we'll pass the uh back end IP for the port so col// dollar back end ip that's it when I 28:34:27 press enter you can see that we are able to see the welcome to engine exp so here we can follow to the conclusion that both the connections are actually working before we are introducing an aggressor right so now let's restrict uh so now let's restrict the client's outgoing traffic how we can do that for that we going to create a manifest file so vim client and aggress policy m again we are going to define the four keywords that are actually been useful for almost all the many file that we have created so far that is API version kind data and lastly is this okay now API version we'll fill it later uh what exactly is the client for the specific address I'll just type network because agress falls under a network policy uh network and here in the metadata I will need to 28:35:28 define the name of this policy here I'll type the name asphress - t this is the name of the uh network policy that we are creating now here I will need to find the name space where this policy will created so that name of the name policy memo this is the name space that we have created initially. Now let's write the actual crux that is the settings the configuration for this network policy. Here we need to define the port selector. Write the port selector. You will need to match the labels which has the dedicated client name. Here match the labels for the ports which has the labels app colon. Then we define the policy type. So here we are dealing with the policy type as so here I'll just write types and then uh you will need to define the 28:36:29 port selector for aggress here inside the poly types you define to the ports where it match the port selectors with the table. So matches where the pod has the label as appent database. So here we are restricting the connection from inward to out. And now let us define the port for the same ports with the protocol as TCP. Okay. And then we will need to define the port number. So this specific database actually runs on port number 5432. Skip colq. Let me clear the screen first. Let me apply it. cubectl apply hyphen app and digress policy. Here it says there is an issue with my ML file did not expected hyphen uh okay let us fix this into the visual studio code and here 28:37:31 client agress policy I'll just go here. So here code port should go somewhere here and I think now we should be good. Let me just uh update the same to my here I now here it says uh API version is not set. Okay, let us get the API version. So cubectl API - resources. Let's do a grab on network policy. Enter. And for network policy basically we will version I'll update the main file now. And here I will paste the API version. Now let us apply the file cubectl apply fress. And here it says it's a bad request and network policy not be uh handled as policy strict decoding error unknown 28:38:32 field as ports there is an here it says that this specific value is right I'll go to the insert mode and fix the indent right then we're getting the same uh let me just uh visual studio port because that will actually help us to troubleshoot right. Okay. So I believe I got the issue. Uh this port should be just just below to the two and because we are defining the agress rule and likewise this port should fall under ports. Now I think shing should be good. Let us switch to the terminal now. And now let us apply the file and see the clearing the screen and you will apply hyphen f. And now it says net policy networking ks.io client agress policy is actually created for us. And good but before even that let us verify the resource. So 28:39:33 get network policies and here you can see a client agress policy is actually created right. So we have both ingress and agress policies in our name space. So now this time let us check what exactly right. So let us first connect the database like an end. So for that qtl exact of client uh c network count for the database to dollar and this database actually runs on port number 543 and here it says that a database TCB connection. Why? because uh our agress policy explicitly allows the client pod to connect to the pod but the label data is nothing but uh basease that is that is actually running on port number 543. I go over here here we actually allowing the labels here we are actually allowing the client where the so here so here you 28:40:37 can see the label that we have utilized is app equals to database so that is the reason we are able to uh actually run this command right so now let's take check the uh connection to the back end right so clearing the screen and now let me run ctl x I will get - T - Q O time and we will do the same but this time we would be doing with the back end http col here. So uh this time you can see it is tagged. Now it says that it is failed. Why? Because uh you can see so you can see actually we are getting this termination error. Why? because the agress policy allows the client to connect to the space uh like an end point uh to the port that we have but it does not allow the client to connect with the back end which is running on port number. So uh therefore here we can 28:41:39 come to a conclusion that the connection to the back end is actually blocked by the client policy. So here you have to remember that our back end also has the ingress policy that allows the traffic from the pods which are labeled as app which runs on port number 80 but the permission doesn't allow override to the client's agress. So for a new connection to succeed the pods application policy and the destination pods applicable ingress policies must permit the con. So basically that's why this connection got failed. So here the key takeaway from eress demonstration is we are allowing the incoming traffic at a destination that doesn't automatically permit the outgoing traffic at so we have demonstrated both the sides of network enforcement. Now let's take a quick recap. So now let us discuss about the key takeaways that we have been that we have done far. So let me just open 28:42:40 the readme.md file. Don't worry this file will be present into GitHub repository when watch on this. So basically today uh we learned about network policies and specifically we learned about two network policies that is ingress and address. So basically what exactly is ingress policy. The ingress is something that allows the incoming traffic to the pod and secondly aggress basically it controls the outgoing traffic from the pod selected by the I hope this actually made sense for you because network policy enforcement depending uh because uh I hope it made sense because network policy enforcement depends on the networking implement that's why we used calico for this specific and yes one last thing labels and selectors are also very important when you're working with networkities. Even if there is a small mismatch in a label, you can actually change the traffic that is actually allowed. So yes, that was all in this video and I will soon 28:43:41 keep learning. Thank you very much. Hey everyone, welcome back. So if you have started learning Kubernetes you already know one thing that is in order to deploy anything you write files and literally a lot of YAML files. Let's take an example that you want to run an application. So for that basically you will write a deployment YAML and to let other things talk to that application you write a service YAML and if your application require configuration then you create config map secrets and maybe few more Kubernetes resources. Right now imagine that you have a real project with many application and suddenly you are actually looking to dozens of YAML files. Now the challenge is keeping them all updated and deploying them correctly gets really hard, right? So here's the question is uh is there any simpler way to manage and deploy these applications on Kubernetes? Well, yes there is and that is where Helms comes into the picture. So in this video we are going to learn about Helms from scratch. First 28:44:42 we are going to understand what exactly Helm is, why was even it created and then we are going to look into Helm charts. Basically we are going to look into the charts, values and templates. So these are the three ideas everything else is built on. And don't worry if you are completely new to this. I'll explain every command, every line of the YAML in very simple language. So basically you will be able to get complete things and Helm will make sense to you. Right? So on that note, let's get started. So before even we start with them let's understand the problem that it solved because once you feel the problem then the solution will make more sense for you right. So let's say you want to deploy a very simple application on cubernetes for now let's take an example of engineix right which is one of the popular web server. So what we'll do first we will create a deployment yl and this file will tell kubernetes which container image to run how many copies we want or how many replicas we want right and how the container should run. Then we are going to create a service 28:45:43 ammo. So here pod can come and go but their IP address will change right so service will give them a stable address so the other application can always uh reach out to the engine right and if our application needs some sort of configuration then we'll add a configuration map that is config map 2 right so even for a very small application we already have a three separate YL files right now let's make things very realistic let's say you are in a real company so here We don't deploy everything at once. We deploy the same application to different environments. That is we have development, we have staging, we have production. So in development maybe one replica is enough and in staging we want two and maybe in production we want five. Right? So what do we do? Uh do we copy every ML file three times just to change one single number? Uh basically we can do it. But look at this like 90% of these files are exactly the same. We are copying them just to change one 28:46:45 value. Right? And here is the main thing which really hurts. Right? Say we need to update the image version. Now we have to remember to change it in the every copy. Now if we miss one file so basically the production will run something very different from what you actually tested. What we really want is simple. Write the ammo once then for each environment change the values that are different. And that is exactly the problem Helm helps us to solve with. Right? So now what exactly is Helm? So the short answer for this one is nothing but Helm is a package manager for Kubernetes. If that sounds like a jargon, so don't worry about this. Let us understand it with something probably you have used with earlier, right? So if you have used Linux, then you probably have installed software with the package manager. For example, on Ubuntu, you type a install and the software's name. So you don't manually download every file and you basically don't copy the configuration into the folder and set 28:47:46 everything by hand. Basically the package manager does that job for you. It knows what belongs to which software. It installs it. It upgrades it and it can remove it cleanly. So Hen gives us a similar experience but for the application which are running on Kubernetes. So instead of handling a big pile of separate YAML file, we organize them into one package. In H that package is called as a chart, right? With H we can package our Kubernetes resources. We can configure them, install them, we can upgrade them and even we can roll out to the previous older version uh just in case if something goes wrong, right? So here's the simple definition is uh that I want you to remember is Helm is nothing but a package tool that makes our life easier to package, configure, deploy and manage Kubernetes applications. Right? But again there is another question that might lie on your mind that is uh is Helm same as Kubernetes or is Helm a replacement of Kubernetes? Basically the answer is no 28:48:47 not at all. They two are very different. They do a very different job. Kubernetes is a platform that actually runs your containers. It creates your pods. It restart them if they crash. It scales them. It manages the deployment services and all the other objects. Hem doesn't run any sort of containers. It is a tool that helps you to install and manage the application on that specific platform. So here's what exactly happens when you install a chart, right? Hem takes the template inside the chart and fields your value. The result is a normal Kubernetes YAML. uh the same kind you would write by hand hence and then to the YAML to the Kubernetes API from that point Kubernetes takes over. So it creates the pod. It keeps them running and does everything normally it actually is supposed to do. So remember this hem is not a replacement for Kubernetes. It makes working with Kubernetes very much easier. So now let us understand the most important idea in Helm that is nothing but the chart. You might have heard about the term called Helm chart. Now what exactly is a Helm chart? So a 28:49:49 Helmchart is simply a collection of files that describes how to deploy an application on Kubernetes. That's it. It's not a magic. It's a folder with particular structure. Now let's look at three most important part. First, a chart.yamel. Think of it as the chart ID card. It holds the information about the chart itself such as the name and the version. Second, we have values. Mamel. So this is the setting file. It holds the default configuration values. uh for example how many replicas, which image, which port and so on. Third, we have the template folder. This holds the Kubernetes YAML for resources like the deployments, the services, but it is not fixed. These are the templates which means they have blanks that get filled by using the values from the values. So the whole idea in this is templates plus the values goes into the HL and outcome of the final is the cubernetes YAML. So now let's take an small example. So imagine that our value.yamel looks like 28:50:49 this. So here the replica count is two. That means we want two copies of our app running. Under the image the repository is enginex and the tag is 1.27. So we want engineix image the version as 1.27. And under service the port number is empty. Now here is a small piece of deployment template. Now look at this line. Normally you'd write replicas colon 2 directly but here instead of writing the number two we have written dot values dotreplica count inside the double curly braces. Let's read it piece by piece. So the double curly braces tell helm that this is a blank fill it in for me. Then the dot means that look at inside the values and the replica count is the exact key we want. So when helm runs it replace that blank with the real value that is true. The final deployment that reaches Kubernetes simply says the replicas S2 right now here why it is so powerful. Now remember our problem with the development staging 28:51:50 and production. With Helm we keep one template for each environment. We just provide different values. One replica for dev, two for staging and five for production. Same chart different values and no copy paste. So we don't maintain separate copies for the whole deployment YAML anymore. We just change the values and honestly this is one of the most biggest reason why we should consider ham in the very first place right so now before we jump into the terminal there are three hem words you'll hear every time that is chart release and the repository let's make them crystal clear uh because we are going to use all of them in this specific hands first the chart we just covered this a chart is the package it contains everything needed to deploy an application the charty camel the values and the templates. Think of chart like a recipe. It describe how to make the dish but it is not the dish itself. Second we have release. So a release is what you get when you actually install a chart into a 28:52:51 cluster. It's a running install copy of that chart. Going back to a recipe, the chart is the recipe and the release is the dish you actually cooked. So when you install a chart, you give the installation name. If we install engineix chart and call it my engineix then my engineix is the release name for us and from then on we will use that name to manage it. We can upgrade my engineix check its status see it history and we can even do the roll back. So here something important is there you can install the same chart many times with different release names. For example, engine dev and engine staging uh and all of these can be happen with the help of just one chart as long as they don't clash with each other. Hm tracks each one of them completely as a separate release. So here the thing is we have one recipe for multiple dishes. Right? Third we have the repository. So a hm repository is a place where charts are stored and shared. It's like an app 28:53:53 store for the charts. Right? teams and the open source project publish the charts to this repository. So you can find lot of them into the artifact hub. You can add a repository and you can search it. You can even install chart from it. So without even writing the YAML file yourself, you can do all of these task. Those command looks like this. But today we won't install someone else's chart because here we are going to create our own chart from the scratch locally. Why? Because when you built it yourself, you understand what Helm is actually doing. After that any chart from any repository will actually make sense for you. So a quick summary a chart is the package a release is a installed copy of it and a repository is a place where the chart are being shared. So all right enough theory has been done. Now let us open our terminal. So for this specific demonstration we'll use mini cube. So mini cube runs a small single node cubernetes cluster right on your laptop. So it is a perfect for learning setup because you can break things and nothing bad will happen. First we are going to check that helm 28:54:54 and mini cq bar are ready. Then we are going to create our own chart for engineix and we'll write every file ourself. Our chart will run to engineix replicas and then we are going to expose them with the kubernetes service. Then we'll check the chart. We are going to install it and we are going to open engineext in the browser and after that we'll upgrade from two replicas to three and finally roll back where we started. Okay. So the first thing that we need to check is we need to check whether the Helm is installed or not. Right? This command prints the Helm version installed on your machine. If you see a version number uh you are good. Hem 4 is currently the major version. If you are on Helm 3 everything in this video works the same way. If you get command not found then Hm is not installed yet. So you have to pause here and you have to install it. I have put the official documentation of the installation link. You can check that in the description section into the resources section. Right. Next, let's check the mini cube. This shows the installed mini cube version. Uh your exact number may be 28:55:56 different from mine and that's absolutely fine. Now, let's start creating our cluster. Mini cube start. This creates and start a local cubernetes cluster. The first time it can take few minutes because it downloads what it needs. Look at the last line. It says cube cuttle is now configured to use to the mini cube cluster. Now remember that line because it is important in a second right. So let's confirm everything is healthy. So here you can see the host is running the cubelet is running the API server is running and the cube config is configured. Perfect. Now cube cuttle get nodes. So this will list the machine in our cluster. Mini cube gives us one node called mini cube and its status is ready. So our cluster is up. Now one small but very important check. This shows which cluster cube cut is currently pointing to. It says mini cube which is good. Why does this matter to Helm? Because Helm uses the same cube config as cube cutle. So whatever 28:56:57 cluster cube cut is pointing to H will install into it. Right? So if you have access to real company cluster at work, always run this check first. You don't want to install a practical chart into a production by mistake. Our node is ready and we are pointing to cube. So let's build our chart. Right. Let's start by creating the folder for this specific tutorial. So everything stays in one place. So mkdr makes a new folder called helm - beginner demo and cd moves us into it. Now uh the first real help command helm create makes a brand new chart for us with a readym made folder structure and some example file and hello app is the name we are giving to our chart and says creating helm - app. Now we have the folder with that name. Let's look inside it. ls - r. This lists everything inside the folder including the subfolder. You'll see three parts we talked about that is chart. values.ml 28:57:57 and the template folder. Inside the template, Helm has created a lot of example files such as an ingress, autoscaler or service account, some helper and test files. But they are good to study later but right now they will be confusing us. So let us delete them. Uh and we just only need the deployment and service right now. Okay. So this removes everything inside the template folder but keeps the folder itself. So one word of caution over here is rm - rf deletes without asking. So make sure you are inside the helm - beginner demo folder before you run it. So now let us create the chart. Mamel open it in any editor you like. I'll replace everything in it with this. So let us understand line by line. First line API version v2. This tells which chart format we are using. V2 is the standard format for the modern Helm chart. You'll see this in almost every chart today. Line two here we have some. So in line number two we 28:58:57 have name. This is our chart's name. Hello app. It should match your folder name. In line third we have description. So it is just a short uh description explaining what this chart does. It is for us human. So we have to make it very much clear. On line four you can see we have something called type and the type is nothing but application. This says the chart is meant to deploy an application. Then we have version and the version is 0.1.0. This is the version of the chart itself. Uh that is the package. And next we have app version that is 1.27. This is the version of the application inside the chart. In our case it is enginex 1.27. Now these two versions confuse a lot of people. So let's make things clear. Version is the version of the box. App version is the version what's inside the box. So if I change something in my template, I bump the chart version. Even though engineix is still 1.27 and if I move a new engineext version, the app version changes. Save the file. Now we 28:59:58 have values.l. So now let us create a new file called values.l. And this will be inside the new folder that we have that is hello. So open hello app and inside that create values.l and created a big example file there. Delete everything and replace it with this. So what we have over here first we have the replica count as two. So we want two engine spots running. Next we have is image. Notice that the lines inside it are indented with two spaces in the yl. That indentation means that these settings belongs to that image. So we have image.reository image.tag image.pool policy. Always use spaces and never use tabs whenever you are dealing with YAML because YAML is very strict in the indentation. Next we have repository. Repository is engineext. That's the image name Kubernetes will pull. Tag is 1.27. And notice it's inside the quotes. That's on purpose. Without quotes, YAML might treat 1.27 as a decimal number. Uh that doesn't sound like a problem until you have version 29:00:59 like 1.10. As a number that becomes 1.1 which is completely different image. So quote your version tag. That's a good habit. Pull policy if not present. This means that image is already on the node. Kubernetes uses it instead of downloading it again every time. Next we have pull policy if not present. This means if the image is already on the node, Kubernetes uses it instead of downloading it every time. Next we have container port and the value is 80. That means that engineix runs on port number 80. So here we have defining the port number for the container. And finally the service setting. Uh the type is cluster IP which means service is reachable only from inside the cluster and it listens on port number 80. Now here is the key idea. Uh these are the default values. Uh when we install or upgrade we can override any of them without touching the template. We'll actually do that later in this video. Save the file. Now here is the most 29:01:59 interesting part that is the template. So inside the template folder create a file called deployment.yamel yl and add this. Don't worry, it looks like a lot, but we'll go through it line by line and mostly it's a normal Kubernetes yl. So here we have API version app/v1 and kind deployment. Uh this is plain kubernetes. We are telling kubernetes I'm creating a deployment. Uh nothing helm specific here. Now our first helm is blank. The name of the deployment isre.name followed by hyphen deployment. Sore is a built-in object that helm gives us. It holds the information about the current installation and dotre.name is the release name uh we choose when we install. So if we install it with the release name called my engineix this line becomes my engine deployment. So why to do this instead of having a fixed name because then we can install the same chart twice with two release name and name will never clash. Next we have 29:03:01 labels. So labels are like sticky name tags on the Kubernetes object. Uh we are going to add label called app.cubernetes.io/instance set to the release name that is the standard recommended label in Kubernetes which is why we are going to use it. Now here we have replicas. It comes from dot values.replica count and dot value means read the value from values.yamel. Our default is two. So by default we will get two replicas. Now look at these two parts together because this is the uh place where mostly we'll get uh things wrong. Now look at these two parts together because this is the place which creates a lot of confusion. So here the selector says the deployment manages the pod with this label. And down there in the pod template, we put that exact same label on every pod it creates. They must match. If they don't, the deployment can't find its own pod and Kubernetes will reject it. Since both use the release name they always match. So under the port spec will list our containers. 29:04:04 The dash means uh this is an list item. We have one container and we have named it as engineix. The image line has two blanks. Uh the first is dot values dot image.ository which is enginex. Then a colon then dot values dot image.tag which is 1.27. So the final result is engineix 1.27. uh we wrap the whole thing in quotes. So the result is always treated as a plain text image policy. So so basically this comes from dot values.image.pool policy which is if not present and finally uh the container code that comes from values.container port which is empty. So in simpler words this is a normal cubernetes deployment except the parts that might change are blanks and fills those blanks from values.l AML and the release name. Save the file. Our deployment creates the engineix pod. But pods come and go and their IP address keep changing. So we will need a 29:05:05 service. A service gives our pod a stable name and address. So create a file called service.ml inside the template and just add this. So here we have API version. So the client is service. Again it is a plain Kubernetes that we already know that we have already studied. So here we are creating a service. The name uses the release name again. So for my engineext the service will be called as my - engineenix service. The same instance label as before. So we can easily see uh which release this service belongs to. The service type comes from dot value. Our default is cluster IP because it's a value. We could uh switch to something else later without editing this file. Uh then we have the selector. This is how the service finds it pods. It sends the traffic to any pod with this label. And remember our deployment puts exactly this label on its pod. So the service and the ports are connected. And then finally we have the port. Port is the 29:06:07 port that service listens on that comes from the service. Which is 80. Target port is this uh target port is the service where the traffic has been sent to the port. So that comes from the container port also which is 80 which is where engine is actually listening and the protocol here is TCP which is what web traffic uses. So now save the file. Let's look at to our chart one more time. Chartl is the ID card values.ml is the setting and in the templates we have these two files that is deployment and the service. That's a complete working health chart and uh you wrote every single line of it. So now let's check it before we install it. Right? So before installing anything uh let's make sure our chart doesn't have mistakes. Helm has a command for exactly verifying whether there is any mistake or not. So for that we are going to make use of helm lit. So helm lit checks the chart for common problems like broken yl 29:07:08 missing fields or template mistake. The dot / hello app is the path to our chart folder. So look at the last line, one chart linked, zero filled. That's what we want. You'll probably also see an info line saying that an icon is recommended. That's just a suggestion. A chart can have an icon picture, but we don't need one. Info is not an error. If you had a typo like broken indentation, lint would show an error. And here is where we can actually identify the problem. So, always use lint first. It saves really a lot more of time. Next, uh I have a command that I really love to use because it shows you exactly what Helm is actually creating. So, Helm template renders the chart on your machine. Uh my engineext is the release name. We are using it for this preview and do/hello-en app is our chart name. Now, look at 29:08:09 this. This is our template. But every blank is now filled. The name became my engineext deployment replicas is now two. The image is engineext 1.27. And if you scroll, you'll see the service with port 80 as well. This is the clearest way to see what Helm actually does. It takes the template plus the values and turns them into plain cubernetes. One more important detail, Helm template only prints. It does not install anything. Our cluster is still empty. All cluster is still empty. It's a safe way to check our output. Right now our chart is checked and we have seen the output. Now time to install it for real. So now here let's break this down. H install tells h to install a chart. My engineext is the release name. This this is the name we are going to use to manage the installation from now on. Hello app is where our chart lives. d-namespace 29:09:09 hello- demo says install everything into the name space called helm - demo a namespace is like a separate folder inside a cluster so our practice stuff says separate and d-create hyphen namespace tells helm to create the nameace if not exist so we don't have to create it ourself and there it is helm says or release my engineix is in the helm - demo name space and the status is deployed it and also notice revision col one. Every time we change this release, Helm will increase this number. So keep that in mind because we'll use it when we want to do a roll back. Right? So now let's verify. Let's check uh let's ask Helm what release it has. So Helm list shows the Helm releases in a range space. There is our my engineext revision as one. The status is deployed. And look the chart column says hello app 0.1 1.0.1.0 29:10:09 and the app version says 1.27. Those come straight from the chart. We wrote. So now you can see why those two fields matter. So here is everything our chart has created. One deployment called my engine deployment with two out of two already two pods both running. The random letter at the end of the names are added by Kubernetes. So yours will be different and one service called my hyphen engine service with the cluster type as uh cluster IP which runs on port number 80. Every name here come from the template from our release name. Nothing is hardcoded. So if your pods are saying that container is creating mini cube is actually basically trying to pull the image. Uh so just give it some time. So here you can see we have successfully rolled out our application is actually running. We didn't apply the deployment and service file one by one. We installed them together as one release and Helm now remembers everything that belongs to my engineix. Right? So now 29:11:10 let's actually see our uh engineix page. Remember our service type is cluster IP. That means it's reachable from inside the cluster but not directly from our laptop. So for a quick local test uh we can use the port forwarding. So uh this creates a temporary tunnel. the traffic to the port number 8080 on your laptop goes to the port number 80 of your service and uh now you open your browser and you can go to localhost col880. So when you are done go back to the terminal and press Ctrl C to stop the port forwarding now let's learn one of the Helm's best feature upgrading an application right so imagine our application suddenly gets more traffic so two engineix pods are not sufficient enough anymore and we want basically to make it as three so without hand we'll be opening the deployment yl uh change the number apply it again but here we have a chart So let's do it the H way right. So helm 29:12:10 upgrade changes a release uh that's already exist my engineext is the release we are upgrading and do/hello hello app is the chart and here's the interesting part dash set replica count equals three. So our values.ml still says the replica count as two but we haven't touched it. D- set puts a sticky note on top of it and says for this release use three instead. The backslashes at the end of the lines just means the command to continue to the next line. They make long commands easier to read. Right? So here, Helm rerenders the chart with the new value and sends the changes to the cubernetes. And look, the revision here is now true. The deployment now shows the deployment now shows three out of three. Let's see the pods. So here uh we have three engineix pods and all are running. two of uh two old ones and one brand new one. Notice we haven't changed anything. We haven't uh we actually didn't do 29:13:11 anything. We didn't edit the template. We didn't created a new ML file. We just gave Helm a different value. That's the power of configurable chart. Right? So now after few upgrades, do you know which values a release is actually using? So here helm can tell you. So helm get value shows the value that you that you supplied for this release. uh we are going uh we only supplied one thing called replica count as3 that's all we did and if you want a full picture including the defaults from values.ml then add dash all uh now we see everything the defaults from our values file plus our override the replic here the replica count here is three and everything else is default this is really handy when you are debugging and you just want to know how a release is configured Right now imagine that after upgrading we realize that this wasn't what we wanted. Maybe we changed a wrong value or maybe we just want to go back 29:14:12 to how things were. This is where HM really shines. First let's look the history of the releases. So Helm history shows every revision of the releases. Revision one was our initial install. Uh the status is now suspended which means a newer version has replaced it. Revision two is our upgrade and the status is deployed. That's the one that is currently running now. Right. So now let's go back to revision one. So Helm roll back uh then the release name that is my engineext and then the revision we want to go back to which is nothing but one. So Helm confirms the roll back worked and in the cluster Kubernetes removes one pod because revision one had two replicas. Right. So rolled out. We are back to two out of two exactly where we started. Now let's uh check the history one more time because there is something important here. Did you expect to see the revision one back on top? Basically most of us will but look Helm created a brand new revision that is 29:15:12 revision 3 and the description says roll back to one. Hm doesn't delete the history or travel back in time. It takes your configuration from revision one and applies it again as a new version. So you always have a full record of what happened and when in a real team uh this is really very valuable right and here is a quick bonus where Helm is storing all of this history. So let's dig into it. So by default Helm saves uh each revision as a cubernetes secret in the same name space as release. Uh see the names uh that is my engineix v_sub_1 v2 and v3 one for each revision. That is how Helm remembers the full history of a release uh right inside your cluster. You don't need to touch this. Just know that this is where Helm list history and roll back gets their information. Right now remember the problem that we started with the same application in different environment uh different settings and no copy paste. Let's actually solve that 29:16:13 now using the exact chart that we just built. So in real project we don't type dash set for every value. Instead we keep uh the override for each environment in their own value file. So in your helm uh demo folder uh next to the helm - app folder you can create a file called values - pro.ml and add this. So for production we want four replicas and we want to change the service type to node port. A note port is a service that opens a port on a cluster node so we can reach uh the app from outside the cluster. That's useful on mini cube. Uh now notice we only wrote uh what's different uh the image the ports everything else comes from the default values.ml and merge this file on top of the defaults right so same chart uh dot /helm app but a new release name enginex - uh - f means uh use this value file and we put it into its own name 29:17:14 space helm - broad now let's see all our releases in every name space so Uh here you can see two releases my engineix in helm demo. So here we have two releases my enginex in helm - demo and engineix plot in helm - broad and uh look at the chart column both come from the same chart hello - app 1.0.1 0.1 right and in Helm prodics pod running one chart two environments different settings that's the whole point of using helm right here and because this service is a notebook mini cube can give us the URL for it directly right so mini cube service find this service and prints the URL and you can open it on your browser your URL will look different from mine and that is absolutely fine one small note over here is on Mac and windows with docker driver mini cube keeps the command running to hold the connection open. So uh just like port forwarding leave that terminal open while you test it and then press 29:18:15 Ctrl C when you are done and uh there's our production engineext uh from the very same chart that we have created. So uh now before we clean up let's quickly go through every Helm command we used today. This is a great moment to take a screenshot uh which you can see on the screen. So here we have Helm version uh to check the Helm. Helm create to start a new chart. Helm lane to check uh it for the problems. Helm template to preview the YAML without installing. Helm install to deploy it as a release. Helm list to see your releases. Helm upgrade to change a release. Helm get values to see the configuration. Helm history to see the uh revision. helm and roll back to go back and so Helm uninstalled removes a release and all the Kubernetes resources that the release has created in one go we do it twice one for each release this is another big green by the way you don't have to remember which file created which object and knows because it tracks everything that belongs to the releases 29:19:16 right so let's double check no resources are found everything from our release is gone but the name space themselves are still there because we asked him to create them. Let's remove those two. Right? So this delete both name space and anything that is left inside it. So yes, that was all in this video and I will see you in the next one. Until the next time, keep learning and thank you very much. Hey everyone and welcome back. In this video we are going to learn about one of the interesting concept in Kubernetes and that is nothing but custom resource definition which is also called as CRDs. Now don't worry if you haven't heard about this term before because in this video you will understand what exactly is a CRD why do we need it how it works and how you can create your own custom resource definition that to from the scratch and here we are not just discussing the theory here we will perform hands-on demonstration where we are going to create our own custom resource type inside the cubernet right so I'll explain each and every important 29:20:18 line of the YAML what it means and why we are writing So let us start from the beginning. So before understanding custom resource definition, let us first understand something about human. So when we install Kubernetes, it already provides us with different sort of resources. For example, we have pods, we have deployments, have services. We also have config maps, secrets, name spaces and many more like these are the things we already have, right? So uh now here what do I mean by resource? So basically the resource is simply an object that Kubernetes understand and it knows how to manage it through the API. For example, when we want to create a pod uh using the AML file, Kubernetes understand that we want to create a pod. Now when we want to create a deployment, Kubernetes know deployment and it actually know that we are trying to create a deploy. Similarly, when we are creating a service, Kubernetes understand that we are trying to create. If you look at this example here, we have an API version. We have a kind and the kind is p. Now because pod is already a resource type that Kubernetes 29:21:18 is aware of, we can create a pod with the help of YAML. But now let us imagine a situation. Now suppose you are working in an organization. Your organization manages hundreds of applications and your team wants to maintain some additional information directly inside the cubernetes. For example, let's say your team wants to create something called a book resource, right? And this book resource should contain the name of the book, name of the author, the total number of pages. But here there is a big question that is in front of us that is does Kubernetes already understand the resource that we are trying to create and here in this case is book. Well, definitely no. Kubernetes is aware about pods, it is aware about deployments, it is aware about services and other built-in resources, but it doesn't automatically know about our organization book resource. So if you try to create a YAML file like this, Kubernetes will not recognize book as a built-in resource type, right? So it doesn't know what exactly a book 29:22:18 resource is and it doesn't know what information that book should contain and it doesn't know what structure it should look like. So uh how do we solve this problem? So this is exactly where custom resource definition comes into the picture. So what exactly is a CRD? So custom resource definition allows us to introduce new resource type in Kubernetes. So now let us understand this in a very simple language. Kubernetes already knows about the pods about the deployments about the services. But what we want we want Kubernetes to understand something new. Uh it can be a new resource let's say a book. So here what we do we'll create a new custom resource definition. And here in that CRD we will provide Kubernetes with the definition of that new resource. We will tell Kubernetes what that resource is called, what information it can contain and once Kubernetes accept the definition it can start recognizing a new resource type and then we can create actual objects using that resource type. That is the exact idea behind a CRD or what we call as a custom resource definition. So remember this a CRD is a way to extend 29:23:21 Kubernetes API by introducing a new resource type. So now let us understand this with the everyday example. Now imagine that you are managing a library. Now you want every book in that library to follow the same format. For every book you want to store three information. First is the name of the book. Second is the name of the author and third is the number of pages that that book contains. So here basically you are creating a standard form. This form tells everyone what information a book record should contain. So likewise in Kubernetes we are doing the same thing with the help of CRD. Now imagine that someone fills out that form. Uh that blank form represent the definition and the filled form represent the actual record created by the definition. Right? If you connect it with Kubernetes, we are actually understanding CRD in a similar way. CRD defines the structure of a new resource and the custom resource is the actual object created by the definition. So this is one of the most important thing that you need to understand. A CRD defines what a resource should look like and a custom 29:24:21 resource is an actual object which is created by this definition. So we are going to see this clearly on the hands-on demonstration. So now let's get started with the actual hands-on. Okay. So before we start with the hands-on, let us make one thing very clear that a CRD and a custom resource are not the same thing. They are two different things. So uh let us use our book example. First what we are going to do, we are going to create a CRD. Then that CRD will tell Kubernetes that I want to introduce a new resource type which is known as a book. Right? And here uh it will tell Kubernetes what sort of information a book resource can contain. After that uh we'll create a custom resource and the custom resource will tell Kubernetes that we have to create a book object with the particular name the author and the number of pages. Right now so what exactly the CRD will do? The CRT will create the definition and the custom resource will create the object for that definition. Now think of it 29:25:21 like in an library example that we have discussed initially. So the CRD is a blank form and the custom resource is the uh form that will actually be filled. If you remember the comparison then uh you will already understand most of the important concept in CRD. Right? So you can actually follow along with the documentation that has been provided over here. So you can find it under sub repository number 36 in the readme MD. And now we are actually good to start with custom resource definition. Right. So uh before we start uh writing the custom resource definition the CRD there there is a structure that actually we should be aware of. Right. So let us first understand the basic structure of the custom resource definition. So uh like I mentioned earlier also that whenever we want to create any sort of resource in Kubernetes there are four keywords that we should keep in mind and that is nothing but API version, metadata and spec. Right? These are the things that we already are aware of right now. Uh the thing is if you have already worked with Kubernetes, you have 29:26:23 already seen these four fields many time that we have been repeating again and again. So these are the familiar parts of the cubernetes that we know. But here is something interesting that uh CRD also uses this field. However, the meaning of some fields inside the CRD is different from what we actually see in a pod or maybe in a deployment YAML. So let us understand each and everything from the very scratch. So let me just start it from the line number one that is API version right. So here what we have we have an API version. This will tell Kubernetes which API version we are used to define which API version we are using to define the resource. So in a normal pod uh we usually replace this value with version v1. Why? Because we are using the uh why because we are trying to create the resource type pod. And for part the API version is v1. But when we are creating a custom resource definition we are using the API version as API extension.kest.io/v1. 29:27:24 Now why we are using so because a crd belongs to a cubernetes API extension. And don't worry if you don't uh understand this or if you uh don't actually are getting this because this is something that you don't have to memorize right you just have to understand what exactly it is and why we are using right. So uh don't worry about memorizing the entire value right now. Just remember that when we create a CRD we use API extension.k.io/v1. Okay. Now next thing that we have is kind. So in the kind we are defining as custom resource definition. Right. So here we have a kind. This tells Kubernetes what kind of object we are trying to create. Right? Let's say for a pod whenever we are creating a pod manifest we write the kind as pod. Right? And for a deployment we define the value for kind as deployment. Likewise when we are creating a custom resource definition in kind we are def we are defining it as custom resource definition. Right? So this will tell Kubernetes that the YAML file is defining a new resource type. And if you 29:28:26 notice something uh and if you notice something important at this point we are not creating our book resource. We are creating the definition that will allow us to create the resource later. Right? Now let's come to the next part that is metadata. Right. And inside metadata we have one more field that is called name. So let us discuss about it. Right. So here uh in metadata metadata actually metadata will contains the identifying information about our cubernetes object. For example when we create a pod we give it a name. Right? The same idea applies to our CRD. We are also creating a name for the custom resource definition. And what exactly the name over here is? The name over here is book.demo. demo.example.com right so we'll understand why the name has this particular format when we are actually building the YAML right now here comes the next part the settings the configuration that is nothing but the spec right so in Kubernetes spec generally describes the desired configuration or in simpler terms it 29:29:27 will be the definition of the resource but here so here the things are very interesting because inside a normal part the spec actually describes the things uh such as the containers or volume. But in inside but inside a CRT the spec describes how a new resource type should be defined. So if I put it into simpler terms it tells Kubernetes what are new resources should look like and inside this spec we have some additional field that are specific to the CRD. So these are the fields that we are going to understand next. So here you can see we have a group, we have scope, we have names and then we have version. Let us discuss about these things initially. First thing that we have over here is the uh API group which helps us to identify the custom resources. Now think of it as a way to organize and identify the API that or resource will belong to. For this specific demonstration, we will use the value as demo.example.com. Right? So this is just an example group. In real organization, you would normally 29:30:29 use a domain name that your organization owns or it controls. For now, we don't have to worry about that. Just remember that the groups gives our custom resource its API group. Next what we have? We have a scope. So here you can see the value as name space right. This tells Kubernetes that our custom resource where it can exist. Right? So b so basically here there are two values that we can define into the scope. So a value can be a cluster scoped or it can be a namespace scope. Right? So let us understand what is the difference between namespace scoped resource and cluster scoped resource. So if you use a name space or custom resource will belong to the Kubernetes name space. For example, when you create a book resource in the default name space, we can also create another book in different name space. Now if uh the scope is a clustered scope, right? So if you use a cluster, the custom resource is not associated with any namespace. It exists at the cluster uh cluster level. Right? But for our demonstration, we will make 29:31:29 use of the scope as namespace because we want our book resource to behave like a namespace resource. That's all you need to understand about scope for now. Next, what we have? We have names and inside name, we have three values present over here. Plural, singular and kind, right? So, this section tells Kubernetes what names to use for a new resource type. So, let us understand these three fields in detail. First one that is plural books, right? So here we'll use it when we want to list multiple book resources. For example, if you remember we were running cube cuttle get parts. Likewise here when we run cube cuttle get books we should get the output over here. Next we have singular as book right. So this is a singular name. It represent one book resources. For example when we run cube cuttle get book this is the output that we would be expecting. Finally we have kind. Now if you remember here in the kind we defining custom resource definition. Likewise here we are defining the kind. The kind here is book. So this is the value that we will write in the kind field when we are creating that custom resource. 29:32:30 Right? So here in our case when we are defining the resource type at that time we will define the kind as book. So let us remember the difference. The first thing that we have is the plural as book singular is book and third we have kind which is a book. Now these are the values that we would be referring into the custom resource but they will be used in different places. Right. Next we have versions. Inside version you can see multiple fields such as name, curved and storage. Right? So the first question that we should ask is why do we even need a version? So think about it as the application. Right? So the application changes over the time. So today our book resource might contain only one book and only a single author who is writing the book. But tomorrow we we might want to add more information to it. For example, we might want to add another publisher. we might also want to add another um author right so as a resource evolves we may need to introduce a new version of its API that's why CRD supports version so for a 29:33:31 simple demonstration we'll use only one version and that is nothing but V1 so let us understand these additional fields so that it will give us clarity so the first thing that we have is a name col v1 this is the version name that we will be using second we have served col true this tells Kubernetes that the version should be available for the clients to use. If I put it into simpler terms, Kubernetes can accept request using this version. Then finally, we have storage that is marked as true. This identifies the version Kubernetes should use when storing the custom resources in the API server. For example, here we are using version v1 or both. Right? So one important point that we should keep in mind is that a CRD can have multiple version but only one version can be marked as the storage version at a time. We don't need multiple version for our first demonstration. That's the reason we'll keep things very much simpler and we will only use the version as given over here. Now next we have schema. Okay. So 29:34:31 this is the last segment that we would be discussing because this is how we are going to complete the entire YAML structure for the CRD. Right? So here we have schema and inside schema we have open API v3 schema. What exactly it is? So now we have come to one of the most important part of the CRD and that is this schema. So let us understand uh this in a very simpler language. So if you remember it from our library example we discussed that every book should contain a book name. Every book should have a author name and every book should have number of pages. This schema tells Kubernetes what information or custom resource can contain and what type of value each field should have. For example, the book should be a text, the author name should be a string type and the pages that we would be using should be a number. This is what our schema will actually help us to define. Right? So if you see open API v3 schema here we have the type as object and here under that we are defining the properties. Right? So the open API v3 schema field 29:35:33 contains the validation rules for our custom resource. Here you can see the type as object. This tells that our resource is of type and object and the properties uh is where we define the actual object uh specification and the configuration. Right now let us understand the different type of configuration that we are defining over here. Here we have a book name as type string. Here we have author which is of again type string. And here we have pigs which is again of type integer. So the first field is book name. We have used the type as string. The string means text. For example, you can write anything over here. For example, cubernetes for beginners or cubernetes is easy. Second, we have the field called author which is again of type uh string. Meaning we can write a text value over here. So because an author name is also a text that's the reason we have defined a string over here. Next we have a page number, right? that is pages and the type is uh integer over here. Why? Because page number can be anything. It it can be a whole number. 29:36:33 For example, 100, 200, 300, 500, right? So, we can use integer because the number of pages should be a whole number. So, the schema is simply telling Kubernetes what fields or book resource can contain and what kind of values those fields should have. So, that is the purpose of schema. It helps Kubernetes to validate our custom resource. For example, if we provide a text value in where uh integer is expected, then keyword nis will reject the invalid value. And this is something that we are going to see in today's hands-on. So now let's start with the hands-on because we now understand the concept. Let us create our own CRD. We'll follow five simple steps over here. First, we are going to create a CRD that is something called a book. Second, we'll register that CRD with Kubernetes. Third, we'll create an actual book resource. Fourth, we'll verify that Kubernetes whether it has accepted that CRD or not. And then finally, we are going to test uh what exactly happens if we provide incorrect value where exactly it is expecting an integer value for us. Right? So before 29:37:35 you start the hands-on, make sure that your mini cube cluster your cube ADM or your kind is actually up and running and that is how we are actually going to start with today's hands-on. So now let me switch to my item and here is where we are actually going to start today's hands-on right so the first thing that you should start uh doing is first check whether your cubernet is up or not secondly just verify the node so cube cuttle get nodes here you can see my mini cube is up and running and here it is giving me a signal that we are ready to continue now okay now let us create a new file and here we are going to create a crd so let me just call it as vim book crd.l because here we are going to define the values for the custom resource definition and the custom resource that we want to create is for a book enter. Now again whenever we are creating any sort of resource in Kubernetes what are the four golden keywords that we should keep in mind that is nothing but API version then we 29:38:35 have a kind then we have a metadata and lastly we have the spec the configuration right now what exactly we are trying to create here we are trying to create a custom resource definition that is exactly what we are going to define over here custom resource definition okay now What is the API version for it? For that we can make use of our best friend that is cubectl API resources. And let's do a grab on CRD. Enter. And here you can see the API API version for custom resource definition is nothing but API extensions.k.io/v1. Let me upload let me update the same value over the API version which is present at the top. Okay. Pasting the same value. So now what we have? We have the API version. We have the custom resource. Let us move with the next file that is the metadata. What should be the name of this specific custom resource that we are trying to create. Here I 29:39:35 will type it as book dot demo.ample.com. Now if you remember here we are following one format and I told you that when we are actually creating the CRD at that time we are going to understand what exactly uh why exactly we are using this format right. So here you can see the name actually starts with the word called book right and which is uh nothing but a plural name of a resource. So here you can see this should be books over here. So at that time when we were creating the CRD I told you that uh I we would be discussing in depth about this name. So here if you notice the format the name starts with books right which is the plural name of our resource. After that we have defined demo.acample.com example.com. Okay, which is our API group. Next, what we have? We have the specification and inside this specification, we will need to define few of the things, right? And if you remember the template that we have studied earlier, uh that is exactly 29:40:35 what we are going to define over here. So, now let me just define the group over here. So, group and inside the group, I will define the same value that I have defined over here just beside the name that is demo.example.com. And apart from that we need to define uh the scope of this specific resource that we are going to create. So scope the scope should be name space. So name space. So here we want this resource to be created at namespace level. So now we need to define the uh names of our resource right. So let me just define names over here. And inside names we will define plural singular and the kind for it. So plural and plural for this resource will be books and then singular. Singular would be nothing but books. Book without s and then finally we have the kind. This kind we would be using in the resource that we would be creating for the book resource type. So here it would be book. Just like you can see in custom resource definition we are defining CRD custom resource definition as the kind. Here when we are creating 29:41:35 the resource type book the kind that it should accept is book. So here we are defining the name of the resource. The plural is books. The singular is uh book and then the kind is book. This name will be used when we work with our custom resource. Right? Next thing that we will need to define is we need to define the versions. So now let me just define the versions over here. So versions first thing that we will need to define is the name. And what will be the version name? Version name will be nothing but v1. Okay. So what exactly does this mean? This tells Kubernetes that our custom resource API has a version and that is nothing but it is called as v1. Now here we will need to define two more values. So just below name just write served s e r v d and served should be marked as true and then lastly we need to define one more thing that is storage and storage should also be a true value. So what is the meaning of search and storage? So what is the meaning of search? This means that Kubernetes should make this version available to the clients. And then we 29:42:37 have storage colon true. What is the meaning of that? This will tell Kubernetes that this version is used to store to our custom resource. Right? Now let us define the schema that will actually uh this is the exact place where we will be defining the properties of our uh custom resource. So here just below storage let us define the schema. So schema and inside the schema you will need to define the opi open API with the uh schema. So open API v3 schema right and again you don't have to memorize everything see that's the reason we have first covered the templates first because that will give you the idea what exactly each value means and why we are writing those value right so you need to refer that template because that will give you the idea when you are creating your own custom resource definition after this specific demonstration I would request you to try to create three to four different sort of custom resource definition and custom resource processes because that will actually give you confidence over the topic and believe me here we are going to cover each and every line of the YAML 29:43:38 file. So you are not feeling left out. Even if you have any sort of doubts, any sort of queries, feel free to write it into the discussion section and I will be more than really happy to answer you with all the doubts that you might have. Right? So and again if it is a collective question and if if it is something that is getting repeated and I will make sure that we are creating a dedicated video to those topics because I believe uh no question is a silly question. It's very worthwhile for asking any sort of question right. So again let's get back to our journey. So here we have defined the open API v3 schema. Inside that we need to define the type of the object. So the type would be nothing but the object because here we want cubernetes to create the object and what are the properties for that schema. So this is something that we would be defining inside the properties. So properties and inside properties you need to define the spec. Now this spec is for what? This spec is for the custom resource uh that we are going to create. Right? So just remember whatever we write inside this spec. 29:44:39 These are the values that we would be expecting inside that custom resource. Now again that spec will be again again again that spec will again be of type object. So I will define object over here and inside that inside this type just define the properties. Inside properties you need to define what all things that you will accept as a value. Now if I say I'm defining the properties but what do I actually mean by that? Let's say whenever we are defining any resource in Kubernetes we are defining API version kind metadata inspect. What else extra we want in that specific one? Right? Let's say if this would have been a pod manifest file then the next thing after spec inside the spec we define the containers and the configuration of containers. Likewise here we are defining the key values uh that we want when we are defining the book resource type. So here the first thing that we want is after defining the spec we will define the properties that we want to accept in that custom resource. So first thing it would be the book name. So book name and here inside the book name here we need to define the type of the value 29:45:41 that we would be expecting. So here uh since book name is a string I will define string over here. Next what we want inside book name uh we not uh we actually want one more thing that is the author name. So author and inside author name you will need to define you need to justify the type of resource it is. So here this will again a string type and lastly we'll define one more thing that is pages the number of page that the book may have. So here instead of taking the resource type the object type as string here we want it to be a whole number that's why we are typing here as integer. So if you type any value apart from these then it will throw an error escape w2. Let me first apply the file. So cubectl apply - f app cd.jl and here you can see we can see a wonderful message that is custom resource definition api extensions.k.io/books.demo.example.com is been created. But before even we go 29:46:41 and check out the things let me explain you everything that we have written so far line by line. So you are having no doubts. So let me explain you everything. So let's start with the very first line that is API version. Here as we discussed earlier this is the API version which should be used for creating a custom resource definition. Next we have a kind. So here this will tell Kubernetes that we are trying to create a CRD. Next here in the metadata we have defined uh the name that is books.demo.ample.com. So here we are giving a name uh to the CRD that we have created and the format is something that we have discussed earlier also. So here the name start with the letter called with the word called books and then we have the group name and the group name is nothing but demo.example.com. I hope that is clear. This is nothing but our API group. Now here we have spec and this spec is for the custom resource definition. Now what exactly step spec will consider? Spec will consider all the settings the configuration for this 29:47:42 custom resource definition. Right? So here we have defined the group. So here we are defining the API group for our resource. We are using the same group that we have defined in the CLD name. So here you can see the name of the custom resource that we want to create is books.ample.com. So this demo.example.com is actually the group API name. Right? So this is the API group name that we have defined at the top. Next what we have we have defined the scope. Now this resource should be a namespace scoped or it should be a cluster scope. Now based on requirement we want it to be a name space scope. So whenever we create a book resource it will belong to a name space right now next what we have defined is we have defined the names inside names we have plural we have singular we have kind right. So here we are defining the names for our resources. So here we have the plural uh name as books and the singular name as book and the kind as book right with Bcaps. Just remember this right because this is the kind that we would be using when we are defining the book resource 29:48:43 type right. So this name will be used when we are using uh when we are using or when we are working with the custom resource. Now next we have versions and in the version we have name as v1 right. So this tells kubernetes that our custom resource API has a version which is called as v1. Then we have served equals to true. So this means that kubernetes should make this version available to the clients. And next we have storage equals to true. This means that Kubernetes will use this version to store our custom resource. Now next come the schema and in the and inside schema you will see we have open API v3 schema and the type as object. Let us discuss this. So this starts the validation schema for our custom resource. The type is an object. Then what we have we have the properties the specs and the type of the uh properties that we want to create. So here we are telling Kubernetes that our custom resource will contain a section called spec and that spec section is also an Kubernetes object. Why we are defining it? Because inside a spec we want to store information about our book. Now what 29:49:43 information we want to store that we define in the properties. In the properties you can see we have book name, we have author and we have pages and again for the book name we have defined the type as string. The author again the type would be string. And for pages we want a whole number. That's the reason we have defined the type of string. So this becomes uh very much handy, very much easier for us to understand what exactly is the value, what type of value uh we should write when we are defining this custom resource definition. Right? So basically if I put it into simpler terms, our book resource will contain the book name, the author and the page name. Book name will be of type text, uh author will be of type text and the pages will be the whole number. Right? So now let us check the resource that we have created. Because right now I believe we are completely understanding what exactly custom resource definition is, how do we create it and what each values mean. If you find this thing challenging, don't worry. Go to Visual Studio Code, refer this template and life will be very much easier for you. Just uh refer this 29:50:45 template, change the values, play along with that is how you will actually learn, right? Let me just go back to terminal now. And now let us verify the resources that we have actually created. So how do we verify it? So let me first clear the screen. We will verify it by running a get command. So cube cuttle get crds and when I press enter here you can see books.demo.example.com is actually created. Right. So here you can see that the CRD has been registered. Now let us check whether the Kubernetes recognize or new resource type or not. So for that how do we check it? So if you remember when we were whenever we were defining any resource type we used to make use of our best friend that is API resource. So now we are going to check whether the group that we have defined into the yl whether that group is registered or not. So how do we do that? So just write cube cuttle api- resources and here we need to pass hyphen api- group and inside that we need to define the API group that we have defined in the crd. What is the API 29:51:46 group that we have defined? Let me just mark it as a comment. Let me do a CAD on the manifest that we have created. Once again, let me just go to let me just move the file that we have created. So, let me move my bookc to the current folder that we will be using that is 36. And here I do a long list. Let me just check the Yep. So, here what we were checking uh we need to check the uh API group name. So here if I scroll all the way to the top here the API group name is nothing but demo.ample.com. Okay clearing the screen let me go back to the previous command that we were actually running. So here we were running the command called API resources and here we need to provide the API group name. So tube cutle API resources API group equals to demo.example.com. When I press enter here you can see that resource is actually registered. This confirms that the Kubernetes now recognizes our custom resource type. Now think uh about what just actually 29:52:48 happened. So before applying our CRD, Kubernetes did not know what is the resource type which is known as a book. Now it actually uh identifies what exactly is a resource type. So after applying our CRD now Kubernetes will recognize book as a valid resource type. So we have successfully extended the Kubernetes API. Right? Okay. So the first part is actually done. Now comes the interesting part. We have registered the book resource type but we haven't created the actual book object. So if you remember the library example, we have created a blank form. Now it's time to fill out that form. Right? So for that we are going to create another resource over here and that would be nothing but vim my book.ml. This would be very much easy. Right? Now again this is a resource type. Then what are the four keywords that we have to keep in mind whenever we are dealing with any sort of resource in Kubernetes. So here we will define API version sorry API version then kind meta data and lastly we have to define 29:53:49 the spec right now if you remember what is the API version for this? Well basically we will make use of our best friend. So for now just remove it from your mind. Uh what exactly is the resource type we want to create? We want to create the resource of kind book because this is the configuration that we have defined in the custom resource. In the metadata we will give the name to this uh specific resource. Now you can write anything. I will write my book. Okay. And then in the specification here it will contain the configuration. Now if you remember in the CRD we have defined the properties. What are the three values we have defined? Book name, author and the pages. Right? So here I will define the book name and book name can be anything. I will just write cuber nis by shubham. Then who is the author? So here define the author name. So this is again we have defined in the crd. So I will define the author name as well. And lastly how many pages does this contain right? Let's say that this book contains 29:54:49 300 pages. That is exactly uh what we have defined into the c. Now when I press escape wq what exactly is missing in this uh yl file? that is nothing but the API version. How do we get the API version? Just define cubectl API resources. And here what we are doing is we are going to do a grap into the book because that is now registered into the uh Kubernetes API. Now I will copy the API version and here I will go and update the value into the API version of the resource that we have created. Now escape col. Now before we apply the manifest file, let us discuss everything line by line. What do we have over here? We have the API version. What is the API version? demo.example.com which was the API group name/v1 which would be the version. So this is the API group and the version which we defined into the CRD. Where do we check it? Let me just do a get into the uh manifest file that we have defined. So this is 29:55:50 the version that we have defined and this is the group that we are referring to. Right? Let me clear the screen. Let me do a cat of on that manifest again. So I hope API version part is clear to you. Now second is we have defined the kind. So kind is basically we're telling Kubernetes what sort of resource type we want to actually create. So here we are telling Kubernetes that we want to create an object. The name of the object is book which is the resource type that we want to do. Now here where did Kubernetes learn about this book? It learned it from the CRD that we have created earlier. So here uh it will actually know what sort of resource we want to create. Next what we have? We have the metadata. So here what exactly would be the name of the resource that we want to create? We want to create a resource uh book and what could be the name? The name of the book would be nothing but my name. So here we are giving a book an object name. The name of that particular object would be my book. So if you remember this is the name from the actual book object. It is different from our crd that we have defined. Our crd is called as book.demo.ex. example.com and the custom 29:56:53 resource is called as my book. So here next thing that we need to check is the spec the configuration for book right. So what are these configuration for this specific CRD the custom resource here we have defined the book name that is Kubernetes for beginner. This is the name of our book. Then we have the author. The author name is Shubang war. This is the author name that we have defined in the custom resource definition. Lastly we have defined the integer value. The whole number that is page uh 300. Uh so this is the number of pages that we have defined. If you notice something important over here, these are the three exact fields that we have defined in the CR schema. We defined the book name, we defined the author, we defined the integer uh as the pages. Right? Now we are providing the actual values to those fields. This is how a custom resource value is actually structured inside a CRD. Right? So once you are done, let us apply the manifest file. So cubectl apply f my book.l enter. And here you can see book.demo.x example.com/mybook 29:57:55 has been created. So our first custom resource has been created. Now let us verify the resources. So how do we verify it? Just run cubectl get books. And here you can see my book is actually printed in front of us. Now if you want to get more information for it what we will do just run ubectl describe and then need to define book and the name of the resources nothing but my book. Enter. And here you can see all the detail information is present in front of us. Right. And if you want to see this into a YAML format uh the way where Kubernetes accept is just just just write over here cube cuttle get books and uh name of the book is nothing but my book and you need to pass hyphen o as yl enter and this is how kubernetes accepts the value right. This is how the YAML has been consumed. And here you need to put your focus into the specification because these are the actual values that we are actually passing over here. That's it. We have 29:58:55 successfully created our first custom resource. Now let us take a moment to understand what we have achieved. First what we have done, we have created a custom resource definition. That CRD introduced a new resource type called book. Then we created a custom resource by using that type and Kubernetes accepted or book object. This is the complete workflow of CRD or what we call as custom resource definition. Now uh there is one more important thing I wanted to demonstrate. If you remember let me just do a cat on bookc.l. Here I specifically mentioned that the type of the page is integer. This means the page should be a whole number. So what will happen if someone provides the text value instead of number? Let us verify the same because our expectation is it should throw an error whenever we are defining any wrong values. Let me open the uh manifest file that we are actually using for uh my book. So here I will open my book.l and here instead of 29:59:56 page number 300 I will define any random value. So I'll just write test over here. Text is nothing but textual value or string value. skw WQ just save it and now let me just try to apply the manifest file. So cube cuttle apply -f my book.yamel yl. Now again when I press enter here we are getting an error. What it says the book which is the resource the name of the resource is my book is invalid. Why? Because inspect.pages it contains an invalid value. The string value is expected over here. It contains a invalid value. The type of the invalid value is string but in specification it should be an integer type but the thing that you have provided is a string. that actually proves that it will not consider any sort of false information. Right? This means that the page must be a whole number. So if someone provide a text instead of number, it will actually throw that error. So Kubernetes will actually reject this invalid value 30:00:57 because it doesn't match the schema. So this exact error message may vary depending So this exact message may vary depending on your Kubernetes version but it should indicate that the value of the page is invalid. Right? If you want to understand let me just put it into very simpler terms. So what exactly happened over here because of our CRD schema says that the page must be an integer type we provided a string. So Kubernetes rejected that configuration and this is one of the most important benefit of using and defining a schema. It helps us to maintain a consistent structure and prevents us to in prevents us for the invalid values from being expected from being accepted. Right? So now let me just update the value. I'll go to my book and here instead of text I will delete this value and here I'll just mark it as 300 like it was earlier. Now s clearing and let me just type cube cuttle apply - f my book.l enter and here you can see 30:01:58 it is actually running now. So that is how schema validation works in CRD. Right? Now before moving forward let us create uh so now before moving forward let us clear up one more important point that is when we create a CRD and then we create a custom resource does Kubernetes automatically perform some action. For example uh does creating a book resource automatically will create a deployment or a pod? Well definitely no. This is important to understand why because a CRD tell Kubernetes how to recognize and validate a new resource type. It does not automatically tells Kubernetes what action to perform when that resource is created. If you see in our example, we created the resource type as book and Kubernetes accepted it and it stored it. But Kubernetes does not automatically will create the library. It will or it may download a book or it will perform any sort of action. it's it is simply storing the custom resource in the Kubernetes API. Now if you want uh 30:02:59 something to happen with that custom resource whenever it is created, we will need another component that is what we call as a controller. Now what exactly is a controller? A controller will keep and watch on our custom resource and it will perform specific action based on their con configuration. For example, imagine that we have created uh the custom resource for website or it may be anything. Right? For now just take an example that we want to create a custom resource by the name website and a controller. What exactly it will do? It will uh it will watch that website resource and it will create deployment and services based on that configuration. But here just remember that CRT defines the resource type and the custom resource will create an object and the controller what it will do it will perform the action based on that object. These are three different concept but for our book demonstration we don't need a controller. We only wanted to learn and understand what exactly is a custom resource, what is a custom resource definition, how to create it and how to create a resource type uh that it can actually use. That is exactly what I've done. Right? If you 30:04:02 understand CRD, let us take some real world example. So CRDs are used by many popular Kubernetes tool. Uh let's take Prometheus operator for as of first example. Prometheus is a monitoring tool. We all are aware of it. Prometheus operator will use the custom resource type as a service monitor. So uh what exactly service monitor will do? A service monitor will help us to describe uh Kubernetes services that should be monitored by Prometheus. So instead of manually configuring everything, we can define monitoring requirements by Kubernetes resources. Secondly, what we have? We have a certificate manager. So certificate manager is used to manage the TLS certificates in Kubernetes. it will provide a custom resource called certificate and we can create a certificate resource uh to describe the certificate that we actually need. So the certificate controller then will watch the resource and it will work to obtain and manage the certificate. Now third and the last example that we have is about uh you know the Argo CD. Argo CD is a popular GitHub tool. It provides 30:05:04 a custom resource called application. This resource allows us to describe the application that Argo CD should manage. So you can see CRDs are used by many tools to extend Kubernetes. They allow different capabilities, different tools uh to their own resource type and they manage through Kubernetes API. So now let me switch to my visual studio code and now let us wrap up this final yet last video of Kubernetes series. Right. So let me just take the summary. So on a final note let us take what we learned today. Today what we learned uh we already know that Kubernetes provides built-in resource types such as ports deployments and services but sometimes when we want to introduce our own resource type this is where custom resource definitions comes into the picture. Uh CRD allows us to extend Kubernetes API by introducing new resource type. We also learned about the different fields inside the CRD. We understood about API group name versions and schema. Let me show it to you over 30:06:06 here. So what we do we actually understood about group scope name and the schemas right and then we learned about the group uh identifies uh or custom resources and then uh the scope what exactly it does it will tell whether it is a namespace scoped whether it is a cluster scope right that is something that we have learned over here then here we have names so names defines the singular name the plural name and the kind for a resource then we have defined the version define the API resource that are available and which version to be used for which sort of resource right then we have schema that defines the structure and validation rule for our API resource and then we have uh performed a complete hands-on when we have created our own CRD so we created our own book uh CRD we have registered it with Kubernetes we created actual book resource then we verified it with the help of cube cuttle and finally we tested like the cubernetes validation rules uh the value provided in the 30:07:06 custom resource and that was for this field two where we define the value as if it is integer and if we are providing it a string value then it should actually rejected that is exactly what we demonstrated just few minutes before right and if there is one thing I want you to remember from this entire video that would be nothing but a CRD defines a new resource type and a custom resource is the actual object that is creating using that type and controller can watch that custom resource and perform action based on that. So once you understand these three concept then life will be very much good. You have a very good foundation of understanding how Kubernetes can be extended and with that we have reached the final topic of our Kubernetes series and if you have followed this series from the beginning. So thank you very much for being a part of this journey. I hope these videos have helped you to understand Kubernetes concept step by step to the level that you feel very much confident that yes I know Kubernetes. So yes, keep practicing, keep building, keep learning and thank you very much for watching and 30:08:06 I will see you in the next one. Until the next time, see you and happy learning. If you have made to this point which means that you have completed the entire Kubernetes course. So take a moment and congratulate yourself because maximum people start with the Kubernetes journey and they don't even finish it. You actually made it to the finish line. So congratulations on completing this course. I still remember the very first day where we were discussing about this technology. Now you exactly know what is the purpose of this technology. What value does it add. You know about deployments. You know about services. You know how to write a manifest file. And if something goes wrong you are capable now. You know how to troubleshoot it. You know how to debug it. That skill you have gained. That didn't happened over the night. You have invested your time and with your point shar focus you were able to achieve that skill. To congratulations on completing this course. And honestly speaking this sort of resource take tons of effort for creating this video. You can actually appreciate it by sharing it with maximum people by liking the video by subscribing the channel and by writing 30:09:04 the comments. I personally want to know what you gain out of this course and do share this video with maximum people who would love to understand this lovely technology. Right? I will share you all the resource material all the readme.md and all the document resources that we have used throughout the video so that you have everything for the revisions as well. So that was all in this video and I will see you in the next one.