Transcript for:
Final Session on Argo Events and CI/CD

[Music] hello welcome to the Argo course my name is Muhammad and I'm very very happy to be here uh unfortunately this is the last Topic in the last session of this course and um so um so far we became familiar with some different Technologies of orgo uh such as Argo City roll outs and work fls and in the previous session we implemented a cicd pipeline using this stack we built a Ducker image we pushed the Ducker image into a NEX registry and we applied all those changes into a kubernetes cluster to have new version of the application so it was very very interesting uh but this project has a WI point until now uh let's imagine that whenever I modify the source code of my application after that I need to run and I need to submit the workflow manually it means that whenever I modify the source code of my application I need to build a ler image I need to push a like image and so on so I have to type Argos me for example Argo name space or argle events you can also Argo or argle events name spaces it doesn't matter and the name of the workflow for example workflow. here each time you need to submit your workflow manually so this is not desirable the best practice is that whenever I modify the source Cod application and whenever I need to run this workflow uh I need a tool to trigger this workflow automatically without any uh manual operations because of that I decided to add argue events to this scenario to this cicd pipeline to solve this problem but what is Argo events Argo events provides a way to trigger workflows based on events that we have within a kubernetes cluster or external twe it events can be anything from changes in a g repository updates in a database or custom events defined by users so I want to use Argo events to trigger our workflow automatically based on uh some different types of events so I go to the browser and I type Argo events this is the official documentation of argu events and it says that argu events is an even driven workflow tomation framework for kubernetes which helps you trigger K objects argu workplace and so on if I scroll down these are all the different types of objects that argue events can trigger them it can trigger argue workflows can trigger K its objects for example uh pods deployments Secrets config maps and so on it can also trigger cofco messages slack notifications Argo roll outs and so on in this scenario I'm going to use Argo IM to trigger our ARG workface very good uh Argo events is available in my kubernetes cluster because uh I installed this tool already but if argu events is not available in your cluster follow the instructions here first of all let's click on operator manual uh first of all you need to install Argo events name space and apply these resources inside this name space and then in uh step three deploy the even boss and use this command very good you can also check getting started page uh if Argo workflows is not available in your kubernetes cluster you need to install it first and then install AR gos because of that you need to create a namespace named named Argo and apply uh the resources of Argo inside this name space and then install Argo events uh and finally apply these U manifests in in inside Argo EV name space uh you will create some different rolls and roll bindings inside Argo name space first of all I want to I want to show you something I Ty CTL get service account DN rgo evens when you install Argo events in your kubernetes cluster it will create a service account named operate worklab a we are going to run all the workflows using the permissions of this service account because of that we are going to Grant some permissions to this service account to run the workflows and so on so you need to apply these roles and R bindings inside our go events name space this is the last step okay uh if you remember in the previous session uh we used Nexus repository to store our Docker images so first of all let's sign in admin and password and if you remember we created a repository in the previous session named arodes demo to store our Docker images here and we have enginex and it has three possible tags Alpine and two other different tags these are the tags are related to ARG workflows these two different Texs and we built and pushed those Docker images using AR workflows and this are workflows U IDs very good and this is the environment of our private gitlab in this scenario I'm going to use gitlab instead of GitHub that because uh I want to show you that we can use different sources and there is no difference between them and also we have two different repositories here the first repository is argu Das config so if I click on it you will see all the configurations of this scenario related to Argus Tech the configuration of Argo City Argo events and Argo workflows and also Argo rollups very good and the second repository is my Dash app the Doer file and the source code of our application all of them are inside this repository let's click on it and you will see thater file here and also the source code index of HTML we are using enginex uh as a very simple application for this scenario and I'm going to use index. HTML to replace the content of our uh web page so whenever I modify the content of this repository whenever I push a new commit whenever I have a new activity in this configur in this uh repository Argo events will detect those new changes and will run and submit our workflow for example if I modify the source code of our application for example index. HTML Argo events will detect that change and will will run our workflow automatically very good let's go to the note I'm going to explain about uh article events components article events components the first component is Event Source the second one is fenor and the last one is event BST first of all let's start with Event Source uh Oro events supports various event sources uh allowing users to Define how and when events are generated for example we have git La Event Source GitHub Event Source web hook Event Source and so on uh even sources often involve integration with external systems or services for example a gitlab Event Source would integrate with a gitlab repository to capture events like code pushes pull requests or issues in the fact we use even sources to connect to connect our Argo events to our repository in this scenario I'm going to use gitlab repository because of that the type of even Source here is gitlab gitlab even Source we use gitlab Event Source to connect Argo events to our gitlab repository for example my Dash app repository so if I install if I apply this resource it means that Argo events will connect to our gitlab repository such as my- app repository so whenever I modify the content of this repository Argo events will detect those changes okay so even source is responsible to connect Argo events to a specific gitlab repository in this scenario I'm going to use my- app repository so whenever I push a change whenever I push a commit inside this Repository Argo Evas will detect those changes and will run the workflow automatically okay the second component is sensor sensors are components that listens for events from event sources and Trigger workflows based on those events sensors are responsible for mapping incoming events to specific workflow triggers so Event Source will connect argu events to geub repository okay after that I make a change inside this repository in this situation sensor component will responsible to trigger our workflow okay the responsible of of even source is connecting these two objects and the responsibility of sensor is trigger the workflow okay the last component is even boss the even boss acts as the transport layer of Argo events by connecting uh the event sources and sensors okay these are all the components these are the important components of our gens okay let's check the configurations of this scenario to see how them work first of all let's go to the private kab environment and I want to clone these two different repositories first of all clone argu dis config repository uh I create a directory here named arod Das demo for example Oro Das demo and I want to clone these repositories here get clone argu Das config and let's clone another repository to my- app repository okay I clone this repository to get clone my Das app repository very good let's go to V code and I type I click on open folder and I type Argo demo and open and very good these are the Repository is of this scenario Argo Dash config and my Dash first of all let's go to Argo Das config directory and let's go to Argo events okay uh we have two important files here even sensor and even Source first of all let's start with even Source this is so important please pay attention that if we apply even Source if we apply even Source in our kubernetes cluster it will create three different objects for us the first object that Event Source will create is a kubernetes pod related to Event Source the second object is the kubernetes uh service and the last one is a gitlab b these are the objects that even Source will create when I apply our even Source but what is gitlab webook first of all let's go to my- appos itory I click on settings and web hooks I click on add new web hook okay uh web hooks are custom HTTP callbacks that you define they're usually triggered uh by an event such as pushing code to repository or posting comment on an issue when the event I curious The Source app makes an HTTP request to the URL configured for the web hook for example if you have experience working with uh Jenkins you should know that you can provide the URL of your Jenkins job here for example and whenever you make a change in your repository this web hook will uh trigger your Jenkin job for example and our article events and the Event Source has a URL our even Source has a URL as I said earlier even Source will create a kubernetes series and its type is cluster IP okay its type is cluster IP and as you know cluster IP service is not reachable from outside of the kubernetes cluster one of the solutions to make our service reachable from outside of the kubernetes cluster is using Ingress so in this scenario I'm going to create an Ingress to access to our Event Source SP SPC so this it this will be the URL of our Ingress for the even Source service okay very good let's go to even source. the first object that we have here is a kubernetes secret as you know even Source will create a web hook for my Dash app repository so it needs some permissions to create this web hook because of that we need access tokens for even source so let's add a token and we can create access tokens per project I click on add new token and its name will be like this y- app Das token it has no expiration date and select a role for example maintainer select Scopes and API is in off and create project access token this is the token of my- app repository so I type Echo DN this access token and pipe it to base 64 and this is the base 64 encoded value of our exess token and I will replace it so even Source even Source will use this token we'll use this access token to connect to my- app repository to create a web hook okay the second uh object is even source as you can see it kind is even Source its name is CI and even Source I want even source to be applied in ARG go- events name space as I said earlier one of the objects that even Source will create is a kubernetes service so this is the information about the service port and Target Port but what about the name of the series it's so important what about the name of the service that our even Source will create the name of the service will be like this the first part of its name will be even Source name name Event Source name Dash Event Source dash s wec the name of the even Source in this example is CI so its name will be like this ci- even source- SBC this will be the name of the service that even Source will create so when you want to create an engress for your backend service you can use this name okay so it has three parts the first part is even Source name the second part is even source and the last part is is as we see okay as I said earlier I I'm using gitlab EV source and its name is argu Das demo and uh this is the project ID of my- app gitlab repository as I said earlier even source is responsible to connect ARG good events to a specific repository and I'm going to integrate argue events with my- app Repository and the project ID of my- app repository is 35 so if I click on my- app repository you can see that the project ID of my- app repo is 35 okay even s will create a web hook as I said previously its end point will be/ push its Port is this this and the URL is HTTP col ar. events you can create this URL based on your needs it doesn't matter this is so important that this URL must be reachable from inside your gitlab server okay and events is push events whenever you make a push event in your gitlab repository Argo events will detect those changes and it will create that access token that we created create that web Hood gitlab D access this is the secret here gitlab D access it will use this access token to create that web hook enable SSL verification for the web Hook is false and this is the URL of our gitlab or of our our private gitlab for example the URL of my private gitlab is gitlab that ISC change it based on your private gitlab and delete Hook onfinish when I delete this EV stor that web hook will be deleted to from inside our gitlab okay and also uh as I said previously even Source will create a service and its type is cluster IP it means that it's not reachable from outside of the kubernetes cluster because of that we need an Ingress to access to this service from outside of the kubernetes cluster so this uh the third object that I'm going to use in this file is ingress I'm going to create an Ingress and its back end is the cluster IP series C- even source- SBC this is the prefix that I talked about it CI even source- SBC this is the name of the even Source Dash even Source Das just we see and its Port is this and the host is ARG do events uh or good. events points to my Local Host this is my kubernetes cluster okay so when I type ping Argo do events it will return the Local Host because argue. events is available in my ITC hosts you can add your argue. events in your TC host and it will return your local host argu that events as a URL must be reachable from inside of our gitlab server so I type pink gitlab Doc it's IP address is this so let's F to itl server I type ITC host and as you can see AR good that events is available in the it hosts of my gitlab server so when I type pink Argo do events it return ears uh this message it means that argue. events is reachable from inside of my gitlab server so this URL must be reachable from inside your gitlab server this is so important okay it was about even Source the next file is event Dash sensor as I said earlier we are going to run all the workflows with the permissions of operate workflows a service account because of because of that it needs some permissions to run the workflows so you need to provide uh some different roles and R bindings to make this work okay so you can use these lines here the name of the sensor is CI and I want to apply this sensor inside arod Das EV name space and I'm going to run the workflows with the permissions of operate workflows as service account and also we have a block here called dependencies its name is not important you can change it if you want it doesn't matter but it has other two different uh things that are so important the first one is even Source name in the fact I'm going to connect this even sensor to even Source I'm going to connect these two different components even source and even sensor so this is the name of the even Source if I go to even source. yam you can see that its name is CI so even Source name is CI but what about event name each Event Source can have multiple events but in this scenario and in this example we have a single event named Argo Das demo this is the type of even source and this is the name of the event Argo Das demo so the name of the event or even name is Argo demo in the fact we use dependencies block to connect Sor to our even source and triggers block as I said earlier Sor is responsible to trigger our uh object it can can be ARG workflows um it can be a part deployment secret the config map or any other things in this example Sor is responsible to submit our argu workflow and this is the workflow that I'm going to use we talked about this workflow in the previous session this workflow is responsible to build my Docker image first as you can see uh its first task is clone repo test clone Das repo it will clone these two repositories my- app repository and Argo dasc config repository it will clone this two repositories first as its first test and then uh and then it will yeah it will build the docker image and push the docker image into our Nexus registry if you are not familiar with this workflow you can watch the previous uh video I talked about uh this workflow in the previous session but for now you should know that the first task of the workflow is clone repo it needs to uh clone our to repositories my app and AR goodes config then it will build our Docker image and then it will push the docker image into Nexus registry and also the last task of this workflow is update Das manifest it need it needs to access to our room R outs manifest and replace its image with the new version of our application for example uh the image fi of our roll outs manifest points to the previous version Argo Argo workflows will modify its image and replace it with the new version of the application so these are the test that uh workflow will need to done we need to do and we're good so sensor is responsible to trigger our workflow and also I need to provide the user name and access token for my two different repositories because uh for my Das app repository it needs to create a web Hut and for my Argo Das config repository it will need to update the roll outs manifest so I need to provide username and token for these two different repositories uh we created an access token for my- app repository this is the access token for my- app repository so I change it with this very good and let's go to create an access token for uh Argo Das config repository I click on Argo Das config and I I click on access tokens add new token ar-c config Das token very good I copy the content and paste it here very very good so uh this is the IP address of my nex's registry and everything is good here okay the even sensor and the even Source very good okay let's go to Arash City and we have um our arus city application here okay it will apply our application inside Argo Das demo name space and but what about AR GES roll outs we have uh an Ingress for the roll outs and our application will be accessible and will be reachable using this URL are good at demo and the roll outs manifest I'm using Canary strategy for our scenario first of all it will uh switch to the new version of the application using 30% of the traffic traffic so 10% of the traffic is routed to the new version of the application and then we have a pause with no duration set it means that I need to unpa the roll outs manually and after that 40% 60% and 80% all the traffic will be routed to the new version of the application and this is the image of my roll outs manifest let's check that this image is available in my Nexus registry or not I click on enginex and tags and uh yes this image is available in my NEX registry and everything is good so okay very very good I want to show you something first of all if you are running if you are using Docker as your container run time you need to add your NEX registry to your Etc Docker demon Json so if I type ATC doer demon Json you will see my insecure registry inside this Json file very good and if you are using container D you have to add your insecure registry to your config dotom I'm using kind for my kubernetes cluster so if I go to kind control plane direct if I go to kind control plane container you will see that I'm using container D inside my kubernetes cluster it ISC container D cig. toop so if you are using container d as your container runtime you need to add your private register inside this file and you need to add these four lines to the end of your file to point to the new to point to your insecure private registry here bre in this scenario I'm going to use workflows artifacts if you are going to use workflows artifacts you need to set up an artifact repository such as Min so if I type Cube CTL get config m-n arle events one of these config Maps is artifact Dash Repository so Argo workflows will use this config map to connect to my uh artifact repository Mino to store my artifacts so if I go to sensor AR and even sensor you will see that the artifact repository ref is the config map artifact D repository it means that ARG workl will use this config map to connect to minio to sore the workflows artifacts very good let's start with this scenario I go to argu das demo and I go to Argo Das config and Argo CD and I apply Cube CTL apply DF Aro app. y-n City you need to apply your arus city application inside Argus city name space so this application has been created in side Argus City application so when I go to Argus City dashboard here this application has been deployed in my kubernetes cluster as I said earlier you can access to your application using this URL ARG go. demo so I type http aru do demo welcome to my website version 2.2.0 this is my application so when I type CU FTL get pod dnrg go- demo these are the replicas of my application very good uh if you want to access to your argor rollouts dashboard you can type CU CTL orgo rolls dashboard I copy the link and paste it here this is a dashboard of my orgo roll outs and we are in revision one very good as I said earlier when I go to Aro events Nam space and when I apply even the source it will create three different but for now when I type K City I'll get h-n argu do ar- events uh these are uh the parts that are available in argu events name space so if I type qctl get testc these are the services and when I go to my- app Repository you will see that there is no web hooks enabled here right now so let's go to apply my even Source Cube C apply Dash Event Source no I need to okay three different objects created a kubernetes secret even source and in so if I type Cube C get p- NR gance you can see that one pod is creating the kubernetes Pod is creating so as I said earlier a kubernetes pod and it's a status is running now let's go to SBC yes ci- even source that SVC SVC has been created and its type is cluster IP this is the second object that even Source created the last object was gitlab web so when I refresh this page we will see a gitlab web hook a refresh the page and yes a web hook has been created using even Source let's click on edit and as you can see here it URL is this or ev/ push and push branches is on wild card I click on all branch es and okay save changes so this URL has been created by even Source very very good so three different objects created using even Source a kubernetes pod a kubernetes service and a gitlab Fook and we can access to this service using the Ingress that we created so if I type your city I'll get in dasn Argo Das events you can access to your backend service using this Ingress very good so at this moment whenever I make a change inside my Dash app repository a workflow will be created here and we will see that workflow here okay Let's test it as you can see we are in version 2.0 I want to change it to 2.1 okay so let's go to my Dash app repository first I click on index. HTML and I click on edit and edit single file and I change welcome to my website version 2.0 to version point to version 2.1 okay let's commit changes okay uh as you can see there is no workface running because one another file needs to apply the another file is even sensor so I Ty to T apply DF event sensor DN article events bre it so let's go to index. HTML again and uh change the file and I go to I want to change version 2.1 to persion to version uh 2 point for example two let's commit changes very good and as you can see one workf is running I delete delete the previous workflow and this is the new workflow that is running its first task is clone report task clone these two different repositories my- app and Argo D config repository its second task is building the docker image and pushing the docker image into Nexus registry okay I want to pause the video uh because this process takes a few minutes and uh I will come back soon okay Argo workflows built the docker image and pushed the docker image into Nexus registry and very good and the last task is update manifest task and the update manifest related to argu roll outs and very good image. tag has been changed to something like this Argo workflows uh updated the roll outs manifest to point to the new version of the application first of all let's go to Nexus registry I refresh this page first and you will see a new tag here yes this is the new tag that Argo workflows built and pushed here okay and also if I go to my argu dasc config repository I click on our config and as you can see here image. tag has been changed to something like this this is uh the activity that argu workface had and if I click on argu roll outs and if I click on engine roll outs uh you will see that the roll outs manifest has been Chang to something like this using Argo workflows very very good Argo City will refresh uh the new activity after 3 minutes you need to wait for 3 minutes or refresh this page manually very good so the new replica set has been created when I go to Argo demo and if I refresh this page multiple times you will see that 20% of the traffic is roted to the new version 2.2 let's refresh it multiple times yeah welcome to my website version [Music] 2.2 and if I refresh this page multiple times you will see that 20% of traffic is routed to the new version and one replica is en revision two if you want to switch to the new version of the application you need to unpause the roll outs because in a step two we have pause with no duration so I type KL Argo rolous promote engine Das rolous dasn Oro them and the rollos has been promoted and as you can see we have two different replicas in revision one we need to wait uh until the end and after that we will uh be in the new version of the application okay so if I refresh this page multiple times we see 2.0 as well as 2.2 and waiting for the final result of this promotion and all the traffic will be routed to the new version of the application after 1 minute I'm waiting for 1 minute okay we have five replicas and revision two right now and all the traffic is routed to the new version so we won't see 2.0 if I refresh this page multiple times you can see that all traffic is red two welcome to my website version 2.2 for another example let's change it to 3.0 so I go to gitlab and go to my- app repository and index. HTML edit and I'm going to change welcome to my website version 2.2 to version 3 Z okay I commit this change and I'm going to wait for the new workflow here yes the workflow is running right now because I made a change in my Dash app repository so let's wait for the final result of this workflow because of that I pause the video Until the final result of this workflow okay workflows uh built the docker image and pushed the docker image and I'm waiting for the final res result of the last task update manifest task okay done image the tag has been changed to something like this and very good and also if I go to Nexus registry and if I refresh this page one another time if I go to enginex tags we will see another uh tag here and let's go to argue City wait for 3 minutes or refresh the page refresh your arus city application very cute so if I refresh this page 20% of traffic is roted to the new version 3.0 yeah 3. Z and we are in revision three and we have one replicas in revision three and in step two we have unpa with we have pause with uh no pause duration so I promoted the roll outs manually and we need to wait for the final result and after that all the traffic will be roted to the new version of the application but right now we have three replicas in revision three so if I refresh this page multiple times 60% person of traffic is routed to the new version of the application three replicas and right now four replicas and after 1 minute all the traffic and five replicas all the traffic will be routed to the new version of the application okay uh it was about argue events so using argue events you don't need to submit your workflow manually each time you modify the source code of your application and it can help you a lot to trigger your objects this object can be uh ARG workflow which can be a pod can be a deployment can be a secret config map or slack notification argor LS or any other things okay uh we implemented a very interesting cicd pipeline using Argo Tech including Argo City Argo rollouts Argo workflows and Argo events and it was very interesting uh I hope this course has been helpful for you and I apologize if the quality of the course was low and you can also contribute on our GitHub repository of this course if you want uh this is the repository of this course Argus city- tutorial and you can also add your own cicd pipelines add your own workflows add your own argd applications projects and any any other things if you want and also I have another uh personal repository named cicd with Argo stch this is my personal repository you can uh check its R me and also you can follow the instructions of this repository to run your cic pipelines as I did in this session very good uh please let me know your feedback and I wish you all the best and goodbye