[ Kube 86 ] Getting started with Kustomize tool for Kubernetes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello viewers welcome to this video in this video i'm gonna be looking at a tool called customize customize is a neat simple tool that allows you to customize and template your resource manifest so instead of explaining if i show you some quick examples it will give you a rough idea of how you can start using customize obviously there are lots of documentations out for customize which i will show you at the end of this video but uh it's it's it's very simple it's not a big deal so let's start by doing some examples okay so i've got my kubernetes cluster cube ctl get nodes it's at three node cluster it's based on branches k3d the idea is to start with a template manifest and then start customizing that manifest file depending on where you want to deploy and other things like that okay so if i show you a quick example it will make a lot of sense so i'm inside the play directory i'm going to create a directory called demo let me actually open this up in visual studio code we are in demo back in the terminal i'm just going to create a resource manifest for a deployment so cube serial create deploy engine x minus minus image nginx i'm not actually deploying it but i'm just doing a dry run so that i can grab the output and then write it to a file so deployment.yaml and here i'm just going to delete the lines that i don't actually need creation timestamp which i don't need and then strategy i don't need that creation timestamp i don't need that okay so that's the bar minimum that i need let me also increase the size of the font so that you can see better so uh that's a very simple deployment manifest i've got under the demo directory and if you want to deploy what you normally do cube cdl create minus f dot okay that's created cube ctl get all if i type the name correctly cubesat you'll get all that's running fine that's okay no big deal we've got a deployment manifest and we just deployed it so now what i'm going to do is i'm going to create a file called customization.yaml okay create a new file called customization.yaml and the only thing i'm going to add here is resources and i want to include deployment.yaml actually deployment.yaml i'm going to move that inside the demo directory okay so in here if i do an ls i've got the demo directory and inside the demo directory i have the deployment yaml that's the actual manifest and i've also got the customization dot yama so if you're using customize either through the customized binary which we will see later or using the built-in cube ctl command it will expect a file called customization.yaml okay so the bam that's required in this file is the list of resources that you're going to deploy so in my case i'm inside the demo directory and i want to include this deployment.yaml so so far we haven't done anything different we've just included the resource that we want to deploy inside the customization.yaml you can do whatever you want here say for example uh if you've got a service.yaml inside this demo directory you can include that and maybe you've got sub directories called build source and then nginx.yaml or whatever it is or if you want to include all the manifest inside a particular directory just specify the directory here but in my case i've only got the deployment.yaml so i'm just including the deployment.yaml in my customization.yaml so how do we run it from now on i'm not going to edit the deployment.yaml so that's the idea so i'm going to start with the bare minimum so that's a very basic uh deployment manifest that i need but i'm going to customize depending on my needs but i'm not going to touch this deployment.yaml file so all i'm going to do is i'm going to update the deployment.yaml through this customization.yaml let me add one more thing okay common labels so what i'm doing here is so i'm using the the same deployment.yaml but in the customization i'm specifying i want to apply this label to all the resources that are managed through this customize okay so let's say owner is venkat so that's the customization.yaml i'm saying what i want to include in this case it's deployment.yaml and the only customization that i'm doing is adding a label to all the resources that i'm deploying through this customization.yaml in my case it's just this one deployment which is a deployment so all the resources that the deployment is going to create the deployment itself the replica set the parts the containers everything will have this label owner is linked in so as you can see here i'm not touching the deployment.yaml all i'm doing is updating this in the customization.dml so now how about deploying this in our cluster so there are a couple of ways one is using the customized binary which i'll show you now okay let's go to customize github and download the customized binary if i go to the github and go to the releases page so the first one is k yaml we don't need that config now kubernetes customize yeah version 3.8.5 assets and i'm going to download linux amd amd64 and wcat just uh downloading that star.gz file so i've got that star i'm extracting the zip file okay so i've got the customized binary here and i'm gonna move this customize binary to use a local bin and now if i do which customize oh sorry which customize it's in user local bin and i can do customize version okay version 3.8.5 okay so that's one way but if you happen to use an arch-based operating system it comes with the with the official arch repository itself okay so let me remove use the local bin customize that i extracted and i'm also going to remove the dart file that i downloaded okay so as i'm using arch based it's actually rc next i can install it from my official repository okay as you can see here customize version 3.8.5 it's available in the arch repository which customize customize version okay 3.8.5 which is same as version 3.8.5 i've got customize binary downloaded to my system and i'm inside the play directory and i've got these customized customization.yaml and the actual manifest inside the demo directory if i do cube cdl get all i don't have oh that's the old one let me delete that cube cdl delete deploy engine x cube ctl get all okay so that's gone alright so there are two ways one is using the customized binary itself and if i do customize and you have to do build customize build and the directory is demo so demo is the let me see into the demo directory so i don't have to type demo every time okay so i can do customize build dot and if you just do customize build and the current directory where you've got the customization.yaml file it's going to spit out the resulting yaml file okay so that's all it's going to do so based on your customization whatever customization you've got you might have got loads of customization so depending on that it's just going to give you a resulting file that you can then apply in your kubernetes cluster maybe you can do this and you can redirect that to a file called my deployment dot yaml and then you can do cube ctl create minus f my deployment.yaml or something like that okay so let me delete that file and if you can see here customize build and you can see the label has been applied so that's the customization that has been applied to my deployment manifest so owner is venket owner is venkat owner is ranked so that's the label okay so how do we apply it customize build dot i can find this to cube ctl create minus f dash okay so that's one way if you're running a kubernetes cluster of version 1.14 or newer customize has been built into the cube ctl binary so you can use it without having to use the customized binary okay so the command is cube ctrl create minus k instead of minus f you have to specify minus k or minus minus customize okay so i'm going to say cube ctl create minus k and dot which is the current directory bar i've got my customize customization.yaml okay so that's done cubectl getall okay so our enginex is running so what's what was the customization we did we added the labels owner is vented to all our resources let's see if that has been applied cube ctrl get all minus minus show labels okay so that's our deployment it has the label owners is venkat replica set it has that label and the part also has that label owner is venkat okay so let's delete this cube ctl delete minus k dot cube ctrl get all okay so that's gone okay so what else can we do so imagine that you've got uh different environments let's say you've got a production environment you've got a staging environment you've got a development or testing environment and so on and you want to use the same manifest but you want to customize it depending on in which environment you want to deploy okay let me show you how you can actually do that so we've got the demo directory and we have this customization at the top level and i'm going to create sub directories for each of the environment let me show you quickly okay inside the demo i'm going to create a new folder called dev and i'm also going to create another folder called broad and i'm also going to create another folder called overlays and another folder called base so i'm going to move the deployment and the customization to the base directory and then and the prod folder under overlay so it might be a bit confusing but if you look in here i've got the demo directory let me show you here okay so i've got the base where i've got the deployment.yaml the actual file that i'm customizing and there is one customization at the top level in the base directory and now i've got two directories dev and broad inside the overlays directory okay let me go back here so i'm going to create a customization file under the dev directory customization.yaml and the only thing that i need to include here is basis okay and the mybase is actually here deployment.yaml customization.js what i actually want to include in this customization remember i'm inside the dev directory so whatever i'm deploying here my idea is i want to customize this for my dev environment and then later i will show you how i will customize the same template for my prod environment okay so basis all i want to do is i want to include this deployment.yaml in customization.yaml so it's i think it's two directory above and it's called base so i'm inside the dev directory so one level above is overlay and another level above is demo and we've got the base directory there okay let's do one customization now name prefix dev dash and what i'm actually doing is i'm just using the same customization.yaml file and the only change the only customization that i'm doing here is i'm prefixing all the resources with the name dev dash let me copy that file and paste it inside the prod and i'm going to change the name prefix to broad that's it so i've just created two customization.yaml file one inside the dev directory one inside the pro directory and i've included all my resources from the base directory and the customization that i'm doing is in addition to this customization that i'm adding the label i'm adding one more customization which is adding a name prefix all the resources that i'm deploying deployment replica set pods everything will have a prefix called dev and in production everything will have a prefix called prod okay let's try this out and let's use customize and see what yaml it generates customize build and this time it's inside overlays dev okay and you can see here name of the deployment is dell nginx and uh the name of okay the part will get its name from the deployment when we deploy it and if i do overlays and the prod directory you can see the name of the deployment is prod slash nginx so based on so we've got this customization inside we don't have anything else we don't we didn't copy the deployment.yaml it's in the base directory and we just have the customization that we want to apply and we just refer it uses the basis directory okay let's try and deploy it cube ctl create minus k and our customization file is under overlays dev okay that's done if i do cube ctl get all and you can see the deployment has the name dev slash nginx and the pawn has the name dev slash engine x replica set dev slash nginx okay let's delete that cube ctl delete minus k overlays dev and now let's try the other one prod cube ctl get all and the deployment name is prod slash prod dash engine x replica set and the part has the name from nginx okay that's cool let's delete that cube ctl delete fraud ctl get all okay so we are good to go now all right what else can we do customization.yaml okay let's say i want to add another customization let's add common labels again here so another layer of customization common labels i'm gonna specify i'm gonna say environment is dev save that and copy and in the prod customization paste that the environment is going to be fraud okay so this time we've got two layers of customization one is the customization.yaml in the base directory itself where we are just adding a common label owner is linked on top of that depending on whether you're using this customization or this customization it will add additional label so environment is dev if you're using the customization under div directory and the environment is fraud if you are using the customization under the pro directory okay let's try and deploy that cube cdl create minus k dev cube ctl get all minus minus show labels okay so we've got the owner equals blanket from the base customization and we also have n is dev similarly for the part as well we've got the owner and the end label got applied correctly and let's do the other one as well cube cto create overlays let's use the prod this time okay and for prod you can see environment is fraud owner is venkat environment is prod owner is venkat that's all looking good okay let's delete it and let's also delete the dev one okay cube ctl get all all right that's gone okay so finally i would like to show you one more thing there are certain things that you can customize like common labels you can also have things like common annotations let's say any annotation if you want name or machine class colon superfast or something like that whatever you want so common annotation so there are i'll show you i'll show you shortly where you can find all these there's documentation for customize that you can do different things so you might be asking how do i know in the customization.yaml how do i know about using this name prefix common labels and what else i don't know so there is a documentation that we can check let me show you right away okay so here customize let me go to the github page and we should have a documentation link there um where is it okay general documentation and installation guide it's under the api reference okay so that's the customization.yaml reference i've used basis i've used common labels common annotations resources patches i'll show you how to use patches images if you want to change the image you can use variables you can use configmap generator where you can create a dynamic config map based on the file based on variables and lots of different things that you can do but i just want to finish this by showing you an example for patches okay so let's go to our code and what i want to do here is let's say i've got this nginx deployment i want to run um two replicas if it's been deployed to the dev environment but if it's been deployed to the prod environment i want to deploy a three replica deployment okay so that's the thing that i want to do for that i'm going to copy this deployment.yaml and i'm going to paste that inside each of these directory dev and prod because i'm going to customize the number of replicas so inside the dev i'm going to create a new file called replica count.yaml it can be any name whatever you like replica account.yaml paste that and i'm going to delete everything except the thing that i need okay and i also don't need the labels okay so just to identify to what resource this particular patch applies to we just need to be able to identify the results that we are applying this patch for it's a kind deployment and the metadata is nginx so by that it can easily identify which resource we are applying this patch to okay so replicas i'm gonna specify the number of replicas has two save the file and i have again going to copy this paste it inside the prod directory and here i'm going to specify the number of replicas as three so that's done the file name is replica dash count so we need to include that in our customization.yaml so under dev directory i want to say uh patches and i'm going to specify much my patch file which is replica count dot yaml let me also copy that and paste it inside the customization in the prod directory replica account.yaml okay so what we've done now is we've created a new file that contains the the patch that we want to apply and it also specifies to which resource we want to apply this patch to and in the customization we've listed the all the patches that we want to apply so let's try this cube ctl get all we don't have anything and if i do customize build overlays there it's just going to show you what uh the yamaha it's going to generate okay so that has generated a yaml and you can see here it has applied the customization owner is venkat environment is dev replicas is two that's the patch that we applied and if i do that for the broad environment you can see replicas is three okay let's do a quick testing cube cdl create minus k dev cube ctl get all there we go so we've got two replicas of nginx running let's delete that and let's create the broad one cube ctl get all okay so this case we've got three replicas of nginx running so our customization has worked very well okay i think that's all i wanted to show you i just covered few little things briefly but if you want to explore further just go to this api reference documentation it's it's very neat and simple tool that you can use to customize and template your your manifest so you don't have to like i said in the beginning so that's the deployment.yaml that i started with but i didn't change that since then give this a try let me know if you've got any questions i'll be happy to help and i will see you all in my next video bye
Info
Channel: Just me and Opensource
Views: 9,024
Rating: undefined out of 5
Keywords: just me and opensource, kustomize kubernetes, kubernetes kustomize tool, kustomize tutorial kubernetes, kubernetes kustomize tutorial, how to use kustoimize kubernetes, kubernetes yaml kustomize, kustomization yaml basics, kustomize demo step by step, kustomize tutorial for beginners, kubernetes manifests using kustomize, kustomize template basics, kubernetes training for beginners, just me kustomize, cka ckad training kubernetes, kustomize k8s
Id: ASK6p2r-Yrk
Channel Id: undefined
Length: 21min 35sec (1295 seconds)
Published: Sun Oct 18 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.