How to Create a Google Kubernetes Engine (GKE) Cluster with Terraform

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone alex here and today I wanted to make a quick guide on google kubernetes engine and how you can launch a gke cluster with terraform and also manage it with terraform so what gke is is it's a manager Brunetti service offered by google it makes it super simple to scale launch manage and manage urban areas clusters and it comes with a whole bunch of different features here as you can see on the landing page I will leave a link to this landing page in the description but there is a brief overview of the many features that gke offers which are all fantastic and we're gonna go over how we can you can launch your own cluster in GCP with terraform superfast and so you can get started playing with kubernetes I did create a repository called terraform - gke once again I will leave this in the description as well and it's very simple there's a few terraform files here that we're gonna go through and we're also gonna launch a demo application so go ahead and clone this locally and then we can get started on launching a cluster now that you have it cloned locally we can go over to the repository and we'll just go over a few things here so in the first section here I'm defining a Google container cluster resource within terraform what we have here is the definition for the master it's going to have a few different settings here like the name of it the project it belongs to in GCP the description the location you're gonna want it in I have an option here to remove the default node pool because what we're going to do is we're gonna launch a node pool separately we're not going to use the default one there's an initial node count option the master auth here there's different ways you could enable authentication if you leave this blank it's going to disable it we're not going to use basic auth for this and we're also just going to disable this client certificate option and below here in the Google container node pool there's also again a few things the name project the location you wanted in the cluster it belongs to how many nodes we're gonna just have one for now and the Machine type as well as some API requirements for monitoring and logging in the variables there's a few things to find here we're gonna want to update the project to your project and this is currently set to mine and then if you'd like you can change the machine type and the initial node count but it's not required and then it's gonna output some endpoint the master version and also just like what the IP address for the cluster so you can save that value if you need it before we launch the cluster I just wanted to quickly go over a value there is a value here called preemptable and it's set to true if you're familiar with Amazon this is similar to a spot instance so if you want this muster to cluster node to not get destroyed or randomly because of price changes you should set this to false the reason I have this set is just for cost savings reasons but essentially it's a the equivalent of a spot instance in Amazon so if you want to change this value value you can go ahead and now that you're ready we can go to the terminal and we can run our terraform plan command you will have to be authenticated via the Google cloud CLI tool for this to work and it's gonna of course it's going to create our container cluster and then the node pool for that so what we can do here is you can clear the screen and do terraform apply and we're gonna say yes to this so this is going to take a few minutes so if you would like to grab a coffee and let this run I'll see you guys in a little bit so I'm back now and it's been completed so it took about a minute and 40 seconds for the node pool to create and about six and a half minutes for the container cluster resource to finish creating as you can see there is a endpoint and the master version so you can see what version running on and over all it took about you know eight minutes for this to complete so not too bad better than hand rolling a kubernetes server yourself and trying to create it yourself so it doesn't seem so bad when you think about it like that and if we go to our browser now we should be able to navigate to the Google cloud platform page and then on the left hand menu there's going to be a committees engine page so we can click clusters and then you can see our demo cluster here if we want to connect to it we can press this connect button and it's going to give us a command line command to run so what we can do is we can copy this you can either run it in cloud shell I'm gonna run it in my terminal here and just paste that so there you go we have got an entry for the demo cluster and then if you're using cube CTL you can go ahead and run cube CTL get name space and we should see that we have our default namespace or Q public in our cube system namespace so you can see that it's seven minutes and 54 seconds old so you can see that the cluster was launched 8 minutes ago and now we can actually if we want we can add an application to our cluster so we can go ahead and do that next let's go into the app directory here type there's a few different files here we're gonna apply these and then I'll go through each of them so you can just do fusing cube CTL can't spell apply - F and then we can do the deployment you can do the service and then if you do keep CTL get pods you should see that there's this demo here and then we can do cube CTL apply - F and then the ingress the ingress is going to take a little bit just because it's going to create a Google cloud load balancer so just know that it takes about five minutes when we run that so these are all created and now I can actually go through what we just created here so going back to the text editor there were three different files we applied here with the cube CTL so the deployment the service and the ingress so first we can start with the deployment it's going to be living in the default namespace there's a few other things set here like the container we're using nginx and we're gonna pull the image if it's not there and run it on port 80 with the TCP protocol so this is the deployment next we're gonna need the service and this is just doing a few more things with the port the target port and then it's using type node port because we're going to need to configure the ingress to work with this properly so services configured here and I'm also assuming you have a little bit of kubernetes knowledge before you watch this video and already understand kubernetes a little bit so the ingress I was talking about how it's gonna launch a cloud load balancer it's gonna take about five minutes to provision it's very simple here it's just going to define the service names we're gonna have to point to that service because the service is how we're pointing to that pod and so the ingress is gonna you know point to that demo service and then the service board is going to be a tea we have that defined in the service here so if we go back to our Google Cloud console in the gke menu on the left hand side there's many services in ingress so we can see our demo service and that has a an endpoint here this is going to be that node port that we were talking about earlier and then we're gonna see the demo ingress and here it's defining there's a IP address to find so click this it's gonna say for for not found nginx we're just gonna get rid of this wildcard here and now we get that welcome to nginx page so we've successfully created that nginx pod and the ingress for the Google cloud load balancer ingress is now pointing to that service and it knows how to rub that traffic so now we successfully have a nginx pod running in our cluster and this is not to get confused I mean I'm just running the nginx pod it's not like I'm using nginx as the ingress the cloak cloud load balancers being used as the ingress in I'll show you how that looks in in GCP as well let's go back to the Google cloud page and on the left hand menu let's just scroll down and then there's a network services section under networking and then we're gonna click load balancing and here's where the cloud load balancer lives so you can see that if you're curious there's some other things too if we go back to the kubernetes engine page back to cluster on the left hand side there's gonna be workloads and you can actually see this demo deployment and it has one pod in which cluster it's part of and which namespace if you click this you can actually see some metrics so the CPU the memory and the disk and you can see some details about it just a mammal you can see as well what it actually looks like there's also an events tab going back to the overview you can also see you know which revision it is I ended up deploying this again but that's why there's two revisions and you can also see kind of which service is exposed and and also the ingress so some useful information here around monitoring and get some metrics here and you can actually see how down to the pod level how it's performing which is super cool stuff I also want to quickly show how you can actually view the pod logs so if we go on the left hand menu you go to stack driver and we go to logs viewer there is an option here called G key container so we can select that and then there are a whole bunch of different containers here that you can take a look at actually the ones that get installed with gke so that's nice too we're gonna take a look at the demo one because that was the container that we deployed so I want to take a look at those logs so we'll click that and we can see here a bunch of requests from the load balancer you can also see someone made a request here from Firefox which was me and it gives you some nice little insight so the great thing about this is that you can get all of this insight out of the box you don't have to configure any of this so gke comes with that monitoring in that logging integration which saves a lot of time for people who are looking to set up kubernetes clusters and it makes the user experience really nice as well that you get all at all this out of the box and you can just start playing it right when you provision a cluster so that kind of concludes of what I wanted to cover there's a whole bunch of kubernetes content that i'm planning to create in the future so if you have any feedback or ideas please leave a comment below and once again thank you for watching and I hope to see you or the next one
Info
Channel: Alex Podobnik
Views: 10,298
Rating: 4.9731545 out of 5
Keywords: gcp, terraform, gke, kubernetes, devops
Id: Vcv6GapxUCI
Channel Id: undefined
Length: 12min 5sec (725 seconds)
Published: Thu Jul 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.