Day-19 | Jenkins ZERO to HERO | 3 Projects Live |Docker Agent |Interview Questions | #k8s #gitops

00:59:25
https://www.youtube.com/watch?v=zZfhAXfBvVA

概要

TLDRDans cette vidéo, Abhishek guide les spectateurs à travers l'installation de Jenkins, un outil d'intégration et de livraison continues, sur une instance EC2 d'AWS. Il démontre comment configurer Jenkins pour s'exposer à l'extérieur, utiliser Docker comme agent pour exécuter les pipelines Jenkins, et déployer des applications sur un cluster Kubernetes. L'utilisation de Docker comme agent permet de profiter de la légèreté des conteneurs qui facilitent le test et le déploiement des applications sans les conflits de dépendances typiques des machines virtuelles traditionnelles. En utilisant Docker, chaque étape du développement utilise des conteneurs dédiés, assurant une isolation propre et réduisant les coûts de maintenance. Abhishek fournit également des astuces pour écrire des pipelines Jenkins et discute des bonnes pratiques pour gérer et optimiser les instances Jenkins et ses agents dans un environnement professionnel.

収穫

  • 👨‍💻 Jenkins permet d'automatiser les processus DevOps.
  • 🐋 Utiliser Docker comme agent maximise l'efficacité.
  • ☁️ Déployer Jenkins sur une instance AWS EC2.
  • 🔗 Argo CD simplifie le déploiement sur Kubernetes.
  • 🛠️ Docker garantit une isolation des processus.
  • 📜 Un pipeline Jenkins gère plusieurs étapes de développement.
  • 🔄 Redémarrer Jenkins après l'installation de plugins.
  • 🔍 Jenkins utilise des repo SCM pour le code source.
  • 🗂️ Les conteneurs facilitent la gestion des dépendances.
  • 🛡️ Assurer que Jenkins est exposé correctement pour l'accès externe.

タイムライン

  • 00:00:00 - 00:05:00

    Abhishek inaugure le 19ème jour de son cours complet sur le Devops et se concentre sur l'implémentation pratique de Jenkins, en commençant par son installation, l'exposition aux accès externes, la configuration de Docker comme agent, et enfin le déploiement d'applications sur un cluster Kubernetes. Il propose des ressources sur un dépôt GitHub pour suivre ses instructions.

  • 00:05:00 - 00:10:00

    Abhishek crée une instance EC2 sur AWS, installe Java et Jenkins tout en s'assurant que les paquets nécessaires sont mis à jour. Il souligne l'importance de configurer les règles de sécurité AWS pour que Jenkins soit accessible via le port 8080.

  • 00:10:00 - 00:15:00

    Il explique comment accéder à Jenkins une fois installé et comment installer les plugins recommandés. Il insiste sur la nécessité de passer au pipeline Jenkins pour une meilleure gestion des versions et de préférer les pipelines à la configuration manuelle des projets freestyle.

  • 00:15:00 - 00:20:00

    Abhishek explique la transition vers l'usage de Docker comme agent Jenkins pour éviter les problèmes de dépendance liés à l'utilisation de machines virtuelles multiples et démontre que ce nouveau modèle permet de créer et détruire des conteneurs selon les besoins, réduisant ainsi les coûts et la maintenance.

  • 00:20:00 - 00:25:00

    Il montre comment installer Docker sur l'instance Jenkins, accorder les droits nécessaires au démon Docker pour Jenkins et Ubuntu, et l'importance de redémarrer Jenkins pour que les changements soient pris en compte.

  • 00:25:00 - 00:30:00

    L'utilisation du plugin Docker Pipeline dans Jenkins est mise en avant pour faciliter l'exécution des pipelines sur les agents Docker. Abhishek passe en revue les différentes manières de créer un pipeline dans Jenkins, en insistant sur la flexibilité et la réutilisabilité des pipelines codés par rapport aux projets freestyle.

  • 00:30:00 - 00:35:00

    Abhishek construit un pipeline Jenkins simple afin de tester la configuration de Docker comme agent et souligne la simplicité et l'efficacité du modèle. Il montre qu'une fois le travail terminé, les conteneurs sont supprimés, prouvant la fluidité de l'intégration de Docker dans Jenkins.

  • 00:35:00 - 00:40:00

    Il passe ensuite à des pipelines plus complexes, montrant comment gérer des applications à trois niveaux avec des configurations de dockerisation distinctes pour le front-end, le back-end et la base de données, et comment exécuter ces applications sur différents conteneurs Docker spécialisés.

  • 00:40:00 - 00:45:00

    Abhishek introduit un projet plus complexe de CI/CD qui implique Jenkins et Argo CD pour le déploiement continu sur Kubernetes. Il explique comment Jenkins peut être configuré pour surveiller les changements de code et déployer automatiquement ces mises à jour via Argo CD sur un cluster Kubernetes.

  • 00:45:00 - 00:50:00

    Il résume les étapes nécessaires pour installer Argo CD et configurer une application Python simple, en montrant comment utiliser Jenkins pour compiler, tester et mettre à jour les déploiements Kubernetes de manière fluide. Abhishek offre aussi des références pour une compréhension plus approfondie grâce à des vidéos complémentaires.

  • 00:50:00 - 00:59:25

    Enfin, Abhishek termine par des questions courantes en entretien sur Jenkins et la CI/CD, offrant des stratégies pour expliquer les processus CI/CD en entreprise et aborder les défis techniques, et renvoie à d'autres ressources pour approfondir le sujet pour les interviews.

もっと見る

マインドマップ

ビデオQ&A

  • Que couvre cette vidéo sur Jenkins ?

    Cette vidéo couvre l'installation de Jenkins, son exposition, la configuration de Docker comme agent et le déploiement d'applications sur Kubernetes.

  • Pourquoi utiliser Docker comme agent pour Jenkins ?

    Docker est utilisé comme agent pour profiter des conteneurs légers, évitant ainsi les conflits de dépendance et facilitant l'évolutivité.

  • Comment Jenkins interagit-il avec Docker ?

    Jenkins utilise des conteneurs Docker pour exécuter les pipelines, en créant et supprimant les conteneurs selon les besoins.

  • Quelles sont les étapes principales d’un pipeline Jenkins ?

    Les étapes incluent généralement le checkout de code, la construction, les tests et le déploiement.

  • Quelle est la différence entre un projet freestyle et un pipeline dans Jenkins ?

    Un projet freestyle utilise des interfaces graphiques pour la configuration, tandis qu'un pipeline est une approche de code, permettant une gestion versionnée.

  • Comment Jenkins gère-t-il les projets multi-agent ?

    Jenkins utilise des configurations de conteneurs Docker multiples pour gérer les différentes étapes d'un projet multi-agent.

  • Pourquoi Argo CD est-il recommandé pour le déploiement continue avec Kubernetes ?

    Argo CD propose un déploiement continue déclaratif, surveillant les changements et s'assurant que l'état du cluster correspond toujours au référentiel Git.

  • Quelle est l’importance du redémarrage de Jenkins après l’installation de plugins ?

    Redémarrer Jenkins après l'installation de plugins assure que les changements sont bien pris en compte.

  • Qu'est-ce qu'un CI/CD ?

    CI/CD signifie Intégration Continue/Déploiement Continu, des pratiques clés dans le développement logiciel.

  • Comment Jenkins s'intègre-t-il avec des outils de contrôle de version ?

    Jenkins s'intègre via des plugins pour automatiser le processus de construction et de déploiement à partir de dépôts de code source.

ビデオをもっと見る

