5. Terraform - Setup Kubernetes using Terraform | EKS setup using terraform | Provision EKS on AWS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
setting up kubernetes cluster involves lot of steps and also it is a time consuming process how it will be if we convert this one into yes hey guys welcome to Galaxy Technologies my name is Ravi Shankar in this video we are going to see how to set up kubernetes cluster on AWS I mean to say eks by using terraform script for this I have already written a tariff on script I will walk you through with the step by step water null vtn mods then we are going to execute that script let's jump in and see hey guys now let's see the steps which are involved to set up kubernetes cluster on AWS I mean to say eks cluster by using terraform for this we need to set up these things that is first we need to create a VPC which we have already set up in our previous lecture if you are watching this video directly maybe you can check out our previous videos because it is continue to our previous videos next thing create an extra subnet for kubernetes so far we have created only one subnet we are going to add one more subnet next create an easy to instance which we have already created next to create a security group for kubernetes this we are going going to do that one and to set up kubernetes cluster we need to create all these things that is IIM role IIM policies attach roles then create eks cluster and node group once this is done I can say that our kubernetes cluster is ready then we'll try to access our cluster so with these steps how our terraform file looks like let's go and see that one I have committed all the terraform code over here so in previous lecture whatever we have covered that is with V1 VPC with ec2 and the one which we are talking about now is that is V2 VPC with e case I have committed the information or required files over here so this is same as our previous one that is VPC with ec2 output and variables let me open this one and you can see here we are using variables and even outputs also right so this is the same as our previous one okay now let's go back and as I said we need to add one more subnet that I am going to add it over here next thing is Security Group we need for ecase you can see here we are creating a e case Security Group let me open this one and there is a output file and variable file variable file helps us to change the values for the SG this is the actual file so let me see the variable what is there so it is expecting a variable called VPC Jad so let's see how we are going to get it later but if I go over here it is going to create the security group under current VPC which we are going to create it okay next thing we are going to see the outputs it is going to just display the output of our security group that's okay and we are going to see the eks okay this is the one which you need to understand it again e case expects the variable file that is Security Group IDs we need subnet IDs we need and VPC ID so these three we need to give input to this SJ how to give this one to input I will let you know so next go back to our eks and if you see the output what is the output you are going to get the end point of our eks kubernetes cluster okay next thing we'll see the actual file this is the E case as I said we need to create an IIM role so this is the IAM role and we are assuming a policy then we are going to attach the policies you can see here all these policies are required then we are creating one more IAM role and here we are creating IAM policy so like this watermel dependencies are there those IAM roles and policies we are creating over here then we are creating a cluster over here so cluster name is ede case01 this is the cluster name and it is expecting here two subnets you can see here subnet ID where subnet ID 0 subnet id1 so nothing to change over here we just need to change our VPC file I will show you and it depends upon this IIM roles nothing but if these IM roles are getting created then only it will able to create the cluster otherwise it is going to fail next thing we are going to create a node group so node group name we are giving it as a div and back end is the terraform local name it is also expecting the subnet IDs and you can see here capacity type this is on demand spot instances and dedicated you can specify whatever you wish but we are going with the on demand next thing disk size we need 20 GB and instance type this is T2 small next thing we are using the ec2 key pair so this is the one which you need to change if you are updating it according to your key pair you can change it or else you can give this one in the variable file that would be easy okay and desired we are mentioning to maximum three and minimum size is one okay maximum unavailable one can be another available at any point of time again it is creating a depends on these policies okay this is what we are going to use it let's go and see how it looks like so this is the one I have already cloned it into our local system but we need to change a little bit over here as I said it is expecting our eks cluster is expecting two security groups right sorry subnets right but if you check your our VPC we have only one subnet okay this is the only one subnet I'm going to create one more subnet so to create one more subnet just we need to copy this one one more time okay and the first one I will name it as a subnet one and uh here also demo subnet one and second one we are going to name it as a demo subnet to even this one also even here also subnet 2. now we need to provide the cidr block for the subnet tool right so I will name the variable as a subneter 2 that is the reason in our previous lecture we mentioned it as a subnet one now we'll go to variable file and we need to add the subnet for this one so let me copy this one and I am going to change it to subnet to cidr and I am going to change it to 2 okay that's it I can say that we have created one extra subnet even I need to save this file as well if I missed it and I think it's fine now next thing is this is the actual file which we are going to execute that is the reason we need to call our other modules so this we call it as a module so SG eks and eks module we need to call from VPC with ec2.ef file okay so to call that one we need to specify the module block type okay so to Define module block type we need to give module and our module name we can give SGS security groups and here we need to provide the where is our module located so our module is located in the dot slash sge case in the current location it is available so yes G underscore e case okay in the current location only it is available right if I go to my directory so go to vpc2 so here in this file we are updating so in this file where it can go in the current location there is a SD underscore eks file is there so that is the meaning of this one and if you do remember okay while checking our Security Group yes GE case so SG case is expecting here VPC ID as a input so we need to give the VPC ID for this one so how we can give VPC ID it is quite simple so VPC underscore ID okay this is the variable it is expecting so this variable name we need to provide so what is our VPC ID we are using so this is the one we need to copy it over here okay quite simple so we are giving for this module just give the VPC ID as a input so now what will happen this VPC ID will be defined in the variables file of our security group sorry this variable file not even this one so under this one yup here so VPC ID so it will copy this is not required anyway so this VPC ID will be replaced with the value which you are going to get it over here so that it will be creating under same Security Group similar way if you go to your e case variables it requires the sgids and the subnet IDs and VPC ID these three things we need to provide it let me remove this one that is a default value so these three things we need to provide it okay so let me copy before copying again I will go to my VPC with ec2 so here again I am adding a module module name is eks I am going to give and the next thing Source where it is available dots Class E case right this is where it is available so what and all variables it is expecting so not this one let me minimize the eks and open the sorry let me open the UK is and variables so it is looking for the sjids so let's copy this one over here so sgids we need to give the sgids equal to our sjids are creating over here right so that is what you need to specify that is module module dot SGS dot Security Group public okay so this is how we need to specify the sjid so here we have created the sgids that we are calling over here whatever is created as part of the sde case those security groups we are using over here next thing it is also looking for the VPC ID right so same bpc ID we should provide and the last thing it is looking for the subnets so go over here so this is the one it is looking so go over here and copy the subnet IDs equal to we need to provide the subnets so what are the our subnet names so that is what you need to specify over here so let's go to our subnet so this is the AWS subnet demo subnet to write okay so this is two and one more is one one thing we have missed I will tell you what is that so open the braces and just give the dot over here and Dot ID okay so this is how you can Define it so this is the one and let me copy it one more time comma this one okay first one I can name it as a subnet one and the second one is subnet2 so these names should be equal to how we have defined over here yeah subnet 2 and here subnet one okay same name naming convention we have used so there is no problem and one more thing if you remember subnet one when we were creating we have Associated this one with the route table okay that even we need to do for the subneter tool that one step we have missed it so we need to create one more subnet Association over here so so subnet Association that is for demo subnet to ID route table is same routable is same so even here it should be one right we have given minus 1 okay so that is how you need to Define let me save this file and one more thing we missed it is we cannot give the same name for the both subnet Association so you need to give one over here and 2 over here let me save this web okay that's it I think we have done all the changes which are required let me check it one more time that is and one thing we missed it that is under which subnet we need to create our EC to instance now there is no demo subnet right either demo subnet one or two so I'm just changing it to demo subnet one and save it now let's try to execute it before executing let me go to V2 and over here we have all the files now terraform in it so we need to initialize it whenever there are new modules we must initialize our terraform scripts then terraform validate so we are just validating it so there is a type of okay so terraform validate and let's see the syntax I think yes it is good now terraform plan and by the way I haven't removed our previous systems or VPC so which we have created on top of that one we are adding this one so you can see here this is the VPC which we have created in our previous lecture and this is the instance which is up and running so now it should not delete this instance and it just create the kubernetes cluster let's go now and execute the terraform plan okay it is creating 22 resources and the Destroy 3 resources may be it is recreating the security group right so existing Security Group has been changed that is what it is trying to do that's okay so terraform apply so let's apply it it is going to take at least 10 to 15 minutes to create the cluster we should wait till the time so give S2 created if we encounter any issue we need to fix that and we should execute it okay hopefully it should work okay so it is giving conflict why because this is not properly removed before creating the new subnet that could be the issue I am assuming so the thing what we can do is we just need to change the cidr block of the subnet 2 to something else so let's go over here variables so let me change it to 3 over here so subnet 1 will be under 3 and subnet 2 will be in the 2 range okay now let me save this file so that it won't create any conflict let's apply it again so whatever resources has been created so for those resources remain same and it is going to update the new one okay just give us earlier it was 28 now it is sorry 23 now it is 5 only let's see now because it should destroy our ec2 instance because earlier it was in 10.10.1 series now it is going to change it to 10.10.3 series again we are getting the subnet related issues so we need to make sure that these two are creating in the different availability zones so yeah I think we are using availability John as well right so this variable it is using the same so subnet one which availability Zone we are using that is AP South one here so subnet 2 we can just copy it and we will name it as a subnet to Z and let me make it as a 1B and save this file and go sorry subnet to right so this is subnet to minus 2 over here so subnet 1 let it be as it is so now subnet 2 is getting created under 1B availability Zone okay I'm just trying to fix the error sound fly so that you can understand it better so what it is saying okay there is no closing braces it is saying so let me go to variables and I just need to close it out okay now let's try it out again just to create this time only four resources among them two are going to get destroyed quickly let's see what's happening in our AWS account at this moment so this is my is my ec2 and VPC let me go and check out further my this is the VPC we have created and subnets it should create subnet 1 and subnet to a route table yep it created a route table and if I check for the subnet associations we could see two subnet associations are there okay let's wait for a while to get it completed so it is saying that it has created a cluster let's go and check it out so KS let me open in the new window yes you can see here a new e-case has been created and you can see here 1.25 this is the kubernetes version which it is using and while communicating with this cluster we must be having a client version below to this one okay I will tell you how to connect with this cluster by using Linux system so I will wait I think there is some issue it is saying error while creating a case node group unexpected state so it is saying that as in public IP address to the instance while launching into it okay one thing we need to change we need to enable autos and public IP to the subnet okay that we didn't do so if I go to this one so we are assigning the public IP over here but we need to give the Autos in the public IP to the subnet actually okay so let's enable that one so we are facing lot of issues but that's okay it is for learning purpose so I will just remove this one or let it be and again why I should need to touch that one in this one I am going to map it as a map public IP and launch that's true that is the thing we need to specify even over here okay this will helps to create the public IPS on launch okay let's try it out once again it removes the subnets and recreate the subnets hopefully let's see it is destroying only one resource under two change this could be subnets okay yes to queue so it is destroying node group under recreating let's see on the console we could able to see two ec2 instances are getting created because the node group is getting ready yes two instances those are T2 small so let me see this is 10.10.2 this is another subnet 10.10.3 and this is 10.10.3 okay good so these two are in one year and this is 1B let's see okay so it has been successfully completed and we got all the resources now how we can able to communicate with this cluster so that is where we need Cube CTL we should install so now all these all are in same VPC so I can connect from this system to remaining two systems this system nothing but this is demo server and even if you are not sure you can get that IP from here so 65.2.170.128 okay so that is the one right not this one then Yep this is the one so this one is the demo server let me take the server and connect to the system mobile extern session and uh I'm trying to connect it to the cluster okay so I'm just logging into the demo server now let's log into your root and the next thing is we need to install the cube CTL at this moment if you check for cube CTL it doesn't work okay now we should install Cube CTL Cube CTL versions for Linux if you go and uh we need to install lesser than 1.25 okay that's what I was saying so this is the actual URL you can find it by searching the similar way how I have such that is Cube CTL version for Linux so go to Amazon official page and you can download 1.25 1.2423 so I am going with the 2 3 so let me copy this one and you can just clone it so now we have learned and it has been downloaded we just need to give the execution permission to this so I have given then move this one to the slash USR local bin okay now let me execute Cube CTL get R of course it is going to give you an error because it cannot able to connect with the AWS Cloud until unless you give the role or else you need to run the AWS configure okay so I'm going to run the AWS configure here I need to give the access key ID secret access key and region name region name I am giving AP South one and enter that's it so I can create a role and attach to this system or else I can give the credentials of my user so that you can find it in your local system that is go to this PC and users so in Galaxy we have dot AWS right so go dot AWS this is where you have credentials so this is a sensitive information that's the reason I don't show you so I will just give these credentials in the of the screen okay now you can see here I have provided the access Kad and secret access key so that I can able to configure the AWS credentials so now let's enter and Cube CTL get all okay now I am trying to communicate with my cluster and still I could see that okay it is giving some connection refused why because you need to get the credentials of your kubernetes cluster so how to get the kubernetes cluster that is where AWS eks command comes into the picture I will grab the command and it will execute it so this is the command awscks update config and region AP South 1 and name our cluster name okay if your region is changing and cluster name is changing according to that you need to update it now you can see here it stored the credentials are certificate to connect with our cluster under slash root dot Cube dot config now let's execute the same command Cube CTL get all which is going to get the kubernetes service and Cube CTL get notes if you check you can see the two nodes over here okay so this is how we can set up our kubernetes cluster by using terraform anyway for you it could be simple because I have already updated everything you just need to use the same code but only thing what you need to change is under eks okay so here you need to change the key pair name okay that is the only change otherwise you can use the same script as it is for your purpose and if you want to change the instance type you can change it all right that's all for this video and thank you so much for watching this video If you like this video please give a thumbs up and let me know if you want to see how the deployments will happen through the helm charts and how we can configure Prometheus and grafana based on your feedback I will create the further videos on this one thank you so much and see you in another interesting video thank you [Music]
Info
Channel: Valaxy Technologies
Views: 16,607
Rating: undefined out of 5
Keywords: aws, devops, valaxy technologies, security, automation, serverless, linux, valaxy, valaxy devops, devops online training, devops realtime training, valaxy devops training, valaxy devops videos, terraform, terraform tutorials, terraform file to setup kubernetes, Setup Kubernetes cluster using terraform, setup kubernetes aws eks using terraform, terraform tutorilas, terraform for beginners, how terraform works, terraform form valaxy, terraform by ar shankar, terraform eks troubleshooting
Id: acnpInts120
Channel Id: undefined
Length: 24min 16sec (1456 seconds)
Published: Thu Mar 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.