Deploying an ASP.NET Core 3.0 Web API on Kubernetes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome today I'll show you how to deploy an SPL net cord 3-0 Web API on kubernetes you will learn how to enable a local kubernetes cluster in your box how to generate cornetist files to describe your asp.net core web api deployment using visual studio code and how to deploy your container eyes web api to coordinate this to follow this video step-by-step you will need a few things first the hello a spinet core docker image created in my previous video continue rising a nice field net cord to 0 web api if you had not seen it already please go through the steps on that one and then come back second docker which we will use to manage docker images in the dead box and which also includes its standalone kubernetes cluster where we will be deploying the image third pieces to the code which we will use to generate and edit the require cornetist files you could of course use any other code editor that works best for you but you might miss the code generation piece and finally postman which is handy to query our Web API once deployed on coordinators again you're welcome to use a browser instead for this if you prefer or any other tool that better suits your needs the first thing that you want to do is make sure that dr. desktop is running and that you can do very easily by apena opening up the tray our icons here and just looking at the docker desktop icon you should say dr. Desktop is running if that's the case then Dugger is up and running now we're going to open the project that we created in the previous video where we have all the files for this Web API that we're working with and I just opened already a terminal here and this terminal we're just going to query for the creaminess to make sure that we already have the image that we'll be working with so we'll do docker images and here Elise hello a spinet core v1 is is there now next step is to enable a do Canaries cluster in our docker desktop installation to do that we're going to open a d'etre icon right click on the docker icon click settings go to the coordinators tab here and then click on enable kinetise apply click install and this may take a while but this is going to pretty much a download a bunch of documents a for kubernetes into your box and enable a very simple one node cluster in the box that you can use to start exercising all the canaries functionality when installation is complete we can go ahead and close this and you should be able to see that both docker and coronaries are running in the box then we'll just close this dialog here and what you want to do now is making a make sure that your communities a context is it matches the docker desktop a cluster that you have new box so to do that there's a couple of ways one way is to again open the tray icon right-click in the kubernetes section here you should see dr. desktop already selected there and the other way is by using the cube CTL tool so this tool comes installed with a docker desktop so you should be able to do cube CTL config get context and that should bring up the docker desktop context that we already saw in the tray icon for some reason it will display more than one dog or desktop like this docker for desktop other one here but it doesn't really matter the one that we care about is already pre-selected and it just for a little bit of context is this khones context is your logical grouping of your cluster and a bunch of other related settings and so they will change depending on which cluster you're working wait so you want to make sure that you're set in the right cluster now if for any reason a cube CTL the cube CTL tool is not found in your box you just you may want to just go ahead and in this case closed wheels business to the code and reopen it because it should be available in your pad in your machine pad and if you're using a just a common line you may want to close it open it again and kill steal should be there now in middle to the code it's time to start creating Java files to describe a do coordinating artifacts that we're going to be using to do that one thing that I can recommend is to install the kubernetes business to your call extension which can generate this stuff for us so if you have not done it already go to the extensions hub look for quia natus and the first result here should be the extension that you want to install so you just go ahead and install it will take a few seconds and this will enable a degeneration of a cone a DS double files we close this now one thing related to this and let me just clear up is is that the communities extension by default will also install these other jumbled extension but as of the the time when I'm recording this video the younger the latest version of this channel extension has a bug that prevents the kubernetes extension from being able to generate the gamma files so to avoid that what you want to do is make sure that you go back to version 0 for one of the devil extension and to do that what you can do is just click in the gear icon here he stole another version and then you will pick the version 0 for 1 and that will pretty much fix the issue you may want to use close and reopen business to the code if you need it but then things should work as expected and of course eventually the Java extension will be fix it and you will not need to do this additional step now let's go to back to our files view now what we want to do is add a new file here that we're going to call deployment that channel and this is these we're going to use to describe the deployment of our container into kubernetes and to fill this file quickly we're going to just type here deploy like I said this is taking advantage of that kinetic extension 4 vs code which pops up this menu window here which we can click and that initially is scaffold the template for the kubernetes deployment so the deployment is pretty much a static description of what we want to obtain or deploy into the coordinators cluster so here first thing we're going to do is provide a name for this deployment this is how you identify the deployment let's call it hello is the net core deployment next into the we go into the selector labels section and so what happens here is that you have today you have to describe a week Grenada spots are going to be targeted a by this deployment okay so the pots are really the living beings or and the minimal unit of deployment into coronaries and a those are the ones are going to be going to be created or destroyed over time in the cluster according to what you have defined it in the in the deployment definition so the deployment is a static view of what you want to obtain the the pods are the living kind of the living entities that actually enable your deployment in grapes so first thing we're going to give a a label for our pots we're going to call it a call them hello a spinet call pod okay so this is the kind of the label that we will assign to all our pots and we're going to say is that our deployment shoot a match the label hello a spinet call pot that make sure that this equipment just manages all those pots now coming down we need to describe which is the container containers that we want including this in the in the pot we just have one container we will name it here just as hello asp net or container and this is this kind of an identifier for this container but now we have to divide the actual image that needs to get deployed there so this will match exactly the image that we that we created earlier okay so if you remember if you just do in the terminal docker images so that image could be and of course there's a few more images here by the way let me expand this a little bit explain this you can see yes we have the hello is Bennett called image here and we have the dotnet SDK and a spinet image here but we also have a bunch of other images these are the images that were downloaded when we enabled the coronaries cluster in the box and these are the images that pretty much bring coordinators into the box now we really care about hello a spinet call right now so that same image we're going to use so let me put it here and importantly we have to specify the tag so in this case as you remember tag is big one to load y usted okay so that's a machine needs to get deployed into this pot now keep keep going down we have a couple of settings here what we call the resource limit so this makes sure to assign a few research I mean machine resources to your communities a containers so that they don't try to take over more resources than than what they should use right to not take resources that some other containers may want to or may need to use so the two ones we have here is a the memory and the CPU so in the case of memory and by default we are getting 128 megabytes which is kind of similar to megabytes and the other one here is a 500 a milli CPU which is kind of equivalent to 0.5 CPU which just means house of you basically so we're saying that at a given time each container that it has been up by this pot I mean each container a that is part of any pot of hello a spinet core pot will have 100 at much 128 maybe right and a house of you that that's a limit that they have and finally we have to specify a deport that the container is exposing okay then and that's going to become the way to get into the processes inside the pot and in our case yours as well we created the docker image that container port is going to be hey okay now I'm going to save this file and it's time to apply these coordinates file so the command W for this is cube CTL apply - F and then we give the name of the file the plumbing Channel so hit enter and create so what this does it is these create a deployment in queries and spins of the creation of the pots so if you do use ETL get deployment you see we have our deployment here q CTA hello eight-minute core deployment and if we do cube CTO get pot we should have one hello a spinet core deployment and some some random grid this is the pot and this is saying that a one of the one containers in this pot are ready which is good status is running so everything is good about this container the container is is good to good to go and we can confirm that it's really a alive let's say by saying kill CTL logs and we will provide the name of the pot and you can see it's ringing of expected console output right here now even when the container is running inside the khones cluster this is not enough for us to be able to query the Web API that's inside that container we need to bringing one more eco net is a artifact or object that we call the service so the service is a kind of a logical grouping of objects that allows you to that allows a coordinators objects to interact with each other and plus in this case this is a we're going to create what we call a load balancer service which allows us to assign a public IP as a public IP to a or DNS name and to our to our pots right so this is without this you will not be able to reach the containers they are pretty much alive in there but there's no way to access them so to do this what we're going to do is just again add a new file we're going to call it a service the channel and just as we did before we're just going to type service here if you like this and here so we have folded the template for the service and we're just going to start filling the the values here so the first thing some name for the service we'll call it hello SP Nate core service so that's the name service and then just as we did in the other template would intensify a which are going to be the parts that are going to be targeted by this service right so if you think of a load balancer so it says okay so whenever this service is reached this service will try to get in touch with as many pots as are available of some specific label so going back to the pots the poor definition here we know that the pot label is hello a spinet core pot so going back to service we will use that as a selector in the service so it doesn't matter how many pots we have which we could have we will just have one right now but we could have multiples so the service will load balance between all the pots that are using this stack here and now this is the external port that people will use to query a a to query the service and then target pour is that port that we have specified on the deployment channel which is internal a container port so you'll have to go a navigate to port 8080 and that will be routed into port 80 on the pots that are being targeted by the service finally we had to add one little piece here which is the type and because there's a few types of services like you could have services that just interact with each other within the cluster without exposing anything to the outside world but in our case what we want to use is a load balancer which instructs Canaries to allow public access to the pots that are behind the service okay so now going back to the terminal we're going to apply this service channel there so let's say give CTL apply service channel and the service got created so if we say now you say QC feel get services here is and we have our new hello a spinet core service of type load balancer and it has it does have a glossary P this is kind of an internal IP within the coordinators cluster but more importantly for us its external IP which is how we can access it from the outside now of course since the closer is just running in our box there's no really a public IP involved is just localhost so now let's test it out let's see if we can actually reach these clusters so we'll go to go we're now going to go to postman I'll create a new request and here I'm going to a query for HTTP localhost and then we said this country port 8080 and then the alcohol with API route which is weather for gas if I'm not wrong so let's hit send and here it is with results from our coal toda Web API which is now hosted in in cornetist if this video was useful please consider hitting the like button don't forget to hit subscribe and another vacation bill to know right away when I polish new videos also please leave your comment below with any talks about this video thanks for watching see you next time [Music]
Info
Channel: Julio Casal
Views: 25,025
Rating: 4.9470701 out of 5
Keywords: asp.net core, kubernetes, docker, containers, vscode, k8s, asp.net, .net, .net core, web api, asp.net core 3.0, .net core 3.0, visual studio code, microservices, tutorial, asp.net core 3, .net core 3, .net conf, beginner, c#, cloud native, dotnetcore to kubernetes, dotnet k8s, asp.net core to kubernetes, asp.net k8s, asp.net core on k8s, dotnet to kubernetes, dotnet kubernetes, k8s on docker for windows, kubernetes on docker for windows, dockerize asp.net core, dotnetcore, julio casal
Id: ZOROT9yMp44
Channel Id: undefined
Length: 18min 44sec (1124 seconds)
Published: Mon Sep 30 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.