Deploying Any Dockerized Application To Kubernetes | Ashutosh Hathidara | #kubernetes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys i am ashutosh and i am back with another tutorial on kubernetes so today we will talk about deploying any type of dockerized application to kubernetes for uh deploying application scalably we use containerization framework known as docker and to deploy it successfully and scalably we use kubernetes if you don't know what is kubernetes then i'll explain you kubernetes very quickly uh with one example let's say you are you have an application which you which is hosted on internet using any hosting service now many people are using your application at one point in time your application crashes because of maximum number of or a very high number of hits on your application so what will you do in this case there is no backup or there is no another application which will serve in the meantime you fix the application crash so kubernetes is the solution for that so what kubernetes does is it creates a multiple instances of your application it has the load balancer over it so that the users which are accessing your application will not directly access the url of your application but it will call the load balancer and load balancer will distribute the number of heads over the multiple instances and such that the kubernetes will scalably serve the application and even if one of the instance app instance is crashed kubernetes automatically creates another instance for you and this is the most scalable type of deployment we have so today we for the demonstration purpose we will create a dockerized or containerized flask application and we will deploy it on kubernetes cluster so for that you need to install three things in your computer first is docker if you if you can install docker desktop that will be good another second thing is kubernetes cli which you can download from the kubernetes dot io official website of kubernetes the third thing is mini cube which is a virtual machine which directly installs the kubernetes environment and deploy and automatically deploys cluster for us and to it it removes the manual work that we had to do with kubernetes cli create an empty folder named fast kubernetes which will contain the the complete application code that we want to deploy you can open it in visual studio code or any other editor that you like so first create two files which is corresponding to our code files which is app.py which will contain our flask application quickly create a flask application that you like [Music] so this is our demo application that we have created for deploying our flask application now i want to deploy these applications will also need requirement.txt file also create requirements.txt file and just put flask in it because we only have one dependency that is flask now to containerize the application we should also have the docker file which from which will generate a docker image corresponding to this flask application so we'll also need one more file which is docker file we'll use python 3.7 for our application so we also need to have to pull python 3.7 docker image dock image from docker hub we create a new directory inside the container [Applause] will have working working directory as app because we are creating a working directory app just to install the application which we have we'll copy the all the files which are there in this directory to app directory inside the container then we'll run pip install our requirements.txt to install required dependencies for the project then we'll run the command python after py so that it will start the server for us now we have created this docker file now we will generate a image for the flask application using this docker file so how can we do that we can do that using docker build then we will give the image name using hyphen t and give image name as flask cuber letters kubernetes as image name and give space dot dot defines that the docker file is in the current directory so it will look into the docker file which is in the current directory and it will generate a docker container based on the commands that we have written in the docker file when we hit enter it will generate the docker image or it will build a docker image corresponding to the commands which which we are given inside our docker file we can also see this image using docker images command we can see that we have generated this image flash kubernetes here now we want to deploy this containerized application which is there in that image flash cube address how can we do that so we will need one more file that is deployment.ml file to deploy the application onto the kubernetes engine so we'll create deployment dot ml5 note here that this is not yml file this is yaml file which is a yml file is usually used for docker compose and this file is used for mainly for kubernetes so please don't make that mistake for the time purpose i am directly copying the code for this file into the into our application you can pause the screen or pause the video and write this code or else i have given this the github repository for this code into the description box below now you can see that there are two parts here one is a service and another is deployment what this means is we are creating one service which will work as a load balancer and we are creating deploy one deployment which will serve as an application so the user will hit this load balancer and this load balancer will distribute the request into the our application also you can see that we are we have defined the number of replicas as five it means that we will create five number of instances for scalability purpose so that if even if one instance or one app instance crashes the other ins the other instance or the other app instance will serve as an application also you can see that this deployment.ml file is connected or the docker image that we have generated using this line so for deploying the application to kubernetes cluster we are using this docker image which is class kubernetes when we deploy this deployment and this service to kubernetes engine this will automatically create containers based on this docker image now we will deploy dockerized flask application to kubernetes engine so we need to so we need to execute this command which is cube ctl apply and we need to specify file name which is a deployment ml file so we'll specify deployment.eml file so what this will do is this will create so what this will do is this will deploy our service and the app app instances to the kubernetes engine and then we can see it so after executing this command we can see that it is it is showing that the service flask test service is created and the deployment apps flash test app is also created now mini cube and kubernetes provides the ui dashboard where we can visualize our deployment to to open that dashboard we we need to uh we need to execute the command mini cube dashboard so it will open up the dashboard where we can see that our flask test application is deployed so you can see that our flask test app is deployed successfully and you can see the pods parts means that the it defines each app instance of the deployed application so it means that these are the applications associated these are the app instances associated with our load balancer and what load balancer will do is it will distribute the number of hits a number of api calls to this app instances equally and you can also see that if i delete one of the app instance what if i delete one of the app instance what kubernetes do is it will automatically create one more app instance you can see that you can see here that i had deleted and it created it again now what if i want to now what if i want to access my flask application which is deployed on kubernetes cluster using api calls so you can do it using the service mini cube service command now you can see in our deployment eml file that we have to call our load balancer and this load balancer will internally call the app instance and then we can get the result from there so we can see that the service name the load balancer service name is flask test service so to to access your flask application just execute the command mini cube service and service name which is flask test service it will open up the browser and you can see that it has create called to our api which is inside the flask and it has fetched the response which we have defined in our flask application so that's it for today guys please like share and comment on this video and subscribe to my youtube channel for more exclusive content on tech and computer science i'll be back with another tutorial on next weekend till then stay safe
Info
Channel: Dev Sense
Views: 9,521
Rating: 4.8644066 out of 5
Keywords: Deploy, Machine Learning, Deep Learning, React, Kubernetes, Docker, Container, Flask, ML, K8s, Cluster, Kubectl, Minikube, Docker Desktop, kubernetes deployment, kubernetes, kubernetes deployment yaml, kubernetes tutorial for beginners, kubernetes rolling update, kubernetes replicaset, deployment, kubernetes deployment tutorial, kubernetes deployment example, deployment kubernetes, deployment architecture, deployment demo, introduction to deployment, deployment features, deployment benefits
Id: XQNNAeyMAkk
Channel Id: undefined
Length: 13min 33sec (813 seconds)
Published: Sat Aug 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.