hello everyone my name is Abhishek and welcome back to my channel so today we are at day 18 of our complete devops course and in this video we'll be talking about CI CD yeah so this is one of the videos that is most asked from the day we are doing day Zero everybody has been asking about cicd like I get a lot of comment requests uh asking okay can you please do a video on cacd also I have done a couple of videos on cicd if you watch or if you take a look at my channel so there is a basic CI CD setup that I've explained on also I have explained about a complicated or Advanced cicd setup but it's fine I mean as part of this 45 days of devops course we should also talk about cicd where you know we will try to understand what a cicd will introduce ourselves to the world of cicd what are the different tools that are uh you know part of this uh cicd and we'll also take a look at couple of projects okay so when I'm talking about the projects I'll show you what is the basic CI CD setup that people were using five years ago or you know what is a legacy CI CD setup and how this Modern Day applications like for example we have modern applications like kubernetes kubernetes is a project right Amazon or Flipkart so how these people are doing cicd okay because the Legacy uh cicd setup is not scalable so there has to be a modern day solution uh and we will talk about the modern day solutions for the cicd as well okay now before going there uh what we should understand is what is cicd right because there are many people on our Channel who might not understand what is cicd so for them if I just try to explain cicd very quickly CI CD is basically two steps right one is continuous integration and the second thing is continuous delivery okay so there are two parts to cicd so continuous integration is a process where you integrate a set of tools or you know you integrate set of processes that you follow before delivering your application to your customer and continuous delivery is a process where you deploy your application or you know you deliver your application on a specific platform to your customer for example okay so this is a textbook definition now let's try to understand this using a practical or real time example you have your application let's say you are a application developer and you have developed your application on your personal laptop and your customer is sitting somewhere in the USA or Europe or some other part of the world and you are sitting in a different part of the world let's say okay so how your application is delivered from your personal laptop to the customer who is sitting in a different part of world so this process okay every organization goes through this right whether it's a startup whether it's MNC or whether it is man companies everyone has customers over the globe and your application has to be delivered to your customer in a prompt or you know in a efficient and reliable way that is your application has to be tested right your application has to be scanned for any security vulnerabilities your application has to be like you know there has to be reports which suggest that okay everything is perfect with respect to your application finally you deploy your application somewhere which your customer will be able to access so these are certain steps like for example these are the steps that I explained you and from customer to customer or from a product to product these steps might vary let's say you are a mobile application these steps might increase or decrease okay let's say you are a web-based application or your application is very very secure you are dealing with some government project or something so these steps might increase or decrease depending upon your application but in general there has to be a certain set of standards your company follows to deliver the application to the customer so cicd is a process where you automate all of these things right if you have to do all of these things manually let's say you have to unit test your application every time you have to functionally test your application or perform regression testing on your application every time even a single code commit that is made by developer if you do all of these things by the time your application reaches the customer it would it would take months of time but in the modern day or you know these days you're you are talking about delivering your application in weeks of time or you know in days of time so to achieve that you have to have all of these steps automated right what are the steps so some of the steps okay this this does not have to be uh common across uh every organization or this does not have to be common across every product but some of the standard steps that you follow are unit testing your application right so you always have to unit test your application you have to perform static code analysis don't worry I'll explain about each and everything you have to do some static code analysis you have to do some uh like you know code quality or vulnerability testing because for a customer you cannot deliver application with some security bugs and then you have some kind of like you know automation testing like end-to-end testing of your application then you might have some kind of reporting for your application right where you store all of your reports uh say that everything is working fine all of your checks are verified and finally you might want to deploy your application this is mandatory right without deploying your application your client will not be able to access your application so these are some standard steps that every organization has to follow without these steps you are not sure that you are delivering a right application to your customer okay so now let's try to understand what are these steps each and everything and then let us see how cicd will automate all of these things okay so firstly what is unit testing so unit testing is nothing but let's say you are writing a calculator functionality or you are writing a calculator application where you are writing addition functionality okay so whenever you are writing addition functionality let's say you are writing this in Python what you will do is if you are writing code for a plus b is equals to C so you will pass some arguments like you know in your testing you will say pass two and three and verify that the output is 5 okay so this is nothing but unit testing your code okay you are testing your code in that specific block or you are testing the code with respect to that specific functionality this is called as unit testing okay every application developer has to do this and you know this process cannot be manual because every time uh the application developer is making changes to it uh you know hundreds of times they cannot run this manually before delivering to the customer or before submitting to the uh any any staging or promoting from one stage to another stage then you have static code analysis so static code analysis for let me give a basic example let's say that uh same example I'm writing a calculator functionality and I have declared 20 variables and I will just use two variables okay so the problem is there is a lot of memory allocation that is happening here and you are wasting a lot of memory right so to avoid this what we usually do is that we do some static code analysis to verify that you know you are syntactically right you have well formatted your application okay in some programming languages uh formatting or the indentation is also very important right so you have to verify all of these things like your application is well formatted your application has all the indentation right you did not declare any unnecessary variables or there are a lot of other things so this kind of things are called as static code analysis sometimes your code reviewer or your peer reviewer might not catch all of these things then you have code quality or vulnerability testing that is let's say uh you got a new version of uh Android yesterday and you have upgraded the new version of Android and today you came to know that there is a security vulnerability there can be a hacker who can you know attack your mobile then that's a very bad customer experience right or it's a very bad user experience so before we deliver to the customers or before we promote uh the environment the application from one stage to another stage what we usually do is that we do the code quality testing and then there is automation automation uh by which I mean to say automation testing that is in the first step we did unit testing that is we tested the feature or we tested functional functionality of that specific function uh to a plus b is equals to C what we do is we pass 2 and 3 and see that 2 plus 3 is equals to 5 this is unit testing whereas you have functional testing with functional testing you will verify that you know the change that you have done or the addition functionality that you have written does not impact subtraction multiplication or division functionality okay so you verify your application in a end-to-end manner okay not just your function change that you have done but end to end of your application you verify using the functional testing or end-to-end testing then you have some reports these reports are very essential for any organization like you know tomorrow if somebody asks you what is your unit test coverage how many unit tests pass how many end to end has passed in this specific thing or what is the code quality thing is it fine or not so you need to have reports every organ nation has this they store report somewhere and then finally you have the deployment stage so deployment stage is for deploying your application onto a platform where your customer can access this application so without that no matter what you are doing your application is not available to the customer so these are some of the steps that every organization follows and to do all of these texts manually let's say you are doing all of them manually you will take a lot of time to deliver your application to customers right because it's always not like today you make a code change and you deliver to your you deliver your application to the customer no right so what usually happens is whenever you are writing an application or whenever you are writing a feature you will not write everything in one step what you do is you break them into chunks okay so you create some jira stories for each of the feature or each of the functionality and you keep submitting them to your git Repository right so you store each and everything in your gate repository and every time you are confident about a change let's say again if you go back to the example let's say I'm writing addition functionality I'll write first version of my addition functionality tomorrow I'll write version 2 of my Edition functionality day after tomorrow I'll read version three okay finally eventually maybe on version 10 or version 15 I might be satisfied about my addition functionality and I'll say okay this version 15 has to go to the customer right so before that whenever you are writing this version one version two version three version four all of them have to be stored in some place in general this is called as a VCS version control system or you know it can be any I mean VCS is a name and the different tools for VCS are nothing but your GitHub or your bitbucket or your gitlab some of these tools right so your CI CD is or your CI CD gets executed when you push your changes to one of these tools okay so whenever this application developer is confident about version one what he does is he'll push this version one onto the VCS or version control system from there your cicd process will take care right instead of manually executing all of these things what will happen is once you submit once you are confident about your local changes as a developer once you submit your changes to a Version Control System then your CI CD pipeline will actually take place so what is the cicd pipeline what are the tools so let's start with the Legacy tool and see how it will automate the process Okay so if we start from where we stopped okay so application developer again so he is confident about the version one of the addition functionality that he has written what he'll do is he'll submit that into a git Repository let's say it happens to be GitHub in our case okay so he puts the changes to GitHub now from here all the things that we discussed should take place that are unit testing static code analysis automation testing blah blah blah so what we will do is we will you know deploy a cicd tool for example we will deploy Jenkins in our organization and what we will tell Jenkins is always watch for this GitHub repository and whenever there is a pull request or you know whenever there is a new commit that is made onto this git repository on a specific branch on a specific report okay just tell me that you know there is a change that is made and what I will do is I will run a set of actions okay so what Jenkins will tell is notify me whenever developer is submitting any change onto a specific repo onto a specific branch and as part of the automation Jenkins will run all of the steps that I have told you okay the unit testing static code analysis and all of them so how will Jenkins do that okay okay I explained you that Jenkins will do it so what Jenkins will do is Jenkins will act as a orchestrator or it will act as a pipe or a tunnel okay now what Jenkins will do is that as set off as part of this pipeline tunnel or you know you can consider anything Jenkins will automate a lot of tools in it or it will orchestrate a lot of tools in it so these tools are for example if we talk about unit testing and building the application what you can do is you can run them as part of if it is a Java application let's take Java application so you can integrate your building of application in Maven and running unit as using some uh you know junit or Jack Coco for code coverage or code second okay so let's say you integrate Maven which will take care of building your application and running your unit test and then Jenkins can also integrate something like sonar for your code quality code testing then Jenkins can integrate Alm you know or any other reporting tool for reportings so who will do this devops engineer will install or you know configure all of these tools within Jenkins so that they uh you know they get run whenever your code is committed to the GitHub repository we will also see that in tomorrow's video don't worry about it so Jenkins pipeline is not at all difficult to write we'll start with Jenkins Pipeline and then we will move to Advanced tools that we have been talking about okay and then for example after this happens to be deployment then you can integrate k8s or any Docker platform or you know you can also integrate any ec2 instance or cloud-based VMS so this all things can be automated within your Jenkins pipeline so that's why Jenkins is called as a orchestrator okay what do we call Jenkins as Jenkins is a orchestrator which will facilitate all of these tools okay or it will integrate all of these tools within it by using Jenkins pipeline okay so that's why Jenkins pipelines are very important whenever you are watching for any job description okay or you are looking for any uh you know openings in devops I'm pretty sure you must have heard this world called pipelines or you must have at least uh you know saw this term called as cicd why is it very important because of all the reasons that we just talked about without cicd your applications will be delivered to customer months after months you develop your application right so who is solving the problem or who is ensuring your application is delivered within minutes or within hours that is the CI CD process now we talked about Jenkins so in Jenkins terminology we call them as Pipelines okay so Jenkins pipeline is something that takes care of automating all of these tools and executing the actions that these tools do okay once you integrate Maven your thing is to I mean the pipeline should also integrate Maven and it should also execute Maven similarly sonar Alm k8s or any set of tools that we talked about so with this we'll improve the efficiency of your application it will also I mean so this is step one in step two what you can also do is that like you know uh whenever you are again you are a app developer you are committing these changes onto a git Repository okay so your Jenkins pipeline here can also you know promote your application to different stages firstly your application uh Jenkins can promote your applications to Dev environments then whenever it is confident what it can do is it can promote the application to staging environment and finally it can promote to production what is this process okay so this is a very important thing uh stay with me stay focused I'll explain you in detail so usually what happens is organization divide their environments to multiple things like you know there is a production environment which is very similar to the I mean it is very similar or it is the exact environment that customers are using your applications okay so some in some cases you will use a pre-production environment or in some cases you will directly use a production environment so in terms of production environment this is the exact uh environment where your customer is using your application okay let's say here your customer is using application so even though you perform all of the step steps that I mentioned in the previous slide there is a difference between the environmental environment right so what happens is usually the production environment will have lot of servers are it it replicates the exact setup where you are deploying your application to your customer in staging you might have less amount of CPU or less amount of RAM and and you want to deploy your application before every time you deploy your application to production and Dev is like -1 for your staging so Jenkins can take care of deploying your application to multiple stages okay so the reason why your application has to be deployed initially to Dev platform is your queue Engineers would firstly want might want to or you know your automation might want to execute uh initially on a simple environment like you know a very simple easy to instance and once uh things are looking good your Jenkins can automatically promote using some manual approval or automatic approval once everything are looking good on the dev platform you can do an automatic approval and using this automatic approval Now application will be moved from Dev to staging environment so in the staging environment like you know instead of a simple ec2 instance you might have a cluster here okay maybe using Auto scaling you created two easy new instances or maybe you are using a kubernetes platform where you have uh here you just might have one master and one node here you might have uh three Masters and five E nodes or five worker nodes and in the production you might have some three Masters and some 30 worker nodes okay so every time before you reproduce this environment on production or before you deploy your application on production you might want to test it on a single node kubernetes cluster which is your Dev environment then you might want to go staging which is your three master and fine node architecture and then you might want to actually deploy to your customer so why you cannot have production like environments uh even in staging is because this is a very costly setup right so your customer you might give you a very cost you might give a very rich and robust setup but every time you want to test it with your local testing team or your local QA team you might not have that rich setup so that's why you deploy your applications onto Dev and staging environments right are things clear till now so if you have any questions till now or till this point of time definitely post that in the comment section so that I can understand okay at this time stamp you did not understand something so please also put the timestamp so that I can take this as a constructive feedback and improve myself next time okay so now once you understood all of these things okay so this is of Jenkins which is a legacy tool the reason why I'm stressing it as a legacy tool I don't mean to say that uh Jenkins has not used these days or I don't want to like you know uh defame Jenkins but the reason is that Jenkins has been a tool that is like you know people started with Hudson like I mentioned you so this was a tool that was used like everybody might have started with Hudson or Jenkins if they are a developer devops Engineers from seven to eight years back and then people eventually moved to uh Jenkins okay and uh you know everybody uh start dealing with on-premises first and then they move to Cloud platform but these days everything is micro Services right if you look at uh for example Twitter or if you look at uh some applications like uh Flipkart or Amazon so they are basically some thousands of micro Services right there are basically some thousands of services now to deploy these thousands of services okay Jenkins is a platform tomorrow you will understand whenever we are deploying Jenkins so Jenkins is nothing but it's a binary okay and what you will do is basically you install Jenkins on one host probably your laptop or your ec2 instance and then you keep adding machines to it because there are hundreds of developers in your organization and one Jenkins node cannot take all the load so what usually you do is you deploy your Jenkins Master on one ec2 instance and then you keep connecting multiple ec2 instance to it and then you will say let's say there are 100 developers or then there are 10 teams you say that okay for team one uh every job that is running or every change that is made to your GitHub repository run the pipeline on node one for team two run it on node two for team three run it on node three four five Etc okay now the problem here is that this has to scale up right so if there are 10 teams in your organization you might create some 10 Jenkins machines okay and again for each uh development team inside that specific team you might want to uh set up some additional VMS for running the nodes on specific or running pipelines on specific nodes so this setups become very humongous right because every time you scale up this Jenkins instances you know you have to create lot of lot of computer okay so compute is basically very costly even in during our virtual missions class I explained you that compute is basically your RAM right your CPU and let's say your Hardware okay so this is your compute now when you keep adding compute to your Jenkins instances the setup becomes not only very costly but the maintenance also becomes very huge okay so instead you should actually look for some setups which can scale up and scaled on automatically so people might ask one question here okay I can integrate my Jenkins with auto scaling groups and I can scale up and scale down automatically but see we are talking about some real time things right let's say you have to scale your Jenkins to complete zero you I don't even want my Jenkins masternode to exist that is not possible because there are times let's say uh during your weekends or uh during uh some odd times there is no I mean there is some zero code changes that are made and zero pipelines that have to be executed okay in case of thousands of micro Services where you have some 20 to 30 Jenkins uh instances and uh 20 to 30 Jenkins setups okay we are talking about 20 to 30 Jenkins masternodes and again three to four worker nodes so if you are not configuring them well so at any given point of time you have some hundreds of virtual machines which are created but not used but my condition or my requirement is that I have to have zero servers when I'm not using any or when I'm not making any code changes so in such cases Jenkins is not a tool that you should recommend okay so let us see how this Modern Day applications okay let us take a look at one example because these days most of this you know there are some applications that are highly scalable and they are open source so let us take a look at one very popular open source application that is kubernetes and let us see how kubernetes is managing these things because you know kubernetes has some thousands of developers okay they are in different parts of globe and they usually communicate using GitHub right so let us see how kubernetes is handling these things whenever a developer in India making a code change to GitHub repository of kubernetes how kubernetes is dealing with the code change and how it is ensuring that it is not wasting the VMS that I just explained okay so let me stop sharing this one and start sharing a new screen foreign and then let me share my browser here so this will be really interesting and uh I would request many people who don't know uh the GitHub actions or gitlab pipelines to just like you know if you have any questions don't worry I'll definitely explain these things in tomorrow's class where you will be definitely able to understand the setup so I have increased the font and see here this is the kubernetes GitHub page similarly you will have uh GitHub repositories or gitlab repositories in your organization as well where developers will commit the code changes to this version control system so if you see here kubernetes has 3347 contributors that are developers now anytime any developer might do a code change but at this point of time no developer is making code change because I am not seeing any new comments to master Branch or I am not seeing any new pull requests so by the time I logged in there are 761 and even now there are only 761. so let us see how kubernetes is handling Whenever there is a pull request or whenever there is a commit that is made so if you go to the pull request okay so the last pull request was four hours ago so for the four hours there is no code change that is made or there is no pull request that is made so the expectation or the ideal scenario should be for this four hours okay from past four hours there should be zero compute instances kubernetes project must be wasting okay if not you are losing a lot of money for your organization you are wasting a lot of money for your organization so if you see this pull request what usually happens is they have configured it using GitHub actions okay so here what they are doing is they are running the entire thing using GitHub actions so GitHub actions is another way of doing CI CD just like Jenkins and what happens here is whenever a code chain is made it will spin up a kubernetes pod or you know a Docker container for you and everything gets executed on the docker container and if you are not using it then you know the server or the worker which is used to run these Docker containers will be used by some other uh projects like you know you do a shared resources so in the concept of shared resources the advantage is that so kubernetes project there are uh like you know if you go to the kubernetes organization here there are some 77 repositories or you know if you are using GitHub actions uh and if you are using runner from GitHub itself or you're if you are using Runners from Microsoft Runners are nothing but worker nodes from Microsoft so what Microsoft will do is that it will create containers for you or kubernetes pods for you on the Microsoft servers itself or the Azure servers itself so you don't even know where the servers are getting created and if it is a public project or open source project you will get it for free so let's say you don't want to use Microsoft okay and your code is secure what you can do is that let's say for this 77 repositories you can create one common server okay you can host the server on Azure you can host the server on AWS or it can be kubernetes cluster anywhere in the world and what you can say is that whenever a developer is making commit on any of the 77 repositories okay so what you will do is you can create a kubernetes pod on this kubernetes cluster and once the execution is done all of these steps are done just delete the part so that I'll be free one more time okay then any other project can use that kubernetes so what you have done here is instead of wasting resources for each and every project instead of creating Jenkins instances for each and every project you can create one common GitHub actions which can be used across multiple people in your organization or multiple projects in your organization and you can basically you know save your resources save your computer and if nobody is using it there is no wastage because the server size is shared across everyone so literally you are using zero compute instances when there is no code change so this is about your modern day CI CD setup I'll also explain you in T10 whenever we are going to talk about future projects in tomorrow slash and Day After Tomorrow class and one more Advantage is that you know your Solutions are extremely scalable that is uh today if you are using a Jenkins instance every time you have to add one more server what you will usually do is you keep adding one more worker node or you just you know make any additional worker node and attach them to your existing Jenkins setup whereas in terms of kubernetes you all know that easily you can increase one more node and you know you can scale it up to 100 000 or whatever you would like to and if it is a manage kubernetes cluster on eks I mean or Amazon or something you can directly add nodes scale up these nodes or scaled on these nodes right make sense so this is uh some examples about cicd today basically uh today we did not discuss uh practically about anything I just wanted to show you one real-time project so most of this open source projects use GitHub actions okay so one more tool that I wanted to introduce you many people uh definitely you know whenever you watch the Youtube videos or whenever you start uh working with a cicd for the first time you will definitely start with Jenkins but you should also understand that there are very good Alternatives so there are projects on GitHub there are projects on gitlab there are projects on You Know Travis CI there are products on Circle CI so these are all Alternatives and these are all emerging cicd Solutions so even if you don't have good knowledge of how to implement them one should definitely understand the Alternatives and you know eventually every everyone might move towards it like if you ask me uh I like GitHub actions over Jenkins because of the reasons that I just explained you right for example if I have to compare let's say you will ask me to compare uh definitely in future I'll do a video where I'll compare uh Jenkins with cicd but there are many advantages with actions like they are event driven um even Jenkins is even driven but you can only configure pull request action using some web hooks or you know whatever web hooks that githubs are supporting but if there is no web hook configuration for Jenkins by default it is not event driven whereas GitHub actions are default event driven continuous integration and continuous Delivery Solutions and you know you can also what you can do with uh GitHub access is you can integrate your pipelines uh from one project to the other projects as well so there are many advantages that GitHub actions provides you and uh in tomorrow's class and day after tomorrow's class we will try to experiment them on one project using Jenkins as well as GitHub actions so people also asking about are also asking about gitlab pipelines or gitlab cicd so don't worry about it like you know we cannot cover all of them but if you know GitHub actions gitlab cicd is very similar even if you to take an example on gitlab you can search for search for that on stack Overflow or something you'll find them exactly similar only the only thing is that there are syntactical differences and symmetrical differences that's the only thing okay so I hope you like the video today and uh if you are waiting for tomorrow's video just post that in the comment section uh share your feedback for me on Twitter on today's video and I'll be waiting for you in tomorrow's video I hope all of you joined tomorrow's video and perform a practical scenario thank you so much I'll see in the next video take care everyone bye