Set up complete CI/CD Jenkins pipeline for kubernetes - Part 11

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is rahul and in today's session we are gonna talk about how to set up the jetkins continuous pipeline for deploying your application inside kubernetes cluster but before we begin there are certain component which we need to talk about the first component is your application that application can be a java application uh it can be a python it can be a node chairs or it can be an angular application the second component which you need is you need to have a github or svn a versioning tool where you can push your code the third component you need a jenkins you need to install jenkins so that you can create your pipeline the fourth component you need a docker you need to install docker as well as you need to create a docker hub account because we need to push our docker image inside our docker hub you need to have some container registry online where you can push your docker images the fifth and final component is your kubernetes cluster you need to set up your kubernetes cluster and what i prefer i prefer setting it everything on my local machine i'm not using any cloud service provider so if you haven't done it before you haven't set up any kubernetes cluster before then i'll put this link into the description as well as here so that you can follow that video uh where i have shown you how to set up your kubernetes cluster using cube spray so that you can set up your kubernetes cluster on your development machine okay so talking about the component uh after that we need to see the workflow how our workflow flow gonna look like so there are certain steps we will be covering all these steps in the workflow so let's check out the workflow so this is our workflow on the left hand side you can see step number one where we are going to push our code to the github repository after that we are going to install jenkins and jenkins will be responsible for cloning the code from github to the jenkins server so that it will have a copy of our application code inside our jenkins server the third step is we are going to compile our project since we are using springboot application so we are using griddle as a compilation tool but in case if you are using any other application then you can use suitable compilation tool but step gonna be a pretty much similar the fourth step we are going to prepare a docker image of our application after the successful compilation and after that we are going to push our image to the docker hub and the next step we need to pull that latest whatever image we have pushed into the step number five we are going to again pull that latest image in the step number six because we need to deploy that latest docker image into the kubernetes cluster so after we pull that latest image in the step number six we are going to push that not push but we are going to deploy that docker image inside our kubernetes cluster so this is how our workflow looks like and throughout the session i'll share this guide with you and you can find the guide link into the description so where i have documented all the steps which is required for setting up your kubernetes pipeline so please check that link and you don't need to remember any commands or any instructions during the video you can come back to this guide and follow the same and this is going to be our final goal i showed you this is the dashboard but we are going to accomplish all this step uh throughout the session so as a prerequisite as i already told you we need a vagrant virtual box and some ide it can be any sublime atom or visual studio or intellij and then you need to have a kubernetes cluster so kubernetes cluster you need to have it that's a pre requirement uh you can use google cloud platform or aws if you want to provision your kubernetes cluster already somewhere on the cloud services otherwise you can pretty much set up this kubernetes cluster on your local development environment also so you can follow this link where you can use cube spray to set up your kubernetes cluster so this is the guide for setting up kubernetes cluster on your local machine so that you don't have to use any google cloud or aws cloud service provider okay so i am assuming uh like you have done this step because if you haven't done this step previously then there is no point moving forward so i would highly recommend to set up this cluster and one more thing if you are not interested in this blog post and there is a youtube tutorial a complete lab session where i have set up the kubernetes installation using cube spray on my local machine so you can follow this video tutorial also where you will be able to set up your kubernetes cluster if you are not interested in this complete long guide but anyways ah you should do this and i am assuming before you move to any of the step you have done all this requirement all right so let us move to the step number one so in the step number one uh here i'm trying to explain our setup how it's gonna work and how it's gonna look like so primarily we will have three servers one will be jenkins server and second will be kubernetes master node and third will be kubernetes worker node so this is the jenkins server on the left hand side you can see in the diagram that's a jenkins server running on the ip0.100.0.0.1 so that is done via vagrant file i will show you in the next step so this is our jenkins server with this ip and from here we will be automating all the kubernetes deployment on these nodes so that is running on 100.002 and three so that is our kubernetes master node and that is kubernetes worker node so we will be working primarily on this jenkins server and nothing else so everything we are going to do we are going to perform on this jenkins server to add some more detail uh this is the configuration which i am using so jenkins server i am running on two gigs of memory two cpu and this is the ip range i have assigned so pretty much i am as i have assigned the same memory and the same number of cpus and this is my vagrant file which i just talked about so this is the vagrant file for provisioning uh this jenkins server so if you don't know and about vagrant then please follow just google it it's a very simple virtual environment setup tool which you can use so this is our jenkins and this is our kubernetes master and kubernetes worker so if you look on this vagrant file carefully so here we are setting up everything so this is our janken server where we have assigned two gigs of memory and two cpu and similarly this is our kubernetes master and this is our kubernetes worker so you just need this vagrant file to start your virtual environment so uh yeah this is the step number one which is like a primarily a very brief overview how our setup gonna work moving to the step number second here you can see this is the workflow and i think we have covered this workflow so we don't need to repeat that part so we can move to the next stage okay so the step number third which tells us like you need to install jenkins on your jenkins server so as in the flow diagram you have seen this is our jenkins so we need to install this jenkins and this jenkins will be installed on our sorry i just moved back but this jenkins will be installed on this server okay so that we need to perform first of all that is our primary requirement so what you can do is you can just follow this instructions so you need to start your wakaran box so for your reference i have already started my vagrant box here so that is up and running so i don't need to start it so if you haven't started then please do start your vagrant box okay then you need to login into jenkins server okay so that i think i logged into another instance so i will exit it from here and i can show you the vagrant file also which is okay so this is the same vagrant file which i am which i just showed you so this is jenkins server this is master and this is worker okay so now i need to login into my jenkins server jenkins server okay ok so now i am logged in into ah jenkins server and here you can see the ip address of this one all right so after login i will clear the screen so that is done we need to update our server repositories so this is the command which you can use uh because uh since this is your going to be a very first vagrant box and the first thing which we need to do is we need to tell ubuntu i am using ubuntu uh as a my os host os so you need to tell it to upgrade it ah not upgrade but at least update its repository so that we can install certain packages ok so that is being done now we need to install the java because java is needed for running the jenkins okay so you can copy this command and pass it over here so that is going to install open jdk8 and do you want to install i will press yes okay so i think uh java has been installed and you need to verify the java installation uh using this command so that you know that you have installed the java successfully so you can paste it over here and as you can see we have installed the open jdk version 1.8 so that means java has been installed okay i'll clear the screen so that we get a little bit more space to see and yeah this is the output i have pasted it here for the reference okay so now i am assuming you have installed the java on your instance successfully next thing we need to install jenkins and for that you need to copy uh not copy but yeah you need to have this package so we are going to use this command and since i am doing it on uh ubuntu but if you are using red hat santos or fedora then please refer to the documentation provided by jenkins because there are little different documentation for different operating system so please follow this official guide ah where if you are using any any other operating system okay but for the time being i will use this command since i am using ubuntu and yeah you just need to copy and paste everything so you do not have to remember this this steps because this is the one time setup you need to do it okay paste anyway and yeah that's done and then i'm going to update it all right that's done and then i'm going to install it okay i'll press yes so basically i have just added that repository info of jenkins into our ubuntu system and after that i have updated the repository and after that i have installed the jenkin so it is going to download all the required binaries and it is going to perform the installation okay so now jenkins has been installed so next thing which we need to do is we need to verify the jenkins installation okay so since uh i am using a virtual environment and i have assigned a dedicated ip for my jenkins instance that is 100.0.0.1 so i am assuming uh that my jenkins will be accessible on this port followed by my ip address so in case if you have assigned a different ip address then please carefully replace this ip address with the ip address which you have used okay so copy this url and paste it over here and you should see a initial login page okay so here you can see unlock jenkins and you need to provide one time administrator password initial admin password okay to unlock it all right if you are able to see this screen then that means you have successfully installed jenkins okay the next step we are going to fetch the password okay so here is the screenshot which i have pasted for the login screen for your reference okay so the next step would be we need to fetch the default jenkins password which is needed here okay so how to fetch that so there are two ways actually uh one is using this uh jenkins dot log file and secondly you can use this help which is provided by this jenkins login page so you can either view this file or you can verify the jenkins lock file also so i can show you the both way so first of all this copy this command or you can copy this command from here also that is cat and followed by the complete path so you need to go back to your terminal i'll clear here and paste it so here you need to carefully look for this thing so this is your password okay so that is the first way to find the password i'll clear it secondly you can find the password from here also so just copy this and i have mentioned the same thing over here also so once you will use this jenkins.log file then you will see some password something like that and please don't use this password this is when i did it so this is mine password it will not work for you so you need to find your own password okay all right so second way is you need to copy this path and go to the terminal and paste it over here okay so permission denied i'll use with sudo i think i'll clear it anyway sudo okay i think i messed it up so it should be sudo cat and here is the password which you can copy from here and you can go back and paste it over here okay and click continue so once you provide the password it will ask you for the install suggested plugin ok so just go with the default and click here and it will by default install some default plugin which is needed for running the jenkins and it might take some time so i'll be back once this this is done okay all right so once you have installed the default plugin it will ask you to set up a admin user and the password that is needed for uh the login when you are trying to access the jenkins portal so at that point it needed for uh to login inside your jenkins instance okay so i i'm going to put the password and username so i'm using admin admin and password is also admin so this is just for demo purpose so i'm just not going to put some real detail over here so all right okay so once you set up all this thing just save and continue and here uh just be careful like the ip address it should reflect the same ip address of your vagrant machine so that should be same since i am using 100.0.1 0.1 so it should be the same and the port is 8080. if you don't remember this then just copy it store it somewhere okay so click save and finish and start using jenkins okay so if you see this message welcome to jenkins that means you have successfully installed the jenkins and you have also set up the admin user which is needed for a jenkins okay let's head back to our guide and see how many steps we have done so i think we have installed this custom plugins at the default plugins after that we have set up the administrator username password also then we have checked the jenkins url also that is also correct and our jenkins is ready yeah that is it okay so now we have i think pretty much done with the jenkins installation and we are able to access the dashboard also so the next step we need to install some special plugins ah that is our step number five and the plugin which i am talking about is ssh pipeline steps plugin okay don't worry if you don't understand why we need this pipeline uh plugin but in the next steps i think uh during later somewhere in this lab session we are going to use this plugin for deploying our application inside kubernetes cluster okay so copy this name ah this is our plugin which we are going to install so you need to copy it and go to manage jenkins go to manage plugins then available and search here so it should pop up here because since we have not installed so we need to install it okay so click click this plugin and install without restart okay so it should take maybe a minute or so and it should be installed okay so now it is it has been installed go back to jenkins all right so i think we have installed that plugin uh let's head back to our guide and and there is a one more step 5.1 5.2 so 5.1 is done where we have installed this plug-in ssh pipeline steps plug-in uh next thing uh we need to set up gradle okay why we need gradle since we are using springboot application so gradle is the default build tool we are using uh if you are familiar with java applications then i think there is one more famous maven build tool which you can also use but for this session i am using gradle and we need to set up gradle uh to build your springboot application okay to setup we need to go to manage jenkins then global tool configuration so this is the path you need to follow okay so go to manage jenkins after that global tool configuration and after that you need to scroll down and here there is a gradle okay so we need to set up the gradle okay so for that what you need to do is ah you need to click on this eight gradle okay there is eight griddle okay i have clicked it then you need to assign the name what is your default installation so i am keeping it default so you just go ahead and put the name default okay then you need to specify install from gradle.org so what version of gradle you're gonna use so i'm gonna use the gradle 6.7 the default one okay and then after that click apply and then click save all right so now we have installed gradle let's move to the next step which is step number six and we need to install docker inside our jenkins server so the next requirement is we need to have a docker which is uh installed inside our jenkins server so if you are not logged in into jenkins server uh then you can again use this command to login log back in but we are pretty much already into the jenkins server so we don't need to log back in i'll clear it and then what you need to do is you need to use this command sudo apt install docker dot io so it is going to install to docker inside your chankin server okay so i'm gonna paste this command over here and hit enter so press yes i wanna install it might take some minute or so so i'll be back when this installation is done okay so i think we have installed docker and the next thing which we need to do is we need to verify the installation of our docker so what you can do is uh you can run the command i guess some docker command here so i'll clear it okay so yeah i can run the docker command and i can see the help documentation and i think i can run the docker version also okay here you can see we have installed the docker okay so that means you have successfully installed the docker on your jenkins server okay but be careful we are getting this issue so first of all we need to solve this issue so there is a docker.sock file once you install docker on your linux operating system then by default you don't have a permission on this docker.sock file so we need to first of all have a permission otherwise we will not be able to go ahead in this hour in this our lab session okay so first of all let's go back and check in the guide okay so here in this guy there is a step 6.3 which tells about this issue where we need to give the permission okay so to add this permission uh what we need to do is we need to add current user the user which is logged in inside right now okay so that is our current user which is vagrant and we need to assign this user into the docker group so we need to add this user into the docker group so that we have all the permission on this docker.sock file okay so copy this command head back to your terminal and clear it and paste it over here ok so once you done this then you should be able to access that sock file okay so to verify that error has gone what you need to do is you need to exit and log back in okay so that that the user has been added to that docker group so i will exit it from here okay so i'm now exit from my background machine of jenkins server i'll clear it and i need to re login in so i log back in okay i'll clear the screen here and i'll rerun the command docker version and here you can see now that error has gone the permission issue on that docker.sock file has gone okay so that means our docker has been installed and we have added current user to the docker group okay moving to the step number 6.4 here what we need to do is we need to ins add jenkins user also to the docker group okay because uh we are going to use uh jenkins for running or building the docker image so if you go back to this guide here in the diagram you can see so this jenkins is responsible for building the image so if you want jenkins to build the docker image then jenkins user should have a permission to run this docker command okay so for that what you need to do is you need to add that jenkins user to the docker group okay so i'll copy this command and i'll clear the screen and paste it over here okay that has been done and for safer side i'll exit it and i'll log back in so that that user has been added to that group the jenkins user has been added to that group okay so i'll clear it and that is done okay so now we need to move to the step number seven and here we will look on our spring boot application actually what is our spring boot application is doing and why we are going to deploy it so in the step number seven this is our very basic uh web service which is a rust web service and it is returning nothing but a simple hello world message okay so that is a springboard application which i am going to deploy inside our kubernetes cluster but this whole tutorial you can use it uh for any other application also since this is a springboard application that this part you can replace it with any angular node js or any other application on which you can containerize it or we can create a docker image okay so this is a very basic code ah which you can find it over here and i'll put the source code github repo here also the link so that you can go and browse secondly we need to have a docker image we need to create a docker image so for that purpose we need to provide a docker file so basically it is doing i can show you the code here so this is the whole code and this is our docker file so this docker file is responsible for building the docker image so it is going to go inside the build ellipse directory and going to pick the jar file okay so you just browse around this code so it's pretty simple uh code with the hello world application all right so this is our code this is our docker file which is responsible for creating the docker image of our springboot application okay so this is just a small walkthrough of my application which i am going to deploy inside kubernetes cluster okay okay so the next step should be our step number eight where we are going to write our pipeline script okay and this is going to be a little long step because here we are going to tell everything uh to jenkins like what we need to do or what you need to do as a responsible person for setting up the continuous pipeline okay so moving to the step number eight what we need to do is first of all we need to create a jenkins pipeline so go back to your jenkins and click to the new item here input the pipeline name so here i am taking the pipeline name as a j hook spring boot you can take whatever you want and after that select pipeline and then click ok and that should create a pipeline for you and you can verify by going back to the dashboard and this is the pipeline okay so this is a blank pipeline there is nothing in it so we are going to fill in the values not values but scripts jenkins script so that we can deploy our application okay moving further 8.2 we need to clone the git wrapper so as i explained uh the jenkins will clone the git wrapper whatever code we have in our github it is going to clone so first of all we need to write this script this is going to clone our github rapper okay so this is the url which i am providing and as well as this is the github credential that we need to provide okay so this is the script which we need to uh provide inside our pipeline so go back to your jenkins this is the dashboard and the pipeline which we have created click on it and go to configure and then go to pipeline okay so this is where we are going to write our pipeline script so before we begin so first of all we need to write node and after that we are going to write our script okay so you can copy this one this thing this stage everything we do we do inside in jenkins as a stage so consider step similar to a stage okay so this is our stage number one where we are defining git clone this is a user defined name you can put whatever you want for your reference second you need to provide the grid credential id ok i will explain this what is grid credential but first of all let us check the url because the url should be always be correct okay so this is my url and you can copy and paste it over here so that you are sorry you are not providing incorrect url okay so yeah my url is correct and then i'll click apply and then save okay so my pipeline uh first pipeline script is ready where we are trying to clone the github repo but there is one thing which we haven't done it yet so go to pipeline again and here you will see there is a github credential so this is a username and password of my github account okay because jenkins will go to github and then from there it will fetch but while fetching it needs username and password to access the github rapper okay so we need to create this username and password okay so go back to your guide and here i have shown you how to create it so first of all go to jenkins then manage jenkins and manage credentials okay so go back to jenkins then manage jenkins then manage credentials okay and after that uh once you come to this screen then you need to click on manage credentials okay so yeah after that you will come over here and then you need to look for store scope jenkins ok so here this is the option we are looking for and here you need to click on global then add credentials okay just follow with this guide i have taken the screenshots also so here what you need to select is from the drop down you need to select username with password because we need to store github username as well as github password okay so username is password it is selected and let's check okay and scope is global jenkins yeah that's fine and this is the username i need to fill in so i'll put in my uh username rahul wag and after that my password so this is your github password you need to key in okay then you need to assign the id so this is the id i am talking about okay so if you look our pipeline script so here i am using this id so github credential so this id is coming from here here we are creating it and for description you can put whatever ah which suits your ah which helps you to understand what it is actually github credentials okay then click ok and this is your github credential all right so now your first stage is done for the jenkins pipeline okay so let's go back and verify once again pipeline okay so yeah it's done so let's run this pipeline we have not completed yet but we are going to perform one step and we are going to run it to verify it okay so uh just build now and as you can see this is building this is our git clone stage and one side this is green that means our stage one has successfully completed and if you will go here and then you can see cloning the repository this is the repository we have cloned so our step number one is completed and this is our github credentials which is used internally by jenkins okay all right so again i will go to configure and then pipeline okay so our stage one is done then we are going to write our next stage so go ahead in the guide and i think we are done with the grid credentials tape also then what our next stage is we need to build our java application the spring boot application we have cloned our github repo so the java code is with us ah with jenkins actually so if you see this diagram so jenkins is having our all of our code okay so now we are entering into this step where we are building and compiling ok so this is the step where we need to do so this is again as you can see it is pretty simple stage you can put the stage name whatever you want and then the build command gradle build okay so i will copy this and go over here and paste it over here click apply save okay and see once we start building it this steps will keep on adding so we are we only added git clones that is why this is good clone stage and then now i have added a build step okay so i'll build now and here you can see we have a git clone and after that we have a gradle build okay and this build is still going on and you can click on this console output also if you are interested then you can see this is where our compilation is having with the gradle that is compiled the tasks are running if you see previously so it has already cloned our spring boot repo okay so as you can see build is successful now we can go back and verify so this is our stage number one this is our stage number two all are green okay okay so now we are done with two stage let's go back to our guide and what is the next stage is we need to build the docker image and tag it okay so now we have cloned it uh so let's check our flow diagram so we have cloned it we have build it using griddle and now we are going to prepare a docker image so for preparing the docker image we need to copy this stage so this stage is also very simple so this is a stage and script where we are starting this stage this is just an helper command which i have put it just a docker version command so that i can check which docker version is running inside my jenkins after that this is our docker build command which is building my spring boot application not building but it's building a docker build actually then after that docker image list that will tell us how many build docker build images i have created and then i am finally i am tagging with the name j hook docker demo okay so my docker image name will be tagged with this name okay so this is the stage of our docker build so i'll copy it go to pipeline and then again go to configure go to pipeline as you can see step stage one is done two is done and this is third which i am going to insert it over here okay so this is just a docker build we are doing so apply save and then build so now it will add one more third stage over here okay so it has started it's going on it has cloned now it is doing a griddle build and now it's doing the docker build and i think it's done as you can see it's success so our three stages has been completed you can verify with the logs also so if you see over here uh i'll show you this is the last stage where we did the docker build sorry not docker build a gradle build and this is our third stage where we have checked the docker version if you check our script so this is our docker version first of all after that uh yeah here then i am performing my docker build command okay so that is happening with this after that i did docker list images docker list images and these are the images which i have built over inside my jenkins so this is done by this and finally i am taking it with this docker hook j hook docker demo name okay and that is you can see from here all right so now we are done with the creation and tagging of a docker image okay so let's go back to our guide and the next step what we need to do is we need to create a docker hub credentials in our manage credential inside champions okay why we need because in the next step we are going to perform a docker login i'll explain it later but first of all let's go back to jenkins go to manage jenkins go to manage credentials go to here global add credentials and here we need to create a secret that is our docker hub password because from the jenkins if you see over here this jenkin is responsible for pushing our image to the docker hub so we need to push our final image to this docker hub okay but to push anything into the docker hub you need to authenticate your jenkins and for authentication purpose we need to provide username as well as the password okay but we can provide that username in the command line as you can see over here this is the docker login command line interface cli where you can just perform a docker login with you stands for username and that is your username and then p that is password since i cannot disclose that password as a plain text over here so that's why i need to create and store it inside my jenkins as a secret okay so that's why i need to create this secret and i'll copy this id you can keep this id whatever you want i'll show you how it is so what you need to do do over here is you need to go here and select secret file because i need to uh not secret file secret text actually i need to store my password so i want to store my password as a secret text okay and here i am going to put in my actual docker hub password okay so you need to have your own docker password ready with you after that you can create or assign an id that id can be anything which you can remember and which is uh some meaningful name so i am keeping the name as a docker hub password okay and in the description just put some helpful text like a docker password and then click ok so here you can see previously we have stored github credentials and now we are storing the docker hub password here okay now that's been done go back to jenkins and then go back to our pipeline go to configure see you can see our previous build uh git clone gradle build docker build now we are adding fourth so configure go to pipeline and then go back to our guide and this is our docker login stage so here i am providing my username and the password which i have just stored inside our manage jenkins secrets copy this stage go to pipeline go to the new line paste it over here apply and then save it okay and then you can build the pipeline and that should add one more fourth stage to your build that is your docker login here you can see this is our docker login okay so that's been successful and we can go and see over here and there should be a docker login there it is this is a docker tag and after that this is our docker login which is also successful okay so login succeed so this is the message which you need to look for all right so let's go back to our guide okay so here this is my guide and now we need to do is what we need to do is we need to push our docker image into docker hub so just go back to our flow diagram so now we are done with the login also now we need to perform actual fifth step that is push our latest image to the docker hub okay so till now we are just preparing everything so we have built the image we have authenticated jenkins so that we can push the docker image so for that this command is pretty simple this is our next stage push image to docker hub and the command is docker push and then the user name and the docker hub repository okay so here you can see this is my docker hub repository if you haven't done it so i think you can go to docker hub and you can create your own repository from here you can click on here create repository and it should create something similar repositories for you okay so i have already done it and i'll show you one more thing over here so as you can see i have pushed my last image two hours ago okay but this this will get update ah once we push our latest image all right so i'll copy this command this is not a command this is our jenkins script so go to our pipeline configure into the pipeline and here we need to add one more stage push image to docker hub docker push your docker hub repository name and the image with which you have tagged it so that is j hook docker demo okay apply save and now we have already done with the fourth step now we are adding fifth one okay so as you can see this is our push image so here our jenkins is pushing our image to the docker hub and if you go to the console output then you should see something yeah docker push to this docker hub repository and it has already pushed all our images and that is success so go back to the status where we can see yeah everything is green and now our push image to docker hub has been successful so let's go back to docker hub and as you can see uh previously i have done it two hours ago now i will refresh this page and as you can see it is a few seconds ago so our chankins has pushed the latest image of our springboot application to the docker hub okay so we are done with this our fifth stage so till now we have pushed our image to the docker hub okay let us go back to our guide and see what is the next stage is so after pushing the image to the docker hub the next stage is we need to ssh into our kubernetes master server okay so previously we have installed and plug-in that is ssh plug-in for our pipelines if you remember so that plug-in you can see from managed jenkins go to plug-in yep here it is and installed and there should be a pipeline plug-in i guess wait that should be ssh pipe line this is the plugin okay which we have already installed so this is this plugin is required because we are going to perform an ssh login into our kubernetes master node so that we can perform the deployment okay so now we have already installed and i have covered it in my previous stage previous steps so what we need to do is we need to create one more stage that is ssh into kubernetes 8 server our kubernetes master server and here we need to specify this is the syntax of this plugin this is how you are going to provide the ip address of your master node uh using the host name remote.host here you will put in your ip address the name you can keep it anything whatever you want and the username and the password for login since it's a vagrant virtual machine that is local to me so i kept it as a plain text username and password but as i told you we cannot keep it and i just showed you how you can create secrets and jenkins so pretty much you can follow the same step to create a secret for username and password also okay so i'll copy this stage and yeah copy it once more i think there are some problem and go back to our pipeline and configure go to pipeline and here after this we are going to add it over here [Music] okay click apply and click save okay so now we have added one more stage so where we are going to ssh into we are going to perform an ssh login into kubernetes master server ok so now we can click on build and it will take it will go through all the steps once more and we should wait for a minute and then it should be ready okay so now our next stage is done that is ssh into kubernetes server and you can see it from here in the console output that should be somewhere in the last yep so that is success and i think this is somewhere here we have performed that login it is not visible in the console yeah here it is okay so now that stage is also done now we are logged in into kubernetes master node and we can perform our deployment so the next step is we need to copy this uh configuration yml that is k at springbootdeployment.yml into our kubernetes master node so from where this is coming so if you see our workflow we have cloned the github rapport into jenkins server so in the github repo i have created this file if you come back to this github rapper here you will see this file which i have created so this uh yml configuration is responsible for deploying your docker image so if you remember this is our docker image which we recently pushed to docker hub this is the username and the docker hub image name and i am referring to the same docker hub image over here okay and this is the deployment uh configuration which i have specified for kubernetes inside this yml and after that there is a one service whatever deployment i am doing i need to expose that deployment as a service on the port 8080 okay so i have created this yml already so once you are following this whole workflow then you will get it this yml if you are having some different github rapport then please update this via ml and or either copy this yml and update it according to your docker hub image name okay so what we need to do is we need to go back to our guide and see what the stage says so in this stage what we are going to do is we need to copy this file into the kubernetes master current directory okay so here i'll show you uh this is my kubernetes master server and this is my pass current path where i'm working current directory and here you can see there is no such a file over here okay so now jenkins is going to perform a copy ah on to this master node so you need to copy this stage so i'll explain the command over here so this is the ssh put for copying and i'm doing the remote copy on the kubernetes master so that's why i specified remote the file name and i'm putting it into the current working directory okay so copy this stage and go back to your pipeline go back to configure go to pipeline and remember this stage is like a sub stage to this one okay so always remember this is uh we are performing using our ssh pipeline plugin so now whatever we are doing we are doing as a sub stage for this so i'll paste it over here and yeah so first of all it is going to perform an ssh login into our this server and after that it is going to put this file into the current working directory and as you can see here we don't have any file right now okay click apply and then save and then just do a build and just wait for a minute okay so our workflow or the pipeline workflow has been completed and we need to verify whether we got this yml into our kubernetes master server or not so i'll come here and i'll run the command ls so as you can see now we have copied this file into our server i can do the list minus lrt also so this is the file okay all right so now we are done with this stage also let's go back to our guide and see what are the stages we are left with okay so now after copying it there is one more sub stage which we need to perform and that is we need to apply this configuration and that configuration can be applied via cuttle apply command okay and since we are using that ssh pipeline plugin so we need to perform this using this ssh command syntax so this will do ssh command i mean it is going to run this command inside our kubernetes master node on and yeah that should be it so syntax is pretty simple it is going to perform ssh command on a remote server and that remote server is this one and the command is this one okay so i will copy this stage go back to jenkins and i'll go to configure go to pipeline and then again remember this is a substate to this ssh sshk8 into k8 server so i will go here and paste it over here okay apply and save okay so as you can see we have gradually increase our stage one two three four five six seven so now we are with the seven stages for our pipeline and then we are going to perform a build so again wait for a minute and that should be ready i guess all right so as you can see i think we have deployed and created the service of our springboot docker image or we have deployed our docker image of a springboot application actually so now what we need to do is we need to verify the deployment okay so i'll come back to my kubernetes master node and what we need to do is group ctl get deployments so here you can see the name of the deployment that is j hook spring boot and that is ready secondly we need to check the service get service so here uh this is my application that is running on a note port and with the port 3244 okay and if you remember in our vagrant file uh i have used the ip of my master node as 100.0.0.2 this is the ip okay so now i need to access this uh springboard application rest endpoint so what i need to do is this and then i need to copy this port name number okay and then followed by hello okay so as you can see now we can pretty much access our spring boot application which is deployed by jenkins and running inside our kubernetes cluster okay so i think we are done with our jenkins pipeline setup and automating our kubernetes deployment using jenkins and if you go back to our guide so this was our last stage which we did and if you look on this script so it is it's not a next stage but it is a complete script which we pretty much created here inside our champions okay so i copied and pasted over here so that it is available for you in case if you forget anything or if you want to take a complete glance of how it looks like okay so yeah i think we are pretty much done and i hope you liked today's session and if you have any kind of a question then please put down into the comment section and i'm still preparing some more similar videos and similar sessions in upcoming days so go back and check my channel uh where i have keep on posting on devops and kubernetes so where i have previously posted a lot of similar content and it will be really nice if you could subscribe and put give me some feedback that really helps me okay so see you in the next lab session and yeah please feel free to put down or come back with the errors if you have or if you face any issue during this whole setup ok see you bye bye
Info
Channel: Rahul Wagh
Views: 15,604
Rating: 4.9658117 out of 5
Keywords: kubernetes, jenkins, ci/cd, continuous pipeline
Id: TPMUxsRI1OA
Channel Id: undefined
Length: 57min 20sec (3440 seconds)
Published: Mon Nov 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.