Deploy RShiny on Kubernetes using EKS, Terraform and Helm

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello I am Jillian Rowe I am a bio informatics infrastructure consultant and today we are going to talk about deploying our shiny on kubernetes using AWS and terraform so this is the project over here you will see that it's kind of it is in is in a folder called blog post and that's because I have an entire series on deploying our shiny on AWS all the ways not all the ways there's like a million ways you could deploy it but probably the most common ways that you can deploy it and today we are specifically talking about this are shiny AWS eks with terraform so eks is the elastic kubernetes service that is specifically supported on AWS it has pretty great support I've really been getting into it lately I think it's a really great service and it's a very robust way of deploying things if you were in kind of the DevOps or deployment space at all you will know that kubernetes is kind of taking over the world and there is there's a lot of support for it there's a lot of people building things that integrate with kubernetes there are a lot of people building specific packages called helm charts that are deployment recipes for deploying your applications on kubernetes so all in all for a long time I was kind of very into docker swarm and I was kind of I was resistant to using kubernetes but I had to get over that and here we are so this is the directory structure that I use most often if you're wondering about it first of all I have my dot AWS this is like my home AWS it has all of my AWS credentials I like to keep this per project because I work with a lot of remote clients and each one of those clients generally will give me a different AWS credentials I don't want those just all thrown into my home directory I would never be able to keep like I would never be able to keep track of that so I have it I have it per project in my AWS and then and then I have the actual project folder this is the code so this has our terraform code that we are then going to use to deploy are our shiny or to deploy our kubernetes cluster and then once we have our kubernetes cluster up we are going to use helm to deploy a helmet art that I wrote or that I use the the helm CLI kind of bootstrap for me and then I edited that and then we are going to deploy our our finding application so let's go right ahead and get started I personally do not like to install CLS to my local computer with the exception of like my nice IDE that does all of my nice auto correcting for me but except for that I really don't like to have too much stuff installed on my computer so I have docker containers usually I have a docker container per project sometimes I'll share them a bit it doesn't doesn't like really matter that much in this case but you'll see I do the docker run and then I just bind the volumes and I have the dot EWS is in there CWS I have a DWS cube is root cube and then just the name in the container that I built I will link to that below I do think it's handy if you if you want to follow along and you don't want to and you don't want to install the CLS to your local computer that's you know just use the docker container it will be fine and I'm gonna go to CD Projekt project what we're gonna do here is we are gonna go to terraform state actually before well you know okay so we're gonna run terraform in it because this will take a few minutes so while this is running we're gonna talk about things and revisit this so one thing that I want to talk about is just like an extremely extremely brief introduction to kubernetes you know I know a lot of people are probably gonna come back at me with this like oh my god you're completely oversimplifying things I am completely oversimplifying things and I'm totally fine with that but anyways every time you have a computing project especially like a distributed computing project I imagine that you're here because you need some kind of distributed are shiny you need it with a load balancer you need more power more file systems you need more something than you're getting with your other deployment if you don't I don't really know exactly why you would use kubernetes if it's probably more trouble than it's worth but maybe you just want to learn something new so anyways with kubernetes as with any computing project what you have is you have your data persistence layer this is this is a file sometimes you can kind of think of it as being also something like a database but even a database is eventually going to write to a file system and that is actually where your data purchase so you have your data persistence layer kubernetes calls those PVCs which are persistent volume claims you have your compute layer these are the physical computers these are servers these are if you have ever been in a data center like the servers that's what the computer is kubernetes calls those pods I don't really know why it always makes me think of like some science fiction pod people but you know that's fine pods is a fun game too and then on top of your compute layer you have your application layer your application layer is in this case our shiny we are deploying our shiny that's our application that application is going to sit on one of our pods it does actually like have to physically exist somewhere but the idea with kubernetes is that there should be kind of an abstraction you should be able to set up sort of a series of rules and then you don't like have to care so much exactly where your application is physically sitting so that's why you have that divide between the application and the compute layer and then on top of that you have your services layer your services layer is you know like if you've ever worked for the firewall or anything or a network or even if you've just deployed a web server and just had to access it through a particular point through a particular port rather that is your services layer that is what allows your application to talk to the world in the kubernetes kind of context as well that will often take care of load balancing which is just getting getting a public IP address for your service if you've never heard of load balancing before that's fine don't worry it's just a little layer that sits between like here's the world here's your application you need a layer between that that says ok this is how I'm gonna route traffic to my application so you know now now we're back now we're gonna do our set up with terraform and the helm chart just a very briefly go over tariff terraform is an infrastructure as code framework I guess we'll go with framework and what it does is that it takes all the different building blocks of infrastructure and it Maps those I'm not sure if it's classes or objects underneath the hood but probably classes anyways where say you have let's go with an ec2 instance an AWS ec2 instance right what does this have it has the ID like it has the like what kind of instance it is is it the Ubuntu instance is it the Amazon Linux two instance what I don't even know what like the VP sees that you want for that all the kind of things that you would normally go through to use your to like to actually set it up like if you were gonna go on Amazon web console and say I have an ec2 instance what do I need with this I need to know the type of instance I need to know the route volume size I need to know what bpc I want to deploy it in I need to know what subnets I want it deployed and maybe actually that one is a little bit sketchy with the subnets with my knowledge of subnets anyways I really hate networking and I try not to do it so anyway so what you do is you take those individual building blocks and then you take those and you compose them into something larger so that is exactly what we're doing and in a minute we will go and we will look at the code it's just that for right now you can see you know this is this is the layout this is the layout this is exactly what I explained before and we just did our terraform State so let's go and let's talk about that okay so terraform in addition to being an infrastructure is code one of the things that it keeps track of is it keeps track of this thing called your state your state is what steps have I done which one's worked which ones didn't work what resources did I create what are their IDs things like that this is your state it's a bit like if you've ever used to make file and your make file like it will go through the steps and if it sees the file that it already created in a previous step it won't we execute that so you run make thing I know we'll go through all the steps and then you run make thing again it's not gonna completely rerun them all over again so this is our terraform state this is something pretty standard this is just telling terraform I want to actually save my state to AWS instead of saving it locally the default terraform state is to just save it locally is to just save it locally to a file and I'm telling it no no I want to save it to AWS and I am doing that because as if it of future-proofing actually in case I want to share this with other people they cannot be writing to a state that only exists on my file system right they can't do that so instead we have a remote state and that will also prevent like multiple processes or multiple people from clobbering the infrastructure at the same time so this is good this is good to have it's pretty straightforward you can find it all over the place what does it create it creates an s3 bucket so here's you know here is exactly an example we have a resource a resource is something that we want to deploy on AWS we want an AWS s3 bucket we give this a name this is a name for us in a bit for terraform too like this is you know if you were gonna call this okay like a key value kind of thing this would this would be the key to access this and then we name we give the name of the bucket we assign the ACL we assign the region we say that we want versioning enabled and we say that we want the tags and then also I'm not totally sure why terraform wants this but it wants a AWS dynamodb table and so we will create that dynamodb is the AWS key value store so we have that and I did run this I ran Tara for a minute terraform refresh terraform apply and you can also see here you know so green is good green is always very very good in the instance of terraform it is especially good so we have all these things and then we have applied complete you can also see exactly would it create it down here chop this is good so now we're gonna head up one directory and we're gonna go in this I name this be chaos alright so then we're actually we're just gonna run the exact same command again and I'm gonna really hope that this works because this is this is live coding right here I haven't even run this one before I ran the I ran the init command while I was sitting and waiting for something else so you can see that the first thing that it does is I am actually downloading some modules if you haven't taken a look at the at this yet I really recommend going and taking a look at the terraform AWS modules what the modules are it's like a cookbook of recipes that has a lot of convenience convenience kind of functions and convenience AWS building blocks that are already put together for you so for instance in this post youtube youtube madness i am i am using the eks module and i'm also using the bpc module and that is because these are very common things to do and I don't want to do them all myself because that's it's kind of a pain and I'm kind of lazy so here we go oh no no I forgot about this I'm gonna have to kill this video we'll see you did I not put the state we're gonna put the other region bar dot region well yeah I forgot to change the region okay we'll see if it works I don't actually care if it gets deployed in this region that's fine oh you know what actually I didn't do for this one I didn't say that I wanted that I want to save the state remotely to AWS okay I will update and I will show how to do that but for right now I'm gonna create this I'm gonna kill it as soon as this video is done so this is fine anyway so you can see like there are lots of things being created here right there are lots and lots of things so many things here we go module II chaos it's creating it's creating the policies it's creating the B pcs it is creating Mouse is it creating the route tables yeah so kubernetes is really it's a beast to try to get it installed if you try to do it yourself initially when it came out on AWS they had this really like long tutorial for all the steps that you needed to follow to make the policies and to make you know the routing tables and make all of these things and it was a huge pain it was very very painful to do it and then another tool eks CTL came out I have another video on that I'll link to that below that was a pretty good tool but I think overall I kind of just like to use cloud formation or terraform as the case may be I tend to go with just whichever one has what I want what I want in it so there are other times where I use cloud formation because it already has like what I want it's just it's included as a recipe there and there are other times that I use terraform I have no particular brand loyalty okay so this is gonna take a little while but as this is going what we're going to talk about here for a minute is the helm chart and if you'll remember what I said is that the helm chart it is the recipe for deploying our application it is specifically the application layer so now what we are dealing with is we are dealing with kind of the infrastructure layer we are dealing with or we're having terraform deal with deploying the kubernetes cluster itself so once we have our cluster deployed what we want to do is we want to deploy or our shiny application so this is the helm charts are shiny ETS and we're just gonna kind of briefly we are gonna briefly talk about this I'm gonna minimize this so you can see it's just going it's gonna take a little while so we're gonna talk about this instead so if you haven't ever seen a Helmut art it is made up of a combination of yamo files and that is because that is the default kind of format that kubernetes reads what you do is you create different configurations for these different layers that I was talking about and what you have is you have one values you have your initial values yamo here at the top I'm gonna close this out so that you can see this a little bit easier but see what we have here is we have our home chart this is the helm chart that I have our shiny ETA s and we have lots of things in here but one of the things that we have is our chart gamal that's like your of course now I can't think of it but the kind of the definition this is our chart definition this is like our package txt if you've used kind of other package managers so this is our shiny eks and that's all this is just the default because I just used this I did this doing the hell I think it's Helmand it or home create its home create and then what helm does that's actually pretty handy is that it creates all the templates for you and it also creates you this value see Amal and the value cm well what it has is it has all of your default values that are gonna be pretty good going forward but also what it does is that it exposes these values animal through the through the helm API which is really really neat so you can actually change anything in the values DML you can change that on the command line when you deploy and I'm gonna show that in a little bit but one of the things that you could do is I have this image repository and I'm just using the default are shiny because for my particular instance this doesn't actually matter but you know but you would you would want to actually upgrade this with your actual are shiny application you are deploying I have this container port be the rocker shiny image it runs on port three eight three eight not sure why it does but it doesn't really matter either I also have the replica count so for instance with this particular application this is just a demonstration application I only need one rap lookup but there's a good chance that if you're deploying with kubernetes that you want to have lots of replicas and that that's why you're pulling with kubernetes right you have the tag you have you have these other things I would recommend just keeping means the same you have your service type you have and then you have your ingress this gets a little bit interesting what you can do is you can actually deploy it's called having like a micro services architecture on kubernetes and you could have many many many applications and then you could control how those are accessed with the ingress so what we have here yeah we have the ingress I've enabled it I am saying use the nginx ingress which is probably the one that I most kind of use now I'm gonna look into using another one called traffic soon because I really liked that one for swarm and they've kind of upgraded to kubernetes and then you have your hosts what you want here you probably have an actual domain name that you want to point to so you would point to that and this is gonna be we're gonna go over this when we actually deploy this but this is the host this is the host name that a WMS gives you back so normally what you do is you deploy with your home chart AWS is going to give you a public DNS address and once you have that you would update this you would update your ingress to use this public this public address and then you would go into your hosting panel and you would have this domain name point to this thing and so much networking so much networking but you'll see it you'll see you in real-time and I'll show it to it will be fine okay so then we have that so these are all of our kind of exposed values and you can edit you can edit this as well you can add whatever you want to this like you could be like you know like you could have whatever you want in here and the templates so then we have our deployment and you can see here helm uses this kind of templating language I think the back end is written and go but pretty much there are a lot of these kind of include statements and then these indents because yeah Moe is such a pain it's such a pain about indenting and I understand why I have to paint about indenting it it is kind of nice because you get all this code folding but it's still pretty painful anyways then what you have here I mean we're not a bit of a tangent there anyways we have a deployment which is we're actually deploying this is our application layer there's a couple different ways that you can deploy your application layer the default is to use a deployment that's fine and then you have some nice metadata this matters when you're getting into really kind of like complex deployments for now it doesn't really matter you have your spec you have the replicas in my IDE I actually have like a helm I don't know what helm helm like helper I guess and so these values are kind of unless I click on them it shows like it shows what's actually in the values which is kind of handy because then I know it's actually happening in my chart although it doesn't seem to happen all the time like here it doesn't happen I don't know beacon so you can see for this one this is what my IDE shows it shows the kind of interpolated value so this is the chart name this is the image this is the image repository in the image in the image tab I do just kind of want to point out one thing that I find to be really annoying that nobody ever nobody ever actually uses it seems like out in the wild but the default tag for your image it's actually the version in the chart so it would actually be it would be this version so that's just something to watch out for that's one of these things it's gotten me a couple times that I forget to go and change the image tag on almost any hound chart that you'll find kind of out in the wild this image tag is exposed in the amyl just like I did here so just you know just something to keep in mind just something that you'll see there we go so we have we have the containers and then the next part here is we are gonna talk about the ports so like I said the container port is 3/8 3/8 that is the application that is running within the docker container and that's the port that it's running on so this is pretty important to know depending on your application it's gonna be running on a different port this is our port here obviously if the application in your container was running on like port 80 or port eight zero eight zero you would change it you would change the container port to whatever is appropriate for your context and then actually what this here but this gets mapped to did I open this open this Lake okay so you'll actually see this is a bit funny the way that the way that this is done in kubernetes so then this is our service and if you remember our service layer is the way that our application talks to the outside world and what this does is this maps from this thing here that we have this name so this is our metadata name this is the name of our service this is the name of our deployment which is what we are using is our application layer and these are the ports and the ports are like primarily how we talk to the outside world when we talk about services we're talking about a couple things but like on a really simplistic standpoint we're really just talking about ports so we're gonna say here that this port it has a name and it has a protocol usually your protocol is gonna be TCP so don't worry about that but you'll notice here that the name is HTTP if you are deploying a lot of containers like you're using kubernetes as a micro services you will want to like give this some more descriptive name don't use HTTP okay give it give it like a real name or shiny or something like that I left it as a default because it's fine I don't care so so then you can see here my whole my whole tangent about that was that you can see that the target port is HTTP this maps to this so if I change this name to our shiny H don't put a dash in there but our shiny and then I would change it here to our shiny HTTP okay I'm gonna leave it I'm just gonna leave it but I'm just showing you there you know I just wanted to show you how these things map because it does get to be a little bit tricky I always used to do this when I first started out with kubernetes I was like trying to figure out how to go from docker compose and docker swarm to kubernetes which was it was kind of a flawed plan to begin with because they're not like they're not like adjacent technology is and there's this tool called compose which is really great it's a really great tool but one of the things that it does is it tries to do this direct mapping from docker compose files to kubernetes which like it mostly works but there is a couple little funny things and this was one of the little funny things that I found transitioning from Dockers warm and docker composed to kubernetes was there would there was some point where this really tripped me up so now I'm passing on that knowledge to you guys now you can know where I got really tripped up and that was on the stupid port names why can't like it should just it should just be a single port and then it's you're just map you know but I get why they did this it's because then you can have this nice you have this nice separation of responsibilities between the service and between the application so in the kubernetes world no it shouldn't be that simple it should be you have your service you have your application these are different domains and they remain separate and then this now this is the ingress this is pretty much what we talked about it is the like the real like okay how are we talking to the outside world portion of this application and that's that that's that that's really that's really all that I wanted to talk about with kubernetes the rest of it it's really kind of getting deep into kubernetes and that's really all that you need to know to deploy like if you're just deploying like an application an hour sign e - flask whatever this is it you need to know you need to know about the deployments you need to know about the service and you need to know about the ingress and those are what you need to know about so here we go okay so this is still going this is gonna take a little while so I'm gonna up as soon as I say that right as soon as I say that here it is okay here we go man I musta talked for a while cuz I think that that takes some time this one takes some time so one of the things that I do because I hate having to remember stuff is that I actually have my modules and they all have outputs and one of the outputs that they have is to configure the kubernetes client and I don't think I remembered to put that here so we're gonna we're gonna go find this outputs I hope puts outputs yeah it see now I have the way that I usually do things and then I have like minimal examples that don't have a ton of stuff that is only for me but then I realize I kind of need my ton of stuff that's only for me see see here we go here we go well I can already see this is gonna be a little bit different so as I was doing this what I thought was like that I wanted to stay as close as possible to the terraform example because they have they have like a basic example and it's really good it's perfect to like to start off with you should absolutely use it don't screw around with it too much now let's screw around with it too much and but kind of like additionally my computer is like really I don't know I don't know if it's on its last legs because it keeps kind of freaking out like this see like this what is it doing it's text stop freaking out alright let's see if we can do this you can see some troubleshooting some troubleshooting in real time so you can actually see so one of the things that it does do everyone should be fine actually where's the secret it's fine our secret no secret all right this should be fine famous last words right this should be fine we'll see actually I was a little bit stupid and I'm gonna change this so we're just gonna what was this I don't even remember where to point to now region us West - and then the name I think this was the name actually no I don't know that we need this yeah this is fine I didn't actually know okay so I'm pleasantly surprised so normally what I have is I have something that I thought that I had to have that would output my cube my cube config and as it turns out terraform is doing that for me already so I was I was doing extra work for myself but I have to show you this just because I think that it's pretty handy to do things like this and then and then I'm gonna show you the fun thing the fun thing on the terraform page but anyways so what this is this is a resource this is a null resource and then I am calling this cube CTL update because one of the things that you can do within terraform is that you can just call arbitrary bash commands and that's really nice because so because you can do different things like for one thing you could include tests as a part of your infrastructure and that's something that I really like to do so for instance if I have you know I'm deploying a database let's say I'm deploying a database on AWS one of the things that I want to test is can I actually connect to this database the way that I think that I should be able to connect to this database and it's very nice it's kind of like having notes for me in the future or what is it somebody somebody at some point and I really wish that I remember where I read this because I've always thought that it was very apt said that tests are like living documentation and it's true tests are like living documentation and they are very very important for me in two minutes what I have forgotten what I am doing so anyway so I really like to have these kinds of things here this one isn't a test but it's you know it's one less thing that I have to remember it is the null resource cube CTL update you can say it depends on these other things for myself I'll say that this always runs and you have to add this in because like I said terraform like it will keep track of your state and if it says oh I've already I've already run this before and will rerun this and sometimes I just rerun things like just to get these kinds of outputs so just keep that in mind then this is how you would yeah then this is this is how you would update the cube config cube config is very much like it sounds like it's a configuration file that is then read in by a CLI called cube CTL and cube CTL is what actually like integrates with your cluster it's kind of like running docker except instead of running docker run cube CTL so then so then that's all of this okay so again you know think about how you can have little things like this in here to make your infrastructure easier think about how think about how you could just run a bunch of PI test commands to test the things actually work the way that you think they are so right now we're gonna go and we're gonna see so then we're gonna run helm upgrade - - install helm charts eks values I think that's all that we have to set we have to give this a name I'm gonna give this actually wait let's see let's see if queue it let's see if this one oh no no okay so I was kind of hoping that this cube CTL that this was this was fine but no I do actually I do actually have to rerun this I think I think what it is I don't have a Cooper not a secret okay so I've changed my mind on this like six times is this running is this not running all right so this did not actually configure cube CTL to point to the AWS cluster so as it turns out I do need this I saw this file here and I was like oh this is nice this must be just fine but no no no no no no so I'm wondering why I have a kubernetes secret and I can't like find it in my file see this is what I get for trying I was really trying to just do the minimal example but that's ok cuz you guys can see me you are gonna see me kind of go in go in real time here and then this one here it's actually named something else so what's the name [Music] it's local stock cluster name does this get me any complaints it does it does let's close out some of our windows so what I'm doing is that I want I want for terraform to spit it out to update my cube CTL config and to do that I have to get some of the other outputs from Tyra form from when it created the cluster so I do I have a cluster it's here it's created and now I have to access some of the things that I already know about it but because I write my configurations a little bit differently then then the one that I'm showing you guys I'm happened I'm having a dick around a little bit that's fine where's the neat where does this name see here it is so then I what's your name ah local local cluster name what did I have this so this should be name is equal to uncle what's your name and again again my ID is freaking out so normally when one kind of convention that I like to follow is because I'm very rarely deploying just like one thing I actually just like to give my whole project a variable called prefix and then I will use that prefix all throughout my project so for instance with this one a lot of times when I deploy are shiny I'm also deploying maybe I'm deploying a database maybe I'm deploying a message queue quite often I'm deploying some file storage so I'll deploy some EFS file storage and then I can use the same name all throughout so that's why in the default and the default what you might call it in the default terraform like in this basic example then what they use is they use this they use this locals variable they use this one so this one is the cluster name in in the basic example from terraform yep and so then that's so instead of using bar prefix I'm just using local cluster name that's it that's all that I'm switching out it's really it's kind of like a personal preference thing just defining your variables but then get used throughout your project because remember this is infrastructure as old as code okay and then for this one I'm hard-coding in the region because because I forgot to change it so it's in here and then I'm gonna run terraforming it again and we are gonna see how this goes so the tariff for a minute what it does is it initializes the environment the refresh says pull everything from the cloud here so if somebody else had done something to change like you could you could update all the states and then terraform apply it means okay actually deploy my stuff now there is also a terraform plan which would just tell you what terraform would do if you applied it but it doesn't actually do it so that would be non-destructive oh no but you know like that doesn't look good what doesn't it like here I swear I've used almost this exact same chart like I've used it so many times and then because because you want to change just one little thing and you want to do it live I don't know why it would give it like a weird turn at a secret name although actually we don't actually need this Wow yeah we need this we need this I'm sure that it will occur to me right after I have this video and then I'll be like oh my god people didn't know why I didn't have that do you must think I'm such an idiot you don't know the struggle is real with live coding it really is especially if you're doing training or something and you're supposed to like actually know what you're doing and you try to do things live oh it's hard but it's fun it's one of the more exciting things so anyways I realized I don't like I don't entirely I don't need this one right now I don't think I need this one right now so I'm actually just gonna leave it out and then I'm just gonna say cube CTL update I don't think I need the secret it's in there I know so the thing is is that it's in there somewhere because it gets created by terraform and I know that it's created in there it's more just exactly how I'm gonna access it but I don't need it for this one right now because I'm not I'm not putting any kind of certificates this is for you know secrets and certificates and whatnot like certificates like SSL like when you want to be using HTTPS and things and I don't need that one right now so we're just gonna ignore it and just pretend that it did not happen okay this is still going I'm starting to wonder if it's gonna go on long enough that I should pause the video what I probably could have done here is I think I could have just copied this to the dot cube and just been done but I don't know the trouble with manually copying things around is that it's too it's too easy to like get used to it and be like oh it's fine I'll just copy this thing I'll just copy this thing when it really should it should be automated so let's see if we have anything in our dot cube folder yep so now we have our cube config and let's go take a look at it and it should yeah okay so just to go over that again what I was doing is that uh saying okay terraform create my stuff and then I want it to go and I wanted to access some of the data from terraform about actually creating my stuff and then I wanted to say all right now go and update this configuration file but I need to actually access my stuff which in this case is our kubernetes cluster so you can see that I have this resource it's a null resource meaning I'm just gonna execute arbitrary bash commands which apparently really bugs the terraform people because they're like don't do this don't do this there's always other ways to do this but I'm a rule breaker and I'm like you know you will pry my bash in SSH from my cold dead hands anyways so then you want to run this cube CTL update because it's aww because it's an AWS cluster like AWS has a bit of a wrapper that will actually update your cube CTL config and within that I have I have some variables because I wanted I don't know when I wrote this I wanted to have variables I didn't want to just have just one string here because God forbid we just have one string and what that does is that that then writes out a configuration file and then the kubernetes api or the cube CTL which is the kubernetes CLI is going to look at this file and then it is going to access our cluster so now they're gonna run cube CT I'll get pods okay and nothing was found as expected because this is a brand new cluster and we have not actually deployed anything so there we go you can actually see are these is they're kind of they should be the same thing yep so you can see here's our cluster does it have the same name name name name name name yeah so these things they have the same name but you have like you have arms and whatnot so no actually I was wrong I was kind of thinking you could just copy this one over and now I'm not so sure but anyways we're good we have we have this all sorted out yeah the only thing that's a little bit tricky about doing all this infrastructure is management stuff is it's very it can get very difficult to kind of keep track of which configurations go where and that's why you want to be really careful when you're writing out your different configurations to really write tests you know like exactly like what I didn't do but write tests to make sure that the intent of what you think is happening is actually happening so for instance one really good test could be for me to run this command and then to also run an additional cube CTL get pods cuz for this I'm saying okay deploy my deployment infrastructure deploy my kubernetes cluster run an update so that I can actually access that cluster and then oh yeah by the way once I've actually run the update so that I think that I can access that cluster let me make sure I can actually update it so a really good thing would have been to actually just write another command here and then just run cube CTL get pods if that didn't exit correctly terraform would have thrown an error and you would immediately know that something was wrong so just you know so I can kind of sit here and hammer home on some points that's a good idea do it don't do what I did don't do this do as I say and not as I do as I like to tell my kids okay so again now we're using hell hell exists to help us with the application layer well the application layer the services later it helps with a couple different layers all right so there we go did that actually deploy like no problem oh man let's see this let's see and now let me just run it clear make this bigger that's such a pain okay so now when I run cube CT I'll get pods because kubernetes is elastic or kubernetes on AWS is elastic the pods are not always available they're available on demand so before we said we said we said we said at some point we said cube CTL get pods and return d return if returns no resources found did I type that did I like okay I really think that earlier I typed cube CTL get pods and before we deployed the application it said no resources found maybe I did it but I thought that I did but that is because when I first deployed when I first deployed the terraform plus when I use it first used terraform to deploy the cluster what happened is that it said here's our cluster but the pots are gonna be on demand because it's an elastic cluster and that's a lot of the benefit that you get of using AWS versus a data center is that when you have a data center normally what you do is you buy like physical computers and those are always available it's not elastic they're not up or down on demand that might be fine for you that might not be I'm gonna imagine that if you're on AWS that you know you like all the elastic stuff so that's what that is oh and there we go it's already running so one thing that we're gonna do actually we're gonna do clear and then we're gonna just run we're gonna run a couple of troubleshooting commands so one really good one to get a lot of information is to run this cube CTL describe so cube CTL describe the resource type is pod and then this is the ID and this we got from doing cube CTL get pots so this is it tube CTL get pods this is the name of the thing we are describing this and then cube CTL described pod you know this thank you right and then when I described it it has everyone has so much stuff it has it has all kinds of things that we don't really care about but one thing that's really handy is if you are debugging something if it's not running and you don't know why probably something went wrong with starting your container and it would hopefully be in here it's not always gonna be in here but it will sometimes be in here and then we are actually gonna see if this was deployed as a service so that was cube CTL get s SBC and you can see that this was deployed it was deployed as a load balancer this is pending this is pending under how long this is gonna take usually it's pretty fast but the other day it took a while yeah this took a little while I don't know what else I can kind of rant about what else can I talk about Oh regions if you're using terraform don't do what I'd be concerned about your regions so one of the things that I normally do when I am when I'm using terraform is I have I have an additional AWS file let me see if I can find you an example yeah I have an additional AWS file and I actually define all that stuff here and I normally just tell it to use my current AWS region which for me is USC swine this initial file is like it's a little bit it's a little bit strange because there are a few places where you can use variables in there a few places that you can't so you might end up kind of putting that putting that in a couple places but this is actually this is the file that it would look like if I had updated the main the basic example to to use the backend to use the AWS state so you can see here yeah this is the prefix this is the prefix okay and then I'm actually telling it terraform backends this is like the history file sort of of the up terraform and I'm telling it use s3 and then I'm giving it all the examples or all the the examples all the data so that's where that is and you can actually see how this maps to yeah so you can actually see how this maps to a terraform state sorry that this isn't another project that's a little bit aggravating you can see I have my terraform state I initialize it over here and then I reuse it for this project here and that's that's all that happens is we're you know it's a history we're just keeping track of things which is really really nice when you have really big complex infrastructures or really another another really nice point that I'll make about using something like terraform is that you can also destroy everything all at once which is very very helpful cuz with AWS if you just go in there if you just go into the CLI and you start to try to destroy things it's really not going to work out for you very well at some point you will clobber something because you will try to destroy something and it will depend on something else and that thing will depend upon something else and there will be this big long complex dependency tree you don't want to have to resolve that by yourself once you get into complex infrastructure really use cloud formation is terraform I'm sure there are other things out there use other things let's see is it ready is it ready is it ready no it's not ready we'll try it one more time okay so this isn't ready I'm gonna wait a little bit for this to come up and when it comes up I will restart the video go by and we're back okay so before the the service was taking quite a long time to deploy and that was actually because I had a mistake and I want to point out my mistake so what I had was okay in the service I had this session affinity and I had it set to client IP and this doesn't actually work with the type of ingress we're using and if you need to know I set I set this session affinity because oh man my brain just went completely blank there I said it because with our shiny when you have multiple replicas you need to have some you need to have sticky sessions enabled or else it just starts to freak out and that's because since it is like a data visualization it wants to make sure that the same users are going to the actual same application or else things would get like very strange right they would refresh the page and then they would be in a different application and it wouldn't like to save their state and all this kind of thing so we have that so instead of using client IP we're just using cookie which is for all intents and purposes it's the same stuff so we have the nginx ingress kubernetes affinity and we're using cookie that's fine if you wanted to keep this if you wanted to keep this as client IP I just don't use the nginx in Grasse okay I think that's getting way too involved in a services those things so I'm just I'm gonna have I'm gonna have this here and and you can see how that works and it will be posted to okay so there we go so then so then what I did is because I upgraded this I actually just reran this hound command and it upgraded it was fine what's fine I wonder if it'll be fine now now that I'm doing it in real time we'll just have to see oh so you see this you see this kind of like niceness here how my IDE it has like the path so I could go like this I don't know I just think that's a little bit nice that it does that right okay and now we have an IP okay okay it's not yeah yeah and I'm gonna show you that I was like what is this why isn't this working I shall go to Google okay and you can see no it is it is actually working all right I'm gonna show you another cool trick too so here it is it is working I guess because I had the video paused for a little bit longer than I thought I'm not normally that patient when I'm checking my services so anyways you can see the welcome to the shiner II server it is up here with with what we have with what we have right here so that's that it's up it's finally up after an hour I checked the video I couldn't believe that this was an hour of me talking after an hour of me talking finally we have a kubernetes cluster we have an are shiny application that is deployed with helm and we have all manner of niceness see see look at this it works I was about to be like does it work does it work yes it works here we go it works there we go now one other thing that you would want to do is if you see here how we put like just all kinds of junk we put a whole bunch of junk in here right like things that don't actually make sense when you deploy this what you would want to do is that then you would want to go through and you would want to upgrade it and if you remember earlier I discussed that everything in this value is Hamel you can actually you could upgrade it from the CLI or rather everything in the values animal is exposed through the CLI so if we go and we look at this again we'll see that one thing that we did was we actually exposed to the service type and we exposed to this load balancer okay we're gonna do this again man typing and we do this with this - - set variable so here I set the service type as a load balancer I did this because I was on AWS if you were on your own infrastructure you would set this as a node port and then you would have to do network configuration to make sure that you get a public IP but let me show you okay see here it is service type the default is cluster IP since I'm on AWS on a cloud provider I'm using load balancer and then another thing that I want to start is I want to set the ingress dot hosts and then if you go here you see that this is here's the host and that this is an array so you can actually access the things in your right it starts with zero I'm not going to touch this one I'm actually going to touch this one this is our AWS thing this is what I want to update is the AWS die host yeah is equal to and I want to set it as equal to this thing and then I think if I do this it's going to complain to me about the paths but we're gonna try this let's see those are complaining about the palace Yes No maybe so what are you complaining about executing our shiny at host nil pointer evaluating interface host ingress dot hosts one no maybe I do have to do zero you see now this this is the trouble with coding in real-time okay see so now it's so I was like pointing at my screen and so if you can see that that is that is very useful to the YouTube world top anyways and then we're gonna do the same thing in breaths dot posts of zero there are host notepads and then look this got me for a little while PAP's is itself in a write so paths of zero is equal to this there we go and then you can actually see ok so then you'll get a nice note in this also it matters when you're doing that it doesn't matter for this particular instance but it matters when you are doing like real domain names you want to make sure that you have that there it will make it show up a little bit faster anyway uh sometimes it takes a little while like for this one it showed up right away and it showed up right away and I actually didn't show up right away it's just that I deployed it and then I started the video and then I started talking and then it was ok if you really want port to show up right away you do you do this do I have an IDE anymore I also realized I completely filled up my file storage so that could potentially be why my computer was freaking out earlier there you go oh this is actually this is kind of another thing that I wanted to point out about the helm about the helm chart is you can actually give you can give notes like this this is actually what it's called it's called notes and what it does is that it's just this little like it's just this little informational message that gets deployed at the end so one of the things is that it will say it's deployed its revision the notes and then get the URL by running these commands and that is because it knows it knows that it's a load balancer and then it goes through and it just like it gets it gets all the stuff and it runs it which is you know which is quite nice because again when you're working with these big complex systems you are quite often going to be working with other people and it's really easy to kind of get in your own head and be like oh yeah I know I know all this stuff in my head because I kind of worked through it but it is quite nice like I really like the way they did this actually that they have these notes there at the end and back to my other point about how you would want to do this so for instance instead of having to do this this helm command having to do all this manually I actually I have these program directly into my helm sharks are not into my home charts into my terraform scripts how terraformed saltstack information you know there's just there are so many things this it I think I think I screwed with my default script and that's not good oh that's not good where's helm Oh is there not in this one okay it's here it's here in my template files if it works because really my storage is that like 99% I don't know why these videos take so much space they take like they take a ridiculous amount of space once I've exported them to an mp4 or whatever export it is that I use it's fine but before that it's something like this is gonna be like 20 gigs it's gonna be something ridiculous is it gonna work to show you but so one of the things that I do personally is that every time I figure something out so like I will go through and I'll figure out this whole deployment and then I will try to generalize it most of the time I'll try to generalize it a little bit so for instance very very often I am deploying either our SHINee flask or - these are the three things that I deploy most often in my work and I deploy them and quite frequently people want EFS storage as well so I actually created myself a script that has templates of all these things because you saw like going in there and actually manually modifying these files is of course it's do like of course it's doable of course you can do it but if you have a few things but you always deploy and you just need to change a couple of the variables like I just throw these I have template files from my template file sprite templating systems for my templating deployment you know it's like that that's something when I describe it like that it sounds a little bit ridiculous but anyways this this year this is you know this is a real world this is a real world thing that I actually employ so you would see kind of you can just take nor the fact for a minute this is a it's a Jinja template that's the kind of templating language that people use in Python so you can actually see that I go through what I went through earlier where what do I do okay so I actually run I run a dependency update with helm and then you can see I run helm upgrade so normally when I am doing this I will actually put everything into the terraform script and that's because or into the terraform state whatever into the terraform configuration and that is because it is really really easy to forget how to do these things or that I'm handing the project off to somebody else and that they may not know how to do these things or that me and two minutes may not know how to do these things you know things like this so if you actually have your whole process and it's documented from the very beginning to the very end from deploying the cluster to deploying the application to updating it for your various ingress values um for instance for this one you know what I actually do is I use terraform to create EFS which is the AWS networked file storage and then I just refer to it here so I don't have to go like digging around for the different for the different variables for the different IDs and things I just I just used them all in here which is a really nice aspect of using one of these infrastructure as code tools so that's it I will leave you with our pretty pretty our shiny let me go like this one more time and like this again and like this again okay that's it if you actually watch this whole thing thank you and have a nice day
Info
Channel: BioDeploy
Views: 1,212
Rating: 5 out of 5
Keywords:
Id: t06EAwmwq4w
Channel Id: undefined
Length: 69min 14sec (4154 seconds)
Published: Mon Apr 27 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.