AIを活用したYouTubeの無料動画要約に即アクセス!
字幕
en
オートスクロール:
  • 00:00:02
    hello everyone my name is Abhishek and
  • 00:00:04
    welcome back to my channel so today we
  • 00:00:06
    are at day 19 of our complete devops
  • 00:00:08
    course and in this video we will see
  • 00:00:10
    practical implementation of Jenkins so
  • 00:00:13
    that's the reason why I call it Jenkins
  • 00:00:15
    0 to 0 right so if you look at the about
  • 00:00:17
    section I explained what are we going to
  • 00:00:19
    do today uh that is uh install Jenkins
  • 00:00:22
    and then we will see how to expose this
  • 00:00:24
    Jenkins to outside world after that
  • 00:00:27
    we'll see how to configure Docker as
  • 00:00:28
    agent will not create multiple ec2
  • 00:00:31
    instances and configure them as worker
  • 00:00:33
    nodes to this Jenkins Master but we will
  • 00:00:36
    see how to use Docker so that you know
  • 00:00:38
    containers as you know they are very
  • 00:00:40
    lightweight and they have lot of
  • 00:00:42
    advantages so I'll try to explain why
  • 00:00:44
    you should also follow this approach so
  • 00:00:46
    stay with me it might be uh a little bit
  • 00:00:49
    lengthy video but try to follow the
  • 00:00:52
    video till end so that you will get a
  • 00:00:54
    good benefit out of the video
  • 00:00:55
    and finally we'll also see how to deploy
  • 00:00:58
    this applications onto a kubernetes
  • 00:01:00
    cluster so if you feel somewhere that
  • 00:01:02
    you are not able to follow the video or
  • 00:01:04
    I'm going little speed don't worry I've
  • 00:01:06
    documented the entire things in the
  • 00:01:07
    readme section of this GitHub repository
  • 00:01:09
    uh right from installation to everything
  • 00:01:12
    that we are going to today so
  • 00:01:14
    you can Fork this repository or you can
  • 00:01:16
    start this repository so that you can
  • 00:01:18
    follow the video accordingly at your
  • 00:01:20
    suitable time
  • 00:01:22
    perfect now
  • 00:01:24
    firstly what we will do is we'll start
  • 00:01:26
    with an ec2 instance if you see here
  • 00:01:29
    this is my AWS console and I have
  • 00:01:32
    already launched a ec2 instance so there
  • 00:01:35
    is no special requirement but if you
  • 00:01:36
    want to follow the document as is so I
  • 00:01:39
    have some commands that I've provided
  • 00:01:40
    for you how to install Java Jenkins and
  • 00:01:43
    all so if you want to follow the video
  • 00:01:44
    as is you can create an Ubuntu instance
  • 00:01:47
    so so that all the APT commands will be
  • 00:01:49
    applicable to your instance as well
  • 00:01:52
    so I just created a Jenkins instance and
  • 00:01:55
    what we will do is we'll try to start
  • 00:01:57
    with installing Jenkins on it right the
  • 00:02:00
    name is Jenkins but it's just an easy to
  • 00:02:02
    instance uh without any uh software
  • 00:02:04
    packages installed in it right so let me
  • 00:02:07
    take the terminal and firstly what we
  • 00:02:09
    need to do we need to copy the instance
  • 00:02:12
    public IP address so I'll copy the
  • 00:02:14
    instance public IP address and if you
  • 00:02:16
    see here I have my console let me
  • 00:02:18
    increase the font
  • 00:02:21
    right so first of all we'll try to SSH
  • 00:02:25
    to that ec2 instance
  • 00:02:29
    uh let me change the public IP address
  • 00:02:31
    so I am using my key value pair and
  • 00:02:35
    I have SSH to that ec2 instance right so
  • 00:02:39
    I am currently logged into the ec2
  • 00:02:41
    instance now the first thing that you
  • 00:02:43
    need to do is Jenkins is a Java based
  • 00:02:46
    application okay so for that to be
  • 00:02:48
    installed you need to have Java as a
  • 00:02:50
    prerequisite so that is also provided in
  • 00:02:52
    the document if you see the prerequisite
  • 00:02:54
    Java or jdk is a prerequisite so firstly
  • 00:02:57
    you need to run this set of commands
  • 00:02:59
    Okay firstly we are updating the APT
  • 00:03:02
    packages and then we are installing the
  • 00:03:05
    jdk so versions okay so if you want to
  • 00:03:09
    go with the document just use the
  • 00:03:11
    commands as is or if you have a
  • 00:03:12
    requirement of any specific version then
  • 00:03:14
    you can change them as well
  • 00:03:17
    but I would recommend you to follow the
  • 00:03:19
    versions as is because I try to keep it
  • 00:03:21
    as latest as possible
  • 00:03:25
    so this is this will just take a second
  • 00:03:27
    and after your uh app to get update is
  • 00:03:31
    done and you have installed the jdk you
  • 00:03:33
    can verify if your Java is installed or
  • 00:03:35
    not using this specific command once
  • 00:03:37
    that is done you can follow or you can
  • 00:03:39
    copy the exact same command to install
  • 00:03:41
    Jenkins as well
  • 00:03:42
    so I'll just copy the commands to
  • 00:03:45
    install Jenkins let's say you are on
  • 00:03:47
    Centos or you are on a different uh uh
  • 00:03:50
    distributions of Linux don't worry you
  • 00:03:52
    can get the commands from official
  • 00:03:54
    Jenkins documentation so all that you
  • 00:03:56
    need to do is just search for Jenkins
  • 00:03:58
    here and go to the official
  • 00:04:01
    documentation once you go there uh click
  • 00:04:03
    on the documentation option and then you
  • 00:04:05
    have installing Jenkins and to your
  • 00:04:07
    right side you have apps options like uh
  • 00:04:09
    Linux kubernetes where do you want to
  • 00:04:11
    install so click on Linux and then
  • 00:04:13
    choose your distribution let's say
  • 00:04:15
    you're on Centos so you have commands to
  • 00:04:17
    install
  • 00:04:18
    Jenkins on centralized but the only
  • 00:04:20
    prerequisite is you need to have Java
  • 00:04:23
    installed on it
  • 00:04:24
    okay so we are installing Jenkins uh
  • 00:04:28
    Java installation is done after that you
  • 00:04:30
    will have your Jenkins service started
  • 00:04:32
    okay
  • 00:04:35
    right so one thing uh is even when we
  • 00:04:38
    are talking about the uh AWS ec2
  • 00:04:41
    instances you need to understand that by
  • 00:04:43
    default your ec2 instances will not
  • 00:04:46
    accept traffic from external world that
  • 00:04:48
    is the inbound traffic rules are blocked
  • 00:04:51
    by default so if you want to access any
  • 00:04:53
    application like Jenkins is an
  • 00:04:55
    application which has its application
  • 00:04:57
    running on port 8080 if you want to see
  • 00:05:00
    that what is the command you can just
  • 00:05:01
    say PS hyphen EF and grab for the
  • 00:05:04
    process called Jenkins right if you do
  • 00:05:07
    that you can see clearly that okay so
  • 00:05:09
    Jenkins is running on this specific
  • 00:05:11
    instance and the port is 8080 right so
  • 00:05:14
    port 8080 is not accessible to external
  • 00:05:18
    World AWS is blocking that on this on
  • 00:05:21
    this specific IP address so what you
  • 00:05:23
    need to do is go to the security okay if
  • 00:05:25
    you see here this is security and click
  • 00:05:28
    on the existing Security Group so these
  • 00:05:30
    are the default security groups that are
  • 00:05:32
    as attached to your ec2 instance what
  • 00:05:34
    you'll do is edit the inbound rules
  • 00:05:36
    inbound rules is nothing but the traffic
  • 00:05:38
    that is coming inside or to your ec2
  • 00:05:41
    instance click on add a rule what you
  • 00:05:43
    can do is you can select custom TCP and
  • 00:05:46
    select a port range but in my case I
  • 00:05:48
    directly know the port that is 8080 and
  • 00:05:51
    this is very important this is the
  • 00:05:54
    source IP address let's say you only
  • 00:05:56
    want this ec2 instance to be accessed
  • 00:05:58
    from the laptop you can use my IP let me
  • 00:06:00
    put it as anywhere and you can also
  • 00:06:02
    instead of custom TCP you can allow all
  • 00:06:05
    the traffic right now I'm I'll delete
  • 00:06:07
    the instance after the usage so I can
  • 00:06:09
    allow all traffic and even I love
  • 00:06:12
    everybody The Source IP is 0 0 so that
  • 00:06:14
    anybody can access this Jenkins instance
  • 00:06:16
    okay so most of the people might already
  • 00:06:19
    know this process so if you feel that
  • 00:06:21
    you already know how to use this till
  • 00:06:23
    this point of time okay uh pretty cool
  • 00:06:26
    uh the topics that we are going to cover
  • 00:06:28
    after this might uh like it might be
  • 00:06:31
    something that you might not be aware
  • 00:06:33
    like using Dot occur as an agent or
  • 00:06:35
    deploying the applications onto
  • 00:06:37
    kubernetes so stay with me and uh try to
  • 00:06:40
    be focused on the entire video
  • 00:06:43
    perfect
  • 00:06:45
    so right now I allowed the easy to
  • 00:06:49
    specific Port range to be accessed from
  • 00:06:52
    external world if I go to the ec2
  • 00:06:54
    instance select the public IP address I
  • 00:06:57
    just copied it now let me see if Jenkins
  • 00:06:59
    instance is accessible or not okay so I
  • 00:07:03
    copied the IP address and the port is
  • 00:07:05
    8080 so let me even select that port and
  • 00:07:08
    click on enter once you do that yeah
  • 00:07:11
    right now you have Jenkins installed and
  • 00:07:13
    Jenkins is running on this ec2 instance
  • 00:07:16
    so what Jenkins is saying the initial
  • 00:07:18
    password can be copied from this
  • 00:07:20
    specific file so I'll just catch that
  • 00:07:23
    specific file and get the initial
  • 00:07:24
    password okay you need to use sudo
  • 00:07:27
    because this is a root file location
  • 00:07:31
    uh what is happening okay so let me do
  • 00:07:34
    this uh sudo cat followed by the
  • 00:07:37
    location of the file and this is my
  • 00:07:39
    initial password I copied the initial
  • 00:07:41
    password and pasted it here now I am
  • 00:07:43
    able to sign into Jenkins okay once you
  • 00:07:46
    do this uh you have two options one is
  • 00:07:49
    install suggested plugins and select
  • 00:07:51
    plugins to install go with the suggested
  • 00:07:53
    plugins because uh Jenkins has already
  • 00:07:55
    uh categorized the most useful plugins
  • 00:07:58
    uh it depends upon the analytics uh
  • 00:08:00
    which plugins are most used so Jenkins
  • 00:08:02
    has come up with a list and Jenkins said
  • 00:08:04
    that okay so these are the list of
  • 00:08:05
    plugins that many people are using and
  • 00:08:07
    even you it might be useful for you
  • 00:08:09
    and at any given point of time you can
  • 00:08:12
    go to Jenkins and install any plugins
  • 00:08:14
    that you want
  • 00:08:15
    while this is getting installed let me
  • 00:08:18
    tell you one more time all of these
  • 00:08:20
    things are available in the document
  • 00:08:21
    like if you see here this is how you
  • 00:08:23
    copy the password and then you click on
  • 00:08:25
    in uh sorry install suggested plugins
  • 00:08:27
    then what you need to do after that so
  • 00:08:30
    everything is present as part of the
  • 00:08:32
    GitHub repository so you can clone or
  • 00:08:34
    Fork this Repository
  • 00:08:36
    perfect let me go back and see what is
  • 00:08:38
    the status so the plugins are still
  • 00:08:40
    getting installed uh if you feel that I
  • 00:08:43
    don't want all of this plugins it's
  • 00:08:44
    wasting a lot of time for me you can
  • 00:08:46
    just go with install selected plugins as
  • 00:08:48
    well if you are going to use this
  • 00:08:49
    instance for a long time I would highly
  • 00:08:52
    recommend you to configure the username
  • 00:08:54
    and password you can choose a easy one
  • 00:08:56
    as well and
  • 00:08:58
    the reason for that is uh you know this
  • 00:09:01
    is your administrative password the one
  • 00:09:03
    that comes by default uh is like you
  • 00:09:05
    know it's like a test password or it's a
  • 00:09:07
    password that uh you can only use it
  • 00:09:12
    I mean it's a password that Jenkins
  • 00:09:14
    would recommend to change it in the
  • 00:09:15
    future uh so I'm sticking to my IP
  • 00:09:17
    address and port and click on Save and
  • 00:09:20
    finish
  • 00:09:21
    right so start using Jenkins that means
  • 00:09:23
    you are Jenkins installation part is
  • 00:09:26
    done so right now what we have done is
  • 00:09:28
    we have installed Jenkins now let me
  • 00:09:31
    take a moment and explain you how
  • 00:09:33
    Jenkins Works in real time I'm not going
  • 00:09:35
    to talk about the pipeline uh so because
  • 00:09:37
    we already discussed about the pipeline
  • 00:09:39
    what is the orchestration in Jenkins
  • 00:09:41
    what are the different stages uh that
  • 00:09:43
    you could uh integrate in Jenkins in the
  • 00:09:45
    previous class so I'm not going to talk
  • 00:09:47
    it but how Jenkins architecture works
  • 00:09:50
    that is if you see here usually to the
  • 00:09:53
    left side okay so to the left side of
  • 00:09:55
    the diagram I have a Jenkins Master
  • 00:09:56
    where the Jenkins is right now installed
  • 00:09:59
    so this ec2 instance that we are using
  • 00:10:02
    can be considered as Jenkins master and
  • 00:10:04
    what usually happens is in an
  • 00:10:06
    organization let's say we are working
  • 00:10:07
    for amazon.com so in amazon.com people
  • 00:10:11
    create ec2 instance on Jenkins master
  • 00:10:13
    and because there are multiple
  • 00:10:15
    developers multiple project teams and
  • 00:10:17
    multiple development teams so Jenkins
  • 00:10:20
    gets a lot of load to offload these
  • 00:10:23
    things so what Jenkins does is you
  • 00:10:25
    should always use Jenkins Master only
  • 00:10:27
    for the scheduling purpose okay because
  • 00:10:29
    all of the things cannot be run on a
  • 00:10:32
    single Jenkins Master right if
  • 00:10:33
    everything runs on a single Jenkins
  • 00:10:35
    Master then it will have conflicting
  • 00:10:37
    packages let's say one team requires a
  • 00:10:40
    Java version 7 and the other team
  • 00:10:41
    requires Java version right uh sorry
  • 00:10:43
    eight someone requires python to someone
  • 00:10:46
    requires Python 3 so it is technically
  • 00:10:48
    not possible to have everything to run
  • 00:10:50
    in one Jenkins Master not good for the
  • 00:10:52
    purpose of load and not good even for
  • 00:10:54
    the purpose of
  • 00:10:56
    like you know dependency conflicts so
  • 00:10:59
    what people do is they create a Jenkins
  • 00:11:01
    master and they create Jenkins worker
  • 00:11:03
    nodes like let's say this worker node
  • 00:11:05
    should be used by applications one to
  • 00:11:07
    ten this worker node should be used by
  • 00:11:10
    applications 10 to 20 or this worker
  • 00:11:12
    node should be only used by a specific
  • 00:11:13
    development team or this should be only
  • 00:11:16
    for Windows applications this should be
  • 00:11:18
    only for Linux applications so people
  • 00:11:20
    categorize that who is responsible for
  • 00:11:22
    these things devops engineers are
  • 00:11:24
    responsible for these things but
  • 00:11:26
    saying that this architecture was well
  • 00:11:29
    and good like two years ago or three
  • 00:11:31
    years ago but with the advancement of
  • 00:11:33
    micro services with the advancement of
  • 00:11:35
    the kubernetes micro service
  • 00:11:37
    architecture the problem is that you
  • 00:11:40
    have
  • 00:11:40
    different types of applications like you
  • 00:11:42
    know the scale of your micro Services
  • 00:11:44
    has gone leaps and bonds so with this
  • 00:11:47
    approach you might uh end up like let's
  • 00:11:49
    say this project team okay or the
  • 00:11:52
    windows applications uh Jenkins worker
  • 00:11:54
    node it is not at all getting uh any
  • 00:11:56
    requests or there is no change to the
  • 00:11:58
    applications that are made so always
  • 00:12:00
    this ec2 instance is sitting idle let's
  • 00:12:03
    say this is one ec2 instance and you
  • 00:12:05
    have 20 ec2 instances as worker nodes
  • 00:12:07
    okay so whenever Jenkins Master gets a
  • 00:12:10
    request for uh Windows what usually does
  • 00:12:13
    is because it says that okay Windows
  • 00:12:16
    should always go to Jenkins worker Note
  • 00:12:17
    3 for execution of pipelines it will
  • 00:12:19
    only send windows but
  • 00:12:22
    what we have noticed is that the
  • 00:12:24
    requirement for the windows is coming
  • 00:12:25
    very rare okay only very I mean very
  • 00:12:28
    rarely these applications related to
  • 00:12:30
    windows are being changed so the Jenkins
  • 00:12:32
    worker Note 3 is always sitting idle
  • 00:12:35
    that means you are wasting the resources
  • 00:12:37
    on your AWS instance now you can say
  • 00:12:40
    that okay I can always go back and turn
  • 00:12:42
    down this ec2 instance or you know stop
  • 00:12:44
    this ec2 instance only when it is
  • 00:12:46
    required but you never know when is it
  • 00:12:47
    required right or you can configure an
  • 00:12:49
    auto scaling group okay but even if
  • 00:12:52
    you're configuring Auto scaling group
  • 00:12:53
    then again you know you at least need to
  • 00:12:55
    have one worker node and
  • 00:12:57
    you know you don't know which
  • 00:12:58
    requirement is coming to you whether
  • 00:13:00
    it's a Windows application whether it's
  • 00:13:01
    a Linux application node.js application
  • 00:13:03
    you don't know so you have all of these
  • 00:13:06
    challenges with configuring worker nodes
  • 00:13:09
    which are easy to instances
  • 00:13:11
    so to solve this problem in today's
  • 00:13:13
    class what we are going to see is we are
  • 00:13:15
    going to see the latest approach that is
  • 00:13:17
    using Jenkins with Docker as agents that
  • 00:13:20
    means the Jenkins pipelines or the
  • 00:13:23
    Jenkins stages what we will do is we
  • 00:13:24
    will try to run this Jenkins Pipeline on
  • 00:13:27
    Docker containers so everybody knows
  • 00:13:29
    what is the advantage of Docker
  • 00:13:30
    containers right so if you are using
  • 00:13:32
    Docker containers they are very light in
  • 00:13:34
    weight against virtual machines so if
  • 00:13:36
    you are using a Docker container let's
  • 00:13:38
    say tomorrow somebody comes here and
  • 00:13:40
    says that oh okay I'm using node.js15
  • 00:13:43
    upgrade to node.js16 then you have to
  • 00:13:45
    log into the worker node change the
  • 00:13:47
    node.js to 16. then again uh there can
  • 00:13:50
    be conflicting packages like you know
  • 00:13:51
    one team in worker node might say that I
  • 00:13:54
    want to use node.js 15 and the other
  • 00:13:56
    team using worker node one they might
  • 00:13:58
    want to say that okay I want to use
  • 00:13:59
    node.js 16. so this problem can be
  • 00:14:01
    solved by containers because containers
  • 00:14:03
    can be anytime created destroyed they
  • 00:14:06
    can be upgraded you just have to modify
  • 00:14:08
    the docker file and then you can use any
  • 00:14:10
    container that you would want right so
  • 00:14:12
    and most of the default containers like
  • 00:14:15
    you know if you want a node.js container
  • 00:14:17
    you don't even have to write a Docker
  • 00:14:19
    file you can directly use that from
  • 00:14:20
    Docker Harbor somewhere so that's why
  • 00:14:23
    the containers usage for Docker I mean
  • 00:14:26
    only if your applications are light in
  • 00:14:28
    weight like let's say your application
  • 00:14:30
    is a database application then in some
  • 00:14:32
    cases this container approach might not
  • 00:14:34
    work but to have a good resume or to
  • 00:14:37
    have a good project in your resume
  • 00:14:38
    always try to implement this as well
  • 00:14:41
    okay or keep it keep this as your first
  • 00:14:44
    approach so that you can say that we
  • 00:14:46
    have used Docker as agent in our Jenkins
  • 00:14:49
    project setup and we found this as very
  • 00:14:52
    useful in terms of cost and also in
  • 00:14:54
    terms of efficiency and you know
  • 00:14:57
    spinning up and tearing down the docker
  • 00:14:59
    containers perfect now this is the
  • 00:15:01
    architecture that I wanted to explain
  • 00:15:03
    you and in today's class we will see the
  • 00:15:05
    approach to and I'll also explain you
  • 00:15:07
    how to configure this Docker containers
  • 00:15:10
    and how to use Docker as agent
  • 00:15:12
    it's going to be very simple don't worry
  • 00:15:14
    about it
  • 00:15:15
    perfect so now what we need to do is
  • 00:15:18
    that we have Jenkins installed and we
  • 00:15:20
    are also able to access Jenkins
  • 00:15:22
    to configure Docker first of all you
  • 00:15:24
    have to have Docker installed on the
  • 00:15:27
    same machine I mean right now in this
  • 00:15:29
    class I'm only going to use one ec2
  • 00:15:31
    instance so I am not going to create
  • 00:15:33
    multiple ec2 instances so what I'll do
  • 00:15:35
    is I'll use the same instance whereas
  • 00:15:37
    Jenkins Jenkins is installed and an
  • 00:15:39
    install Docker on this machine so for
  • 00:15:42
    installing Docker again you can follow
  • 00:15:44
    my document and you can directly copy
  • 00:15:46
    the steps that is firstly you uh apt
  • 00:15:49
    install Docker dot IO right so let me
  • 00:15:52
    copy the commands from here itself you
  • 00:15:55
    don't have to do sudo apt update one
  • 00:15:56
    more time if you have already done so
  • 00:15:58
    I'll just say sudo apt install Docker
  • 00:16:01
    dot IO
  • 00:16:03
    so what I'm doing I'm installing Docker
  • 00:16:06
    on the same machine you can also install
  • 00:16:08
    on a different machine but you have to
  • 00:16:09
    configure that machine as a slip
  • 00:16:12
    okay so once I do it uh what is the
  • 00:16:15
    thing uh I mean you also have to ensure
  • 00:16:18
    that the docker demo so if you know
  • 00:16:20
    about Docker Docker typically runs on a
  • 00:16:23
    demon process that's a single process or
  • 00:16:25
    single source of Truth for Docker and
  • 00:16:27
    this demon process by default is not
  • 00:16:30
    accessible to other other users so I've
  • 00:16:33
    installed Docker using root so only root
  • 00:16:35
    user has access to this demon so I have
  • 00:16:38
    to Grant access to this Docker D1 so to
  • 00:16:41
    do that what I'll do is uh Jenkins
  • 00:16:44
    basically comes with a user called
  • 00:16:45
    Jenkins user I'll Grant the access to
  • 00:16:48
    Jenkins user as well as the Ubuntu user
  • 00:16:51
    as well just in case we want to use
  • 00:16:52
    Ubuntu user so I have documented both of
  • 00:16:55
    them firstly I am switching to the root
  • 00:16:57
    user using sudo hyphen sudo hyphen and
  • 00:17:01
    then user mod is used to Grant access to
  • 00:17:04
    Jenkins like I'm just making it part of
  • 00:17:06
    the docker group so Docker installation
  • 00:17:09
    creates a group called Docker and
  • 00:17:11
    whoever wants access access to this
  • 00:17:13
    Docker demon or whoever wants to create
  • 00:17:15
    containers or whoever wants to access
  • 00:17:17
    the docker they should be part of the
  • 00:17:19
    docker group so I'm just making them
  • 00:17:21
    part of the docker group and I am
  • 00:17:23
    restarting the docker demon
  • 00:17:26
    so it it is done now if you see here I
  • 00:17:29
    can switch to Jenkins user uh what I'll
  • 00:17:32
    do is switch user
  • 00:17:35
    Jenkins so right now I'm in Jenkins user
  • 00:17:38
    Jenkins user is by default created when
  • 00:17:40
    you are installing Jenkins software if I
  • 00:17:43
    try to do what is a Docker hello welcome
  • 00:17:45
    and you can simply say Docker run hello
  • 00:17:48
    world this will ensure that your Docker
  • 00:17:51
    is installed and the user has access to
  • 00:17:53
    Docker like if you see here right now it
  • 00:17:55
    is saying that okay the demon does not
  • 00:17:58
    have access I mean Jenkins does not have
  • 00:18:00
    access to the demon let us see what is
  • 00:18:02
    happening let me just log out to this
  • 00:18:05
    user and let me again Grant the access
  • 00:18:07
    maybe I fumbled with the command let me
  • 00:18:10
    say user mod
  • 00:18:13
    minus aging Docker is a group and then
  • 00:18:16
    Jenkins is the user let me see if I
  • 00:18:19
    granted the required access or not
  • 00:18:23
    switch user hyphen Jenkins and uh let me
  • 00:18:27
    say
  • 00:18:30
    Docker run
  • 00:18:33
    hello world
  • 00:18:36
    yes so if you see here maybe the demon
  • 00:18:39
    was getting restarted because I used the
  • 00:18:41
    restart command as well maybe the demon
  • 00:18:43
    was getting restarted or maybe I clicked
  • 00:18:46
    on the wrong command one of these things
  • 00:18:47
    but never mind so now Jenkins user is
  • 00:18:50
    also able to create the containers or
  • 00:18:52
    run the containers that is what the
  • 00:18:54
    requirement was okay so if you look at
  • 00:18:56
    the document Grant Jenkins user and
  • 00:18:58
    Ubuntu user permissions to Docker demand
  • 00:19:01
    why did I grant to Ubuntu user as well
  • 00:19:03
    because some people might want to use
  • 00:19:04
    Jenkins with the Ubuntu user or you know
  • 00:19:06
    they might run into some issues so
  • 00:19:08
    instead I said okay Grant Ubuntu user as
  • 00:19:10
    well now the other thing that you have
  • 00:19:12
    to do is because Jenkins sometimes okay
  • 00:19:15
    it does not happen every time sometimes
  • 00:19:17
    Jenkins might not pick up these changes
  • 00:19:19
    so just restart your Jenkins okay so to
  • 00:19:22
    restart your Jenkins just go to your
  • 00:19:24
    Jenkins URL click on slash and just type
  • 00:19:27
    restart
  • 00:19:29
    okay then you will see a pop-up called
  • 00:19:31
    are you sure you want to restart Jenkins
  • 00:19:33
    just say yes
  • 00:19:35
    okay so your Jenkins is restarted the
  • 00:19:38
    reason why I'm doing is sometimes uh
  • 00:19:39
    Jenkins might not pick up the changes or
  • 00:19:42
    your Jenkins might be created a long
  • 00:19:43
    time and there might be some caching so
  • 00:19:45
    it is a good practice to restart your
  • 00:19:48
    Jenkins or uh whenever you install some
  • 00:19:50
    Jenkins plugins you will anyways restart
  • 00:19:52
    your Jenkins so that uh you don't have
  • 00:19:54
    to do it now anything is fine
  • 00:19:57
    so I'll just wait for the Jenkins
  • 00:19:59
    instance to come up again it will not
  • 00:20:01
    take much time now if you see here it
  • 00:20:03
    hardly took two seconds now
  • 00:20:05
    login to your Jenkins so if you did not
  • 00:20:08
    create the password previously it would
  • 00:20:10
    be difficult for you so always create
  • 00:20:13
    your password user ID and password
  • 00:20:16
    right now
  • 00:20:18
    we are done with installing Docker here
  • 00:20:20
    right so we install Docker here now the
  • 00:20:23
    next step that you do is once you once
  • 00:20:26
    you install Docker the other thing that
  • 00:20:27
    you have to do is you have to install
  • 00:20:29
    the docker plugin inside this Jenkins
  • 00:20:32
    okay so why you have to install Docker
  • 00:20:35
    pipeline plugin is like you know to run
  • 00:20:38
    Docker as agent Jenkins should
  • 00:20:41
    understand that okay whenever I'm
  • 00:20:42
    executing a job I have to make sure that
  • 00:20:45
    if the user provides in the Jenkins file
  • 00:20:47
    to run this uh specific job on Docker uh
  • 00:20:51
    I I need to have the configuration so
  • 00:20:53
    that's the reason why you will install
  • 00:20:54
    the docker pipeline so that Jenkins will
  • 00:20:57
    execute your pipelines on Docker agent
  • 00:20:59
    if the required configuration is
  • 00:21:01
    provided in the Jenkins file so again
  • 00:21:04
    let me come here click on dashboard
  • 00:21:08
    you will see manage Jenkins click on
  • 00:21:10
    manage Jenkins
  • 00:21:12
    once you click on manage Jenkins so if
  • 00:21:14
    you are using old version of Jenkins you
  • 00:21:16
    will see manage notes if you are using
  • 00:21:17
    new version of gen games you will see
  • 00:21:18
    manage nodes and clouds so click on
  • 00:21:21
    manage nodes and clouds uh sorry clouds
  • 00:21:23
    after that what you will do is
  • 00:21:26
    you have to oh sorry my bad uh go to
  • 00:21:30
    manage Jenkins and you have to go to
  • 00:21:31
    manage plugins not manage nodes uh sorry
  • 00:21:35
    for that just click on manage plugins
  • 00:21:37
    and install the docker pipeline plugin
  • 00:21:40
    okay so search for Docker pipeline
  • 00:21:42
    plugin in the available plugin section
  • 00:21:45
    again uh just to mention that everything
  • 00:21:47
    is part of the document if you are not
  • 00:21:49
    able to follow the video you can also
  • 00:21:51
    follow my GitHub repository where I have
  • 00:21:54
    provided all these details okay so fork
  • 00:21:57
    or clone the repository or start the
  • 00:21:58
    Repository
  • 00:22:00
    so docker pipeline
  • 00:22:03
    so this is the docker pipeline plugin
  • 00:22:05
    either you can click on install without
  • 00:22:07
    restart or download now and install uh
  • 00:22:10
    after restart anything is fine okay but
  • 00:22:12
    what you need to do is once these
  • 00:22:14
    plugins are installed there are three
  • 00:22:16
    plugins that are getting installed okay
  • 00:22:18
    it said download it successfully will be
  • 00:22:20
    activated during your next boot that is
  • 00:22:23
    during your next start or restart so
  • 00:22:25
    that's the reason why again you need to
  • 00:22:26
    restart your Jenkins okay so uh don't
  • 00:22:29
    get frustrated while you are restarting
  • 00:22:31
    Jenkins too many times so it is required
  • 00:22:34
    if you are not restarting your Jenkins
  • 00:22:36
    your changes might not get reflected and
  • 00:22:39
    you know somewhere down the line you run
  • 00:22:41
    into some issue and you never understand
  • 00:22:43
    what is the issue so that's why always
  • 00:22:45
    try to restart the Jenkins
  • 00:22:48
    so like you see uh it it will not take
  • 00:22:50
    much time it will hardly take some uh
  • 00:22:53
    five to ten seconds so don't worry about
  • 00:22:55
    it
  • 00:22:58
    perfect again I'll just provide the
  • 00:23:01
    password and username
  • 00:23:03
    now everything is configured and
  • 00:23:06
    installed so we can proceed with writing
  • 00:23:08
    our first Jenkins pipeline okay so for
  • 00:23:11
    the viewers let's say somebody is very
  • 00:23:13
    new to Jenkins what you need to do is
  • 00:23:15
    just click on new item okay then there
  • 00:23:17
    are multiple ways of creating Jenkins
  • 00:23:19
    pipelines so you can create a freestyle
  • 00:23:21
    project you can create a pipeline
  • 00:23:23
    project multi configuration project
  • 00:23:25
    multi-branch pipeline organization
  • 00:23:27
    folder is just a folder that you want to
  • 00:23:29
    create but why you have so many
  • 00:23:32
    varieties of it so if uh like you know
  • 00:23:35
    if you go back uh five years or ten
  • 00:23:37
    years there was only freestyle project
  • 00:23:39
    okay all that you can do was only a
  • 00:23:41
    freestyle project where you provide
  • 00:23:42
    everything as part of your uh like I'll
  • 00:23:45
    show you okay so if I just have to show
  • 00:23:48
    you this one if you click on the
  • 00:23:49
    freestyle project so everything can be
  • 00:23:51
    provided in the input boxes okay so uh
  • 00:23:55
    Jenkins used to provide these boxes
  • 00:23:57
    where it it explains you like you know
  • 00:23:58
    if if git then provide the details here
  • 00:24:01
    if you want to provide anything else you
  • 00:24:03
    gonna provide all the details here but
  • 00:24:05
    what is happening or the the biggest
  • 00:24:07
    drawback of this approach like even you
  • 00:24:10
    might find this very comfortable for the
  • 00:24:12
    users like let's say I'm a devops
  • 00:24:13
    engineer I have to do zero coding here
  • 00:24:15
    right everything is just a text boxes
  • 00:24:17
    and I can just provide the repository
  • 00:24:19
    URL of my GitHub or I can provide some
  • 00:24:22
    credentials everything as part of the
  • 00:24:23
    check boxes which is very easy for me
  • 00:24:25
    but the problem is this is not a
  • 00:24:27
    declarative approach right so what do I
  • 00:24:30
    mean by declarative approach is
  • 00:24:32
    this approach cannot be shared with the
  • 00:24:34
    team members let's say if you're using a
  • 00:24:36
    freestyle project and tomorrow morning
  • 00:24:39
    somebody has modified uh or you know uh
  • 00:24:42
    you want to only modify it by sending it
  • 00:24:44
    by your peer review like if you're
  • 00:24:46
    writing a calculator application in
  • 00:24:48
    Python and you want to modify the
  • 00:24:50
    addition functionality what you do is
  • 00:24:52
    you would raise a pull request on GitHub
  • 00:24:53
    and some of your peer will review it but
  • 00:24:56
    in this approach the major drawback is
  • 00:24:58
    that it cannot go through all of this
  • 00:25:00
    workflow which is a workflow that is
  • 00:25:01
    followed by most of the tools so to
  • 00:25:03
    overcome this process and there are
  • 00:25:05
    other drawbacks as well I'm just
  • 00:25:06
    explaining one drawback
  • 00:25:08
    so to overcome all of these problems
  • 00:25:10
    Jenkins has come up with a pipeline
  • 00:25:12
    approach now what is pipeline approach
  • 00:25:14
    so if I just say
  • 00:25:18
    first Jenkins job and let me select the
  • 00:25:22
    pipeline okay so in the pipeline
  • 00:25:24
    approach the biggest Advantage is you
  • 00:25:26
    can write a declarative or you can write
  • 00:25:28
    a scripted pipelines so using
  • 00:25:30
    declarative or scripted pipelines what
  • 00:25:32
    happens is you can write your pipeline
  • 00:25:34
    as code here like let's say I want to
  • 00:25:37
    write a hello world or I just want to
  • 00:25:39
    build a Jenkins plus Maven application
  • 00:25:41
    so this is a draft like similarly you
  • 00:25:44
    can write your own stages and you can
  • 00:25:46
    write your own steps and you can put
  • 00:25:48
    this entire thing in a git repository or
  • 00:25:51
    in a GitHub repository and you can have
  • 00:25:53
    it uh go through your peer reviews or
  • 00:25:55
    you know you can always extend it
  • 00:25:57
    whenever a new plugin is written you can
  • 00:25:59
    simply modify the code and it is very
  • 00:26:01
    easy right because we are all used to
  • 00:26:03
    the code approach or we are all used to
  • 00:26:05
    uh storing the code in GitHub getting
  • 00:26:08
    through the review process seeing if
  • 00:26:09
    anything is wrong and you know if you
  • 00:26:12
    have any declarative model where you can
  • 00:26:14
    see what is in your GitHub instead of
  • 00:26:16
    logging into your Jenkins all the time
  • 00:26:18
    go into this specific job if there are
  • 00:26:20
    100 jobs you have to go to 100 jobs and
  • 00:26:22
    see what is the configuration in each
  • 00:26:24
    and every of this job but instead if you
  • 00:26:26
    have things on GitHub or any Version
  • 00:26:27
    Control System you can see not only uh
  • 00:26:30
    all the Jenkins files uh today but you
  • 00:26:33
    can also track the previous versions
  • 00:26:34
    very easily right
  • 00:26:36
    so that is the reason why we should
  • 00:26:38
    always go with the pipeline approach
  • 00:26:40
    like even if you are learning Jenkins
  • 00:26:42
    today don't start with the freestyle
  • 00:26:44
    project always start with the pipeline
  • 00:26:45
    project itself now you might say that
  • 00:26:47
    okay pipeline I have to write all of
  • 00:26:49
    these code in groovy scripting I don't
  • 00:26:51
    know groovy scripting don't worry uh
  • 00:26:54
    that is what I am going to explain today
  • 00:26:55
    in today's topic I'll try to make it as
  • 00:26:58
    simple as possible and even after that
  • 00:27:00
    if you have some problem I'll also show
  • 00:27:02
    you some tips and tricks
  • 00:27:03
    okay so firstly what we will do is we'll
  • 00:27:07
    start with the basic one in my GitHub
  • 00:27:09
    repository that is writing my first
  • 00:27:11
    pipeline right so this this folder uh I
  • 00:27:14
    have three uh Jenkins projects for you
  • 00:27:16
    today and the first one is my first
  • 00:27:18
    pipeline
  • 00:27:20
    so my first pipeline what does it say a
  • 00:27:23
    simple Jenkins pipeline to verify if
  • 00:27:25
    Docker slave configuration or Docker
  • 00:27:27
    agent configuration actually it should
  • 00:27:29
    be a Docker agent so if the docker agent
  • 00:27:32
    configuration is working as expected or
  • 00:27:34
    not so what I am doing in this Jenkins
  • 00:27:36
    file is you know I am configuring Docker
  • 00:27:39
    as agent and then in stages I am just
  • 00:27:42
    verifying if uh you know the container
  • 00:27:45
    has node.js or not because I'm using a
  • 00:27:47
    node.js container
  • 00:27:49
    so what is this pipeline what is the
  • 00:27:51
    syntax and what is Agent and stages
  • 00:27:54
    don't worry I'll try to explain you with
  • 00:27:57
    a graphical representation or a
  • 00:27:59
    diagrammatic representation
  • 00:28:01
    so if you see here uh just give me one
  • 00:28:04
    second
  • 00:28:08
    uh if you go back here
  • 00:28:11
    right so in the previous class also we
  • 00:28:14
    discussed about it but uh I'll just take
  • 00:28:16
    some time to explain for someone who is
  • 00:28:18
    watching the video for the first time so
  • 00:28:20
    if you see here
  • 00:28:21
    Jenkins is all about picking up the code
  • 00:28:25
    from your local development or in any
  • 00:28:26
    version control system and delivering it
  • 00:28:29
    to production or any uh like you know
  • 00:28:31
    staging environment or somewhere where
  • 00:28:33
    automating all the stages that are
  • 00:28:35
    involved in between right so let's say
  • 00:28:37
    if there are 10 stages your job and
  • 00:28:39
    responsibility is to automate 10 stages
  • 00:28:41
    in Jenkins so Jenkins has acts as an
  • 00:28:44
    orchestrator even if you look at uh the
  • 00:28:46
    example here like you know Jenkins is
  • 00:28:48
    providing a sample uh click on GitHub
  • 00:28:51
    plus Maven what it is doing is it is
  • 00:28:53
    telling that there are multiple stages
  • 00:28:55
    in these Jenkins and the first stage is
  • 00:28:57
    the build stage okay so what it is doing
  • 00:29:00
    in build stage it is basically getting
  • 00:29:02
    out the code from or checking out the
  • 00:29:03
    code from GitHub after that it is
  • 00:29:05
    executing a maven Target then you know
  • 00:29:08
    it is uh verifying uh if the junit
  • 00:29:11
    coverage is proper or not and what it is
  • 00:29:14
    doing is it is just uh storing this J
  • 00:29:16
    unit artifacts right so uh basically it
  • 00:29:19
    gets some reports and it is trying to R
  • 00:29:21
    archive that artifact reports and
  • 00:29:24
    archive the artifact jar or the war
  • 00:29:26
    which is created as an end output of
  • 00:29:28
    this build process
  • 00:29:31
    so this is one stage but in Jenkins as
  • 00:29:34
    we talked in the previous class there
  • 00:29:35
    can be multiple stages right for example
  • 00:29:38
    here uh where is that my Jenkins
  • 00:29:41
    pipeline yeah so if you see here there
  • 00:29:43
    can be your SCM checkout which we just
  • 00:29:45
    talked about then there can be build uh
  • 00:29:47
    let's say your application is Java
  • 00:29:49
    application so this stage might contain
  • 00:29:51
    Maven right so you can build your
  • 00:29:54
    application using Maven then you might
  • 00:29:56
    have a test stage and as part of test
  • 00:29:58
    stage you can run some functional
  • 00:30:00
    testing you can run some code quality
  • 00:30:02
    testing or you can integrate with some
  • 00:30:04
    external code scanning or code security
  • 00:30:06
    related tooling then you finally deploy
  • 00:30:09
    this onto a Docker container or you
  • 00:30:12
    deploy it onto Docker spam or you deploy
  • 00:30:15
    it onto kubernetes whatever the platform
  • 00:30:17
    that you would like to and finally once
  • 00:30:19
    you store all of this test results and
  • 00:30:21
    once you store all of this artifacts
  • 00:30:23
    then you know you finally deliver the
  • 00:30:25
    code or the application to customer
  • 00:30:27
    right so this is the end to end and this
  • 00:30:30
    stages can increase right here in this
  • 00:30:32
    example there are four stages stage one
  • 00:30:34
    stage two stage three and stage four
  • 00:30:36
    depending upon organization to
  • 00:30:38
    organization
  • 00:30:40
    this stages will increase right so the
  • 00:30:43
    stages can increase but the entire
  • 00:30:45
    skeleton of your Jenkins pipeline is
  • 00:30:47
    always the same like for example if you
  • 00:30:49
    if you look at the example that I
  • 00:30:51
    provided here so in this example I just
  • 00:30:54
    have one stage right I said stages and
  • 00:30:56
    inside stages I said that this is a test
  • 00:30:59
    stage and there is only one step in the
  • 00:31:01
    stage step is nothing but the comments
  • 00:31:03
    that you want to execute are like you
  • 00:31:05
    know you can split your stage into
  • 00:31:07
    multiple steps if your stage is
  • 00:31:09
    complicated so I said there is only one
  • 00:31:11
    stage and inside the stage there is only
  • 00:31:13
    one step let's see the example that
  • 00:31:15
    Jenkins is providing so here what is
  • 00:31:18
    happening there is again one stage but
  • 00:31:20
    inside that one stage you have two
  • 00:31:23
    different steps so tomorrow if you have
  • 00:31:25
    three steps what you will do is just
  • 00:31:26
    you'll you'll just write one more step
  • 00:31:28
    right so you said steps here you keep on
  • 00:31:31
    increasing the steps but the entire
  • 00:31:33
    skeleton is same don't worry that okay
  • 00:31:35
    I'm very new to uh groovy scripting I
  • 00:31:38
    don't know how groovy scripting works so
  • 00:31:39
    just take take any example if you if you
  • 00:31:42
    start working in an organization you can
  • 00:31:44
    look at the previous Jenkins files or
  • 00:31:46
    you know you can also take uh help here
  • 00:31:49
    like I showed you this is a Hello World
  • 00:31:51
    program
  • 00:31:52
    so you can start learning from the hello
  • 00:31:54
    world you can start learning from my
  • 00:31:55
    repository and there is also one more
  • 00:31:57
    flexibility that is
  • 00:32:00
    Jenkins provide you pipeline syntax so
  • 00:32:02
    pipeline syntax is a very good utility
  • 00:32:05
    let's say I don't know the Syntax for
  • 00:32:07
    checking out the code from GitHub like
  • 00:32:09
    if you see here what this project is
  • 00:32:12
    doing here uh where is this one like if
  • 00:32:14
    you go back here what GitHub plus Maven
  • 00:32:18
    example project is doing is it is
  • 00:32:20
    checking out the code from GitHub now
  • 00:32:22
    you might say that Abhishek I don't know
  • 00:32:23
    Syntax for this now how do I write this
  • 00:32:25
    one I know I can Google it but is there
  • 00:32:27
    any way so the easy way is just go to
  • 00:32:29
    this pipeline syntax and search for the
  • 00:32:31
    option whatever you want to write so
  • 00:32:33
    here I want to write for git I want to
  • 00:32:35
    check out code from git so it is saying
  • 00:32:37
    okay just provide me the repository URL
  • 00:32:39
    so I'll say this is just a dummy one
  • 00:32:42
    okay I'll say uh github.com Slash uh
  • 00:32:46
    Argo proj slash Argo hyphen CD let's say
  • 00:32:50
    and the Brand's name I want to create
  • 00:32:52
    Jenkins pipeline for main branch for
  • 00:32:54
    example or let it be Master branch and
  • 00:32:56
    finally I can provide some credentials I
  • 00:32:59
    did not save any credentials in this
  • 00:33:00
    Jenkins but if there is some credentials
  • 00:33:01
    that are shown just run on generate
  • 00:33:03
    pipeline script so this is the script
  • 00:33:05
    you can just copy it and you can put it
  • 00:33:07
    in on Pipeline after that let's say I
  • 00:33:10
    want to run couple of shell scripts so
  • 00:33:12
    what I need to do is I can search for
  • 00:33:13
    shell script option here search for
  • 00:33:15
    shell script and it will ask what are
  • 00:33:16
    the shell scripts that you want to run
  • 00:33:18
    I'll say just CD to a folder called Foo
  • 00:33:20
    and run a script called as hack
  • 00:33:25
    test dot sh okay so just again run the
  • 00:33:28
    pipeline script and it will give you how
  • 00:33:30
    to use this as syntax in your Jenkins
  • 00:33:33
    pipeline so Jenkins has all of these
  • 00:33:36
    things in the Jenkins groovy code
  • 00:33:37
    generator so code generator is a utility
  • 00:33:39
    that will be your first savior so if you
  • 00:33:42
    want to learn Jenkins use this code
  • 00:33:45
    generator for writing your Jenkins
  • 00:33:47
    Pipelines
  • 00:33:48
    now I've discussed a lot about this uh
  • 00:33:51
    how to write this Jenkins scripts and
  • 00:33:54
    what are some of the tips and tricks now
  • 00:33:56
    let us proceed with our pipeline the
  • 00:33:58
    first pipeline for the day and I will
  • 00:34:00
    show you how to execute this pipeline
  • 00:34:02
    all that you need to do is you because I
  • 00:34:05
    already have a Jenkins file you don't
  • 00:34:07
    even have to write the Jenkins file and
  • 00:34:08
    everything just go to the specific
  • 00:34:10
    folder okay and what you will do is come
  • 00:34:13
    to your first Jenkins job okay remove
  • 00:34:15
    everything say instead of pipeline
  • 00:34:18
    script say pipeline script from sem that
  • 00:34:21
    is
  • 00:34:21
    instead of me writing the pipeline
  • 00:34:24
    script I want to pick up a pipeline
  • 00:34:26
    script from source code management
  • 00:34:27
    repository that is GitHub repository so
  • 00:34:30
    Jenkins will say okay tell me what is
  • 00:34:32
    the repository of that uh SCM so here
  • 00:34:35
    you can say go to again this folder and
  • 00:34:37
    you can copy either from here or from
  • 00:34:39
    the code section you can say okay so
  • 00:34:41
    this is My URL after that if you have
  • 00:34:44
    any credentials like mine is not a
  • 00:34:46
    private repository so I don't have any
  • 00:34:48
    credentials and then you can say is your
  • 00:34:50
    branch master or main let us see if it
  • 00:34:53
    is master or main so it is a main branch
  • 00:34:56
    change the branch domain then what is
  • 00:34:59
    the path uh is it present in the root no
  • 00:35:02
    it is actually present inside a folder
  • 00:35:04
    called my first pipeline so what you'll
  • 00:35:06
    do is copy this my first pipeline okay
  • 00:35:09
    and append it in front of like you know
  • 00:35:11
    prefix your Jenkins file with this one
  • 00:35:13
    so say my first pipeline slash Jenkins
  • 00:35:16
    file now save this one
  • 00:35:18
    okay once you save this you will start
  • 00:35:21
    seeing the entire concept that I just
  • 00:35:23
    told you like right now there is only
  • 00:35:26
    one ec2 instance if you see here there
  • 00:35:28
    is only one ec2 instance I don't have
  • 00:35:30
    worker nodes now where is this Jenkins
  • 00:35:32
    pipeline going to be executed because I
  • 00:35:34
    told you Jenkins master or ec2 instance
  • 00:35:37
    is mostly used for the scheduling
  • 00:35:40
    purpose but now where is this pipeline
  • 00:35:41
    going to run so you will see the magic
  • 00:35:43
    whenever when I run the build now option
  • 00:35:47
    so as I click on the build no option
  • 00:35:49
    what happens is this particular Jenkins
  • 00:35:52
    will start looking like firstly of
  • 00:35:54
    course it will fetch the code from
  • 00:35:56
    GitHub okay so it said that okay I am
  • 00:35:59
    fetching the code from GitHub this is
  • 00:36:00
    all the git commands that it is
  • 00:36:01
    executing and after that if you see here
  • 00:36:04
    it is pulling an image called node colon
  • 00:36:07
    16 hyphen Alpine so firstly try to see
  • 00:36:10
    if there is any Docker container or if
  • 00:36:12
    there is any Docker image on that
  • 00:36:14
    specific node okay or on that Jenkins
  • 00:36:17
    Master it did not find so what it did is
  • 00:36:19
    it tried to create one Jenkins sorry
  • 00:36:22
    Docker image it executed the entire
  • 00:36:24
    pipeline so the pipeline is very simple
  • 00:36:26
    one it just executes node hyphen version
  • 00:36:28
    because this is my first Jenkins
  • 00:36:30
    pipeline where I just want to see if
  • 00:36:32
    entire configuration is correct or not
  • 00:36:33
    that's it
  • 00:36:34
    I didn't want to do anything so here I
  • 00:36:37
    verified that my node version is correct
  • 00:36:39
    and what Jenkins is doing here is this
  • 00:36:42
    is the uh I mean this is a very
  • 00:36:44
    important thing once the execution is
  • 00:36:46
    done okay once the entire pipeline is
  • 00:36:48
    successful or the build is successful
  • 00:36:49
    Jenkins just said that delete the docker
  • 00:36:52
    container okay so now if you see like
  • 00:36:55
    this is my instance right if I come here
  • 00:36:56
    and say Docker PS you'll notice that
  • 00:36:58
    there is no running container and
  • 00:37:01
    if I do docker
  • 00:37:04
    PS hyphen a
  • 00:37:06
    you will see that okay so this is the
  • 00:37:08
    hello world container that I just showed
  • 00:37:10
    you right to verify the docker
  • 00:37:12
    installation so you can ignore this one
  • 00:37:13
    because this is just something that I
  • 00:37:15
    showed you for Docker installation but
  • 00:37:17
    there are no containers as well that
  • 00:37:19
    means Docker what it did is if you go
  • 00:37:21
    back to the previous diagram so
  • 00:37:25
    Jenkins requested Docker to create one
  • 00:37:28
    container okay so using the docker
  • 00:37:30
    pipeline plugin that we configured you
  • 00:37:32
    talk to the docker and it said okay can
  • 00:37:34
    you give me one container so that I can
  • 00:37:36
    execute my pipeline that is a node.js
  • 00:37:39
    related application Docker said okay uh
  • 00:37:41
    I'll give you a container called C1 now
  • 00:37:43
    Jenkins executed uh this on C1 and as
  • 00:37:46
    soon as the process is done it just
  • 00:37:48
    terminated the C1 okay so that means
  • 00:37:50
    even though you see the diagram like
  • 00:37:52
    this but it is always that you know
  • 00:37:55
    there are no running containers at all
  • 00:37:57
    only when there is a request a container
  • 00:38:00
    is created okay so the actual diagram
  • 00:38:02
    would be only when there is a request a
  • 00:38:05
    container is created right so this is
  • 00:38:08
    the approach so this is how you are
  • 00:38:10
    saving a lot of cost and you are saving
  • 00:38:12
    uh not not just the cost okay even if
  • 00:38:14
    you say that okay my organization is not
  • 00:38:16
    worried about the cost but the major
  • 00:38:18
    advantage is that if we go back to the
  • 00:38:20
    VMS approach
  • 00:38:22
    you have a major challenge with managing
  • 00:38:24
    the dependencies upgrading these virtual
  • 00:38:26
    machines like uh let's say today you are
  • 00:38:28
    using Centos 7. so all of these worker
  • 00:38:31
    nodes or Centos 8 and tomorrow you want
  • 00:38:33
    to upgrade all of these worker nodes to
  • 00:38:35
    send OS 9. so technically there has to
  • 00:38:38
    be a devops theme that is managing this
  • 00:38:40
    worker nodes as well right and today you
  • 00:38:42
    are using node.js 14. tomorrow you want
  • 00:38:45
    node.js 15. so somebody has to log into
  • 00:38:48
    these virtual machines and they have to
  • 00:38:49
    update the node.js version any
  • 00:38:51
    dependencies are there they have to
  • 00:38:52
    update the dependency versions as well
  • 00:38:54
    if there is any security related
  • 00:38:55
    concerns they have to update that
  • 00:38:57
    packages package.json lot of things
  • 00:38:59
    right whereas if you look at my
  • 00:39:01
    configuration here only thing that you
  • 00:39:03
    need to do is just go to this specific
  • 00:39:06
    file and from Note 7 16 Alpine just
  • 00:39:10
    change it to node 17 Alpine that's it
  • 00:39:12
    you just have to change two magical
  • 00:39:14
    letters and your entire configuration is
  • 00:39:16
    done so this is the advantage of using
  • 00:39:19
    Docker as agent now you might say that
  • 00:39:21
    okay I am expecting to write a big
  • 00:39:23
    Jenkins pipeline but you just shared me
  • 00:39:25
    the steps to write a very simple one but
  • 00:39:27
    I'm actually interested in writing a big
  • 00:39:29
    one so the only difference that you do
  • 00:39:31
    is write uh you don't have to worry
  • 00:39:34
    about anything just come here keep
  • 00:39:36
    adding stages okay so this is one stage
  • 00:39:39
    right what you do after this is add one
  • 00:39:41
    more stage add one more stage and
  • 00:39:43
    instead of test stage you might call
  • 00:39:46
    this stage as deploy and what you are
  • 00:39:48
    doing in this specific stage is probably
  • 00:39:50
    you are saying Cube CTL apply minus F at
  • 00:39:54
    deployment.aml file or probably you are
  • 00:39:57
    uh you know adding one more step for
  • 00:39:59
    sonar you are adding one more step so
  • 00:40:02
    here Jenkins pipeline is never
  • 00:40:04
    complicated unless you are not using a
  • 00:40:07
    write syntaxes or you know unless you
  • 00:40:09
    are not using uh proper semantics
  • 00:40:12
    no I am not going to stop it here but
  • 00:40:15
    actually I am going to show you lot of
  • 00:40:17
    other things like okay this is just a
  • 00:40:20
    simple Jenkins pipeline now if you
  • 00:40:22
    understood how to do it okay so if you
  • 00:40:24
    are clear till now just click on the
  • 00:40:26
    like button also uh share your feedback
  • 00:40:29
    to me in the comment section so that I
  • 00:40:30
    understand okay till this timestamp
  • 00:40:32
    everybody is clear okay I'm expecting
  • 00:40:34
    things are clear right now
  • 00:40:37
    after this let us see how to create a
  • 00:40:40
    multi-stage multi-agent job now what is
  • 00:40:42
    multi-stage and what is multi-agent
  • 00:40:44
    don't worry about the name so my
  • 00:40:46
    intention is that like in the previous
  • 00:40:48
    example I just showed you one node.js
  • 00:40:50
    application how to deploy it but many
  • 00:40:53
    people are asking me that Abhishek in my
  • 00:40:55
    architecture or in my current
  • 00:40:57
    organization we are using application
  • 00:40:59
    with database and we have a three Tire
  • 00:41:02
    application basically I have front end I
  • 00:41:04
    have backend and I have database now
  • 00:41:06
    database related cicd has to be executed
  • 00:41:09
    on let's say uh on a VM that has Centos
  • 00:41:12
    whereas front-end and back-end
  • 00:41:15
    applications has to be implemented on
  • 00:41:17
    virtual machine that has Ubuntu okay or
  • 00:41:19
    that has Java installed and in the back
  • 00:41:21
    end I just want Oracle installed now how
  • 00:41:24
    do I solve this problem right because if
  • 00:41:26
    you start using worker nodes then this
  • 00:41:28
    becomes very complicated and during
  • 00:41:30
    during your interviews uh they are
  • 00:41:32
    saying that okay this is not the right
  • 00:41:33
    approach so the right approach would be
  • 00:41:36
    okay so to create multiple stages and
  • 00:41:39
    like you know here I said agent has none
  • 00:41:41
    if you if you look at the previous
  • 00:41:43
    example I said agent as Docker here but
  • 00:41:45
    here what I did is I said agent as none
  • 00:41:48
    and inside the stages I mentioned like
  • 00:41:51
    okay if it is a back end stage okay use
  • 00:41:53
    a maven or use Java okay and if it is
  • 00:41:57
    front end use node or react and if it is
  • 00:42:00
    uh database related thing use any image
  • 00:42:02
    that has Oracle pre-installed in it or
  • 00:42:05
    whenever a container is created then it
  • 00:42:07
    has Oracle or MySQL or anything that is
  • 00:42:09
    already installed so what you can do if
  • 00:42:11
    it is a three-time architecture
  • 00:42:14
    okay probably for front end you might be
  • 00:42:17
    using node.js for backend you might be
  • 00:42:19
    using uh Java with Maven and for
  • 00:42:22
    database okay so what I'll do is I'll
  • 00:42:24
    just copy the things from here to here
  • 00:42:28
    and I'll add one more stage here
  • 00:42:33
    oh my bad
  • 00:42:35
    okay and here I'll say
  • 00:42:39
    database and the image I'll just change
  • 00:42:42
    it to mySQL okay so MySQL let me call it
  • 00:42:46
    as latest okay I'll say my my SQL latest
  • 00:42:48
    never use latest always use image that
  • 00:42:51
    is required the image stack that is
  • 00:42:53
    required but let's say MySQL column
  • 00:42:55
    latest and inside the steps I'll I'll
  • 00:42:57
    run some I SQL related queries or you
  • 00:42:59
    know I'll do some DB related migrations
  • 00:43:01
    or I'll run some joint queries or
  • 00:43:03
    whatever is required here okay so select
  • 00:43:05
    just for an example here okay select
  • 00:43:07
    star from
  • 00:43:10
    x y z okay so this is how you even
  • 00:43:14
    manage multi-tier architecture
  • 00:43:16
    applications okay so you can run this
  • 00:43:18
    pipeline again as is do not save
  • 00:43:20
    anything uh like I'm just providing the
  • 00:43:23
    skeletons like I told you you can force
  • 00:43:24
    this repositories and you can play with
  • 00:43:27
    your applications like you know you can
  • 00:43:28
    uh instead of Maven uh 3.8 you can just
  • 00:43:31
    change it to 3.9 or you can use any
  • 00:43:34
    dummy Java application and you can use
  • 00:43:35
    the same pipeline okay you don't have to
  • 00:43:37
    change anything just bring some Java
  • 00:43:39
    hello world code you can find it
  • 00:43:41
    anywhere in the internet just add that
  • 00:43:43
    Java hello world code to this repository
  • 00:43:45
    and run the maven targets okay and run
  • 00:43:48
    the node.js related things like bring
  • 00:43:50
    one node.js dummy application and run
  • 00:43:51
    the node.js you can you can build your
  • 00:43:54
    uh own pipelines by using this
  • 00:43:56
    repository as your skeleton so now let
  • 00:43:59
    me also try to
  • 00:44:01
    execute this Pipeline and show you now
  • 00:44:04
    what should happen is if you are
  • 00:44:05
    executing this pipe
  • 00:44:10
    you should be able to see that two
  • 00:44:13
    containers are created okay like I told
  • 00:44:15
    you the containers will be deleted but
  • 00:44:17
    this time what I'll show you is using
  • 00:44:19
    the terminal like whenever I start
  • 00:44:20
    executing this pipeline
  • 00:44:22
    I'll show you that
  • 00:44:24
    um you know the containers are created
  • 00:44:27
    dynamically and inside one container May
  • 00:44:29
    when targets are running and inside one
  • 00:44:31
    container your node.js related targets
  • 00:44:33
    are running so in real in real life
  • 00:44:35
    scenarios instead of Maven hyphen
  • 00:44:37
    version you would actually use mvn clean
  • 00:44:39
    install mvn package or any Maven related
  • 00:44:42
    targets and here
  • 00:44:44
    instead of node hyphen iPhone version
  • 00:44:46
    you would be using something called as
  • 00:44:48
    npm run or npm install or any any of the
  • 00:44:51
    targets related to npm
  • 00:44:54
    right so let me
  • 00:44:56
    use the same Jenkins job okay so instead
  • 00:44:59
    of creating a new Jenkins Zone what I
  • 00:45:01
    will do is I'll use the same Jenkins job
  • 00:45:03
    but I'll try to modify the SCM related
  • 00:45:05
    targets that is here
  • 00:45:08
    the repository name will be the same but
  • 00:45:10
    the folder of my Jenkins file is the
  • 00:45:12
    only one that will change okay what is
  • 00:45:14
    the name of the folder here
  • 00:45:16
    multi-stage multi-agent
  • 00:45:20
    why I am calling it as multi-agent
  • 00:45:22
    because here I am using multiple Docker
  • 00:45:25
    containers
  • 00:45:26
    uh not this one here yeah so I'm using
  • 00:45:29
    multiple Docker containers dedicated to
  • 00:45:31
    the uh usage like uh if you want for
  • 00:45:35
    front and one Docker container for
  • 00:45:36
    backend one Docker container and for DB
  • 00:45:38
    related one Docker container
  • 00:45:41
    let me save it
  • 00:45:42
    okay and let me execute it
  • 00:45:46
    so as soon as I execute it you will see
  • 00:45:48
    that a new uh
  • 00:45:50
    Jenkins pipeline is running now let me
  • 00:45:52
    run Docker PS and show you what is
  • 00:45:55
    happening okay till now it is not
  • 00:45:57
    created let us give it one more uh
  • 00:46:00
    few more seconds so till now I think it
  • 00:46:03
    is just picking up the uh code from the
  • 00:46:05
    GitHub repository
  • 00:46:09
    I think now it is getting created
  • 00:46:12
    yeah if you see here the maven related
  • 00:46:14
    container is created and after that you
  • 00:46:16
    will also see uh you see see here the
  • 00:46:19
    node related container is created that
  • 00:46:21
    means your first job got executed right
  • 00:46:24
    and then uh sorry your first stage got
  • 00:46:27
    executed and after that your second
  • 00:46:28
    stage also got executed that means both
  • 00:46:31
    your stages are executed and if you see
  • 00:46:33
    here now the docker containers are
  • 00:46:35
    terminated isn't it amazing so this
  • 00:46:37
    should be your organization architecture
  • 00:46:40
    right if your organization is using VM
  • 00:46:43
    based approach you should always look at
  • 00:46:45
    migrating them to this Docker container
  • 00:46:47
    based approach you should suggest this
  • 00:46:49
    architecture in your organization so
  • 00:46:51
    that you not only save the cost but you
  • 00:46:53
    are also saving a lot of time for your
  • 00:46:55
    organization because
  • 00:46:57
    if you look at the Legacy jobs okay
  • 00:47:00
    let's say here instead of the docker
  • 00:47:02
    containers we are using VMS so what will
  • 00:47:04
    happen is you are technically
  • 00:47:06
    maintaining two VMS so you are
  • 00:47:08
    maintaining a VM for Maven you are
  • 00:47:10
    maintaining a VM for node.js and
  • 00:47:11
    whenever the node.js version is
  • 00:47:13
    increased you have to go to that VM and
  • 00:47:15
    you have to increase that Maven version
  • 00:47:16
    in that VM and if the node.js version is
  • 00:47:19
    increased you have to increase that if
  • 00:47:21
    the base image of the ec2 instance is
  • 00:47:24
    seen you either have to terminate that
  • 00:47:26
    instance create a new one or inside that
  • 00:47:28
    instance itself you have to update so
  • 00:47:30
    there is a lot of Maintenance activity
  • 00:47:32
    for the devops engineers and using this
  • 00:47:34
    approach we are avoiding that
  • 00:47:35
    maintenance activity
  • 00:47:37
    right
  • 00:47:39
    I hope that things are clear till now so
  • 00:47:41
    this is how I I mean I just showed you
  • 00:47:43
    two examples uh one is your first
  • 00:47:45
    Jenkins Pipeline and then you have your
  • 00:47:47
    multi-stage multi-agent now the
  • 00:47:50
    assignment would be I'll be interested
  • 00:47:52
    if somebody can enhance this one and
  • 00:47:54
    create a pull request like you know add
  • 00:47:56
    one more folder Fork this repository add
  • 00:47:58
    one more folder and you know show me
  • 00:48:01
    that Abhishek I just use your uh
  • 00:48:03
    examples and what I did was instead of
  • 00:48:06
    Maven hyphen f inversion and node hyphen
  • 00:48:09
    iPhone version I actually created an
  • 00:48:11
    application like it can be simple hello
  • 00:48:12
    world as well so submit a Java hello
  • 00:48:15
    world application submit a node.js hello
  • 00:48:17
    world application and try to execute the
  • 00:48:19
    targets instead of mbn hyphen F1 version
  • 00:48:22
    just change it to mbn install ambient
  • 00:48:24
    clean installer mvn package and here
  • 00:48:26
    just try to change it to npm install and
  • 00:48:28
    uh like you know it can be hardly it
  • 00:48:31
    will take five minutes okay you can just
  • 00:48:32
    find a search for even ask that GPT to
  • 00:48:35
    give me a Java hello world Java class
  • 00:48:38
    and put that in the repository and try
  • 00:48:41
    to execute using Jenkins pipeline
  • 00:48:43
    now we'll come to the complicated topic
  • 00:48:46
    for today and that is how to set up CI
  • 00:48:48
    CD the same I mean we'll use the cicd
  • 00:48:52
    flow in this case I also wrote an
  • 00:48:54
    application I mean I just used an
  • 00:48:56
    existing application I did not write it
  • 00:48:57
    so this is my existing python
  • 00:49:00
    application okay we uh if you watch my
  • 00:49:03
    previous kubernetes videos we use the
  • 00:49:05
    to-do application so this is my to-do
  • 00:49:06
    application and what I am trying to do
  • 00:49:08
    is I am trying to implement this
  • 00:49:10
    architecture for you okay so many people
  • 00:49:13
    have asked me this one okay Abhishek how
  • 00:49:15
    do I do this like you know I want to
  • 00:49:17
    deploy my artifacts onto kubernetes
  • 00:49:19
    directly
  • 00:49:20
    I want to create a Jenkins pipeline
  • 00:49:22
    which says end to end right from
  • 00:49:24
    checking out the code to deploying the
  • 00:49:25
    artifacts onto kubernetes
  • 00:49:28
    so I have seen many people instead of
  • 00:49:30
    Argo CD using ansible here okay so I'm
  • 00:49:33
    not against the approach of using
  • 00:49:35
    ansible or I'm not uh like you know
  • 00:49:38
    saying that everybody has to use Argo CD
  • 00:49:40
    but the point is Argo CD is a modern day
  • 00:49:43
    uh continuous delivery like it's a
  • 00:49:45
    declarative continuous delivery
  • 00:49:46
    application and if you use Argo CD it
  • 00:49:49
    has the like you know it's a tool that
  • 00:49:51
    is developed for continuous delivery
  • 00:49:53
    okay ansible is a configuration
  • 00:49:54
    management Tool uh I mean by luck or by
  • 00:49:58
    any anyways it can actually deploy the
  • 00:50:00
    code onto your kubernetes clusters but
  • 00:50:03
    Argo CD can not only just deploy but it
  • 00:50:06
    it can also monitor the state inside
  • 00:50:08
    your kubernetes cluster let's say
  • 00:50:10
    in your GitHub okay what you are doing
  • 00:50:13
    is you are saying that I want uh Foo dot
  • 00:50:17
    uh I mean your application is full and
  • 00:50:19
    you have version 3 of your full
  • 00:50:21
    application so if you are using ansible
  • 00:50:22
    ansible just deploys uh whatever you are
  • 00:50:25
    storing it in Helm charts or whatever
  • 00:50:26
    you are storing in the deployment.yaml
  • 00:50:29
    files it will just pick up and it will
  • 00:50:31
    just deploy under your kubernetes
  • 00:50:32
    cluster but if you are using Argo CD or
  • 00:50:34
    flux or Spinnaker any of the continuous
  • 00:50:36
    delivery uh declarative continuous
  • 00:50:38
    delivery tools or github's tools what
  • 00:50:41
    they do is they will ensure that the
  • 00:50:44
    state is always the same because they
  • 00:50:45
    are kubernetes controllers so they are
  • 00:50:47
    actually deployed in your kubernetes
  • 00:50:49
    cluster itself now without wasting any
  • 00:50:51
    time I'll show you how to do this so
  • 00:50:53
    this is a simple python based
  • 00:50:55
    application so this is a to-do
  • 00:50:57
    application and if you deploy the
  • 00:50:58
    application uh you will see uh the
  • 00:51:01
    application like this so it will just
  • 00:51:02
    have a simple UI and I also explained
  • 00:51:06
    the implementation everything in the
  • 00:51:08
    previous examples but if you want to try
  • 00:51:10
    it by yourself just run this Docker file
  • 00:51:13
    all that you need to do is just say
  • 00:51:15
    Docker run minus ID and the docker file
  • 00:51:19
    it will run the application on your
  • 00:51:21
    localhost and you can directly see the
  • 00:51:23
    application on your localhost like this
  • 00:51:25
    now the idea or the point is to
  • 00:51:28
    implement the entire thing in Jenkins
  • 00:51:30
    Pipeline and to deploy that onto
  • 00:51:32
    kubernetes cluster so if you want to uh
  • 00:51:36
    watch the video from 0 to the end to end
  • 00:51:39
    I already have the video on my YouTube
  • 00:51:41
    channel so I put the link here where
  • 00:51:43
    I'll do the exact same thing like you
  • 00:51:45
    know I'll create a Jenkins pipeline that
  • 00:51:47
    will watch for GitHub repository and
  • 00:51:49
    then you know I'll try to build the
  • 00:51:51
    application that is the python
  • 00:51:53
    application I'll try to put this python
  • 00:51:55
    application artifact that is a Docker
  • 00:51:57
    container I'll try to push them to
  • 00:51:58
    GitHub and I'll also paralleling update
  • 00:52:01
    the deployment.dml file inside the
  • 00:52:03
    GitHub and Argo CD if you see here the
  • 00:52:07
    arrow is actually pointing towards
  • 00:52:08
    GitHub okay or it is pointing towards
  • 00:52:10
    Jenkins not from Jenkins to argosity
  • 00:52:12
    that means Argo CD will watch for any
  • 00:52:15
    change in GitHub it understands that
  • 00:52:17
    okay there is a new version of to-do
  • 00:52:18
    application and it will automatically
  • 00:52:20
    pick up and deploy the application onto
  • 00:52:21
    kubernetes so the entire thing I think
  • 00:52:24
    it's a 30 minutes video and the entire
  • 00:52:26
    video is present here but today I'll
  • 00:52:27
    explain you how to do it like you know
  • 00:52:30
    what is the application flow how to
  • 00:52:31
    write Jenkins file for it
  • 00:52:34
    so like I explained you can also choose
  • 00:52:36
    Docker container as agent all that you
  • 00:52:39
    need to do is simply agent hyphen Docker
  • 00:52:41
    and provide the python version like like
  • 00:52:44
    we provided node.js and Maven version
  • 00:52:46
    you can provide a Docker image is equals
  • 00:52:49
    to python 3.
  • 00:52:50
    once you're done with it what I am
  • 00:52:52
    firstly doing is I am writing a checkout
  • 00:52:54
    stage inside this checkout stage I have
  • 00:52:56
    a single step that is checking out the
  • 00:52:59
    python code from sem that is source code
  • 00:53:01
    management after that we are trying to
  • 00:53:04
    build Docker I mean I am trying to
  • 00:53:06
    actually build a Docker image for this
  • 00:53:07
    application like I mentioned here it's
  • 00:53:09
    just Docker build and then I'll push
  • 00:53:12
    this Docker image to Docker Hub and
  • 00:53:16
    finally what I'll do is I'll try to
  • 00:53:19
    update the deployment.yaml okay so the
  • 00:53:22
    deployment at ml is a kubernetes
  • 00:53:24
    deployment file which is present here
  • 00:53:26
    okay so inside the deployment folder I
  • 00:53:29
    have a kubernetes deployment.yaml and
  • 00:53:30
    service.yaml so I'll update this
  • 00:53:33
    deployment.yaml with the new version
  • 00:53:35
    that is created
  • 00:53:37
    that is you know instead of version one
  • 00:53:41
    let's say the build number is 2 what
  • 00:53:43
    I'll do is uh Abhishek hyphen uh sorry
  • 00:53:46
    Abhishek F5 hyphen to do hyphen app
  • 00:53:49
    column
  • 00:53:51
    build 35 or number 35 and what Argo CD
  • 00:53:55
    will do is okay so I notice that there
  • 00:53:58
    is change in this deployment.aml and for
  • 00:54:00
    Argo CD git is always a single source of
  • 00:54:03
    truth right so what Argo CD will do is
  • 00:54:06
    it will watch for this specific change
  • 00:54:07
    uh let me go back to that diagram
  • 00:54:11
    yeah so what Argo CD will do is it will
  • 00:54:14
    notice a change in git repository and it
  • 00:54:16
    will deploy the applications onto
  • 00:54:17
    kubernetes cluster so you can directly
  • 00:54:20
    implement this one just uh like I always
  • 00:54:22
    say just clone my repository and try to
  • 00:54:25
    run this Jenkins file and Argo CD
  • 00:54:27
    configuration you can watch from this
  • 00:54:29
    video it will hardly take you five
  • 00:54:30
    minutes you just have to install a
  • 00:54:33
    kubernetes cluster it can be mini Cube
  • 00:54:34
    or it can be k3s or anything and install
  • 00:54:37
    Argo CD as an operator or as a simple
  • 00:54:39
    binary and make sure your Argo CD is
  • 00:54:42
    watching this repository I showed you
  • 00:54:44
    the exact steps in the video that I
  • 00:54:46
    mentioned here so you can follow the
  • 00:54:47
    video as is okay so with that you will
  • 00:54:50
    be able to set up the end to end Jenkins
  • 00:54:52
    pipeline configuration setup and your
  • 00:54:55
    deployment will be taking on the
  • 00:54:56
    kubernetes cluster
  • 00:55:07
    okay so this is about the uh kubernetes
  • 00:55:10
    uh delivery or kubernetes cacd process
  • 00:55:13
    now
  • 00:55:14
    we'll move to the final topic for today
  • 00:55:17
    that is Jenkins interview questions okay
  • 00:55:20
    so I already covered the Jenkins
  • 00:55:21
    interview questions again on my video
  • 00:55:23
    but I'll explain you uh on brief what
  • 00:55:26
    can be the interview questions on
  • 00:55:27
    Jenkins
  • 00:55:28
    so the first and foremost question uh
  • 00:55:31
    that people would be interested is to
  • 00:55:32
    understand your cicd process okay so you
  • 00:55:35
    can explain the cicd process that I
  • 00:55:36
    showed you here so you can just tell the
  • 00:55:39
    exact same process but you can say uh
  • 00:55:42
    depending upon your organization let's
  • 00:55:44
    say you are using a Android or mobile
  • 00:55:45
    application so you can slightly modify
  • 00:55:48
    the steps here and say that for the
  • 00:55:50
    build language I'm using Android build
  • 00:55:53
    process or for Java applications I'm
  • 00:55:55
    using Maven for
  • 00:55:59
    for node.js applications I'm using npm
  • 00:56:02
    so depending upon your application to
  • 00:56:04
    application you can Define uh the stages
  • 00:56:06
    but the standard flow will be you
  • 00:56:08
    explain your cicd process as what we are
  • 00:56:11
    doing is we are firstly checking out the
  • 00:56:12
    code from uh sem when we are building
  • 00:56:14
    the application then we test it for uh
  • 00:56:17
    code vulnerabilities code code scanning
  • 00:56:19
    static code analysis sash dashed and
  • 00:56:22
    then you can finally say that we store
  • 00:56:24
    the artifacts and we deploy them onto
  • 00:56:26
    your kubernetes cluster for deployment
  • 00:56:29
    we use Argo CD or if you are familiar
  • 00:56:31
    with ansible you can also say
  • 00:56:33
    for deployment we use ansible but if you
  • 00:56:35
    are talking about argosity probably
  • 00:56:36
    they'll think that okay you are using
  • 00:56:38
    Advanced tooling so this will be your
  • 00:56:40
    first first question that is explain the
  • 00:56:43
    CI CD organ uh sorry cicd workflow in
  • 00:56:45
    your organization once that is done then
  • 00:56:48
    people will ask you like you know uh how
  • 00:56:50
    do you handle issues in your worker
  • 00:56:52
    nodes let's say uh you know you have
  • 00:56:54
    your Jenkins jobs that are running on
  • 00:56:56
    your worker notes so how do you handle
  • 00:56:58
    these things
  • 00:56:59
    uh your worker note is going down or
  • 00:57:01
    your worker node is not responsive so
  • 00:57:03
    what you will say is that you know I'll
  • 00:57:05
    log into this worker node try to
  • 00:57:07
    understand the problem uh I'll try to uh
  • 00:57:10
    get the thread terms or you know I'll
  • 00:57:11
    try to look into the worker nodes Health
  • 00:57:13
    okay uh you can say that I wrote a
  • 00:57:16
    simple uh python application where it
  • 00:57:18
    will always monitor the worker node's
  • 00:57:20
    health and in case the CPU or Ram is
  • 00:57:22
    going out of limit okay for some reason
  • 00:57:24
    the CPU or the ram is full it will send
  • 00:57:27
    me uh alerts when the CPU reached 80 or
  • 00:57:30
    when the ram reached 80 percent so that
  • 00:57:32
    we take immediate action or you can say
  • 00:57:34
    we
  • 00:57:35
    implemented Auto scaling on the ec2
  • 00:57:37
    instances
  • 00:57:38
    but the best way is the approach that we
  • 00:57:41
    learned today you can say that okay in
  • 00:57:43
    our case we are actually using Docker
  • 00:57:44
    agents and we only spin up containers
  • 00:57:47
    when uh there is a Jenkins job that is
  • 00:57:49
    running so in that case in that way we
  • 00:57:51
    ensure that you know always our agents
  • 00:57:54
    or uh the Jenkins is never down Okay it
  • 00:57:57
    can always accept the traffic then comes
  • 00:57:59
    your Jenkins administrative related
  • 00:58:01
    questions where people will usually ask
  • 00:58:03
    you like you know how do you install
  • 00:58:05
    Jenkins or how do you expose the Jenkins
  • 00:58:07
    port to external world all of the
  • 00:58:09
    questions related to these things
  • 00:58:12
    so if you want to learn more questions
  • 00:58:14
    about Jenkins okay what are the
  • 00:58:16
    interview questions that uh people can
  • 00:58:18
    ask you on Jenkins and specifically cicd
  • 00:58:20
    I'll put the links in the description as
  • 00:58:22
    well so that you can watch those videos
  • 00:58:24
    so I'll have two links for you one is
  • 00:58:26
    how to set up Argo CD with this existing
  • 00:58:29
    pipeline so the pipeline will work
  • 00:58:30
    exactly as is like you know it will
  • 00:58:33
    check out the code from Once you run the
  • 00:58:34
    Jenkins pipeline uh it will check out
  • 00:58:36
    the code it will build the code and it
  • 00:58:38
    will update the kubernetes Manifest back
  • 00:58:40
    into the GitHub and only thing that you
  • 00:58:42
    need to do is watch this video that I'm
  • 00:58:45
    showing you here and configure Argo CD
  • 00:58:47
    on your mini Cube cluster or any cluster
  • 00:58:50
    so that your entire setup is done if you
  • 00:58:52
    have multiple kubernetes clusters you
  • 00:58:54
    can configure Argo CD to deploy to
  • 00:58:56
    multiple as well
  • 00:58:58
    so finally
  • 00:59:00
    um like I told you if you want to follow
  • 00:59:01
    the entire documentation or if you want
  • 00:59:03
    to follow the entire video in the future
  • 00:59:05
    just clone this repository or Fork this
  • 00:59:07
    repository so that you will have them
  • 00:59:09
    handy I hope you enjoy the video if you
  • 00:59:12
    like the video click on the like button
  • 00:59:14
    if you have any comments or feedback for
  • 00:59:15
    me do put that in the comment section
  • 00:59:17
    and finally don't forget to subscribe to
  • 00:59:20
    my channel
  • 00:59:21
    thank you so much I'll see in the next
  • 00:59:23
    video
タグ
  • Jenkins
  • Docker
  • Kubernetes
  • CI/CD
  • DevOps
  • Pipeline
  • AWS
  • EC2
  • Conteneurs
  • Déploiement continu