Jenkins Pipeline (Docker + Kubernetes)
Jenkins CI/CD Pipeline using(GitHub+ Maven+ Docker+ Docker HUB +EKS)

Jenkins Pipeline (Docker + Kubernetes)

Step - 1: Jenkins Server Setup

1.1) Create Ubuntu VM (20.04) using AWS EC2 (t2.medium)

No alt text provided for this image

1.2) Enable SSH & 8080 Ports in Ec2 Security Group

1.3) Connect through MobaXterm

No alt text provided for this image

1.4) Install Java & Jenkins using below commands

$ sudo apt-get update

$ sudo apt-get install default-jdk

$ wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -

$ sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

$ sudo apt-get update

$ sudo apt-get install jenkins

$ sudo systemctl status Jenkins

No alt text provided for this image

1.5) Copy Jenkins admin password

$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword

No alt text provided for this image

1.6) Open Jenkins server in browser using VM Public IP

URL :?https://public-ip:8080/

1.7) Create Admin Account & Install Required Plugins in Jenkins

No alt text provided for this image

?1.8) Jenkins ready

No alt text provided for this image
No alt text provided for this image

Step - 2: Install Maven & Git in Jenkins

2.1) Install Maven with below command

$ sudo apt install maven -y

2.2) Install git with below command

$ sudo apt install git –y

No alt text provided for this image

Step - 3: Setup Docker in Jenkins

3.1) Install Docker

$ curl -fsSL get.docker.com | /bin/bash

3.2) Add Jenkins user to Docker group

$ sudo usermod -aG docker jenkins

3.3) Restart Jenkins

$ sudo systemctl restart jenkins

3.4) Verify Docker installation

$ sudo docker version

No alt text provided for this image

Step - 4: Create EKS Management Host in AWS

4.1) Launch new Ubuntu VM using AWS Ec2 ( t2.micro )

No alt text provided for this image

4.2) Connect to machine and install kubectl using below commands

No alt text provided for this image

$ curl -o kubectl?https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/kubectl

$ chmod +x ./kubectl

$ sudo mv ./kubectl /usr/local/bin

$ kubectl version --short –client

No alt text provided for this image

4.3) Install AWS CLI latest version using below commands

$ sudo apt install unzip

$ cd

$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

$ unzip awscliv2.zip

$ sudo ./aws/install

$ aws –version

No alt text provided for this image

4.4) Install eksctl using below commands

$ curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname?-s)_amd64.tar.gz" | tar xz -C /tmp

$ sudo mv /tmp/eksctl /usr/local/bin

$ eksctl version

No alt text provided for this image

Step - 5: Create IAM role & attach to EKS Management Host & Jenkins Server

5.1) Create New Role using IAM service ( Select Use case - ec2 )

5.2) Add below permissions for the role

  • IAM Full Access
  • VPC Full Access
  • EC2 Full Access
  • Cloud Formation Full Access
  • Administrator Access

No alt text provided for this image

5.3) IAM Role Created

No alt text provided for this image

5.4) Attach created role to EKS Management Host (Select EC2 => Click on Security => Modify IAM Role => attach IAM role we have created)

No alt text provided for this image
No alt text provided for this image

5.5) Attach created role to Jenkins Machine (Select EC2 => Click on Security => Modify IAM Role => attach IAM role we have created)

Step - 6: Create EKS Cluster using eksctl

6.1) Syntax:

eksctl create cluster --name cluster-name

--region region-name

--node-type instance-type

--nodes-min 2

--nodes-max 2 \ --zones ,

Example: $ eksctl create cluster --name myeks-cluster4 --region ap-south-1 --node-type t2.medium --zones ap-south-1a,ap-south-1b

No alt text provided for this image
No alt text provided for this image

6.2) After cluster created we can check nodes using below command.

$ kubectl get nodes

No alt text provided for this image
No alt text provided for this image

Step - 7: Install AWS CLI in JENKINS Server

URL :?https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

7.1) Execute below commands to install AWS CLI

$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

$ sudo apt install unzip

$ unzip awscliv2.zip

$ sudo ./aws/install

$ aws –version

No alt text provided for this image

Step - 8: Install Kubectl in JENKINS Server

8.1) Execute below commands in Jenkins server to install kubectl

$ curl -o kubectl?https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/kubectl

$ chmod +x ./kubectl

$ sudo mv ./kubectl /usr/local/bin

$ kubectl version --short –client

No alt text provided for this image

Step - 9: Update EKS Cluster Config File in Jenkins Server

9.1) Execute below command in EKS Management host & copy kube config file data

$ cat .kube/config

9.2) Execute below commands in Jenkins Server and paste kube config file

$ cd /var/lib/jenkins

$ sudo mkdir .kube

No alt text provided for this image

$ sudo vi .kube/config

9.3) Check EKS nodes

$ kubectl get nodes

No alt text provided for this image

Step - 10: Create Jenkins CI Job

10.1) Create New Project

No alt text provided for this image
No alt text provided for this image

10.2) Clone GitHub Repository

No alt text provided for this image

10.3) Git Clone Success

No alt text provided for this image

10.4) Maven build

No alt text provided for this image
No alt text provided for this image

10.5) Create Docker file

No alt text provided for this image

10.6) Pipeline syntax to create docker Image

No alt text provided for this image

10.7) Docker image build success

No alt text provided for this image
No alt text provided for this image

10.8) Push Docker image to DockerHub Registry

No alt text provided for this image

10.9) Docker image build success

No alt text provided for this image
No alt text provided for this image

Step - 11: Create Jenkins CD Job

11.1) Create CD-JOB New Pipeline

No alt text provided for this image

11.2) K8S Manifest file

No alt text provided for this image

11.3) Pipeline Syntax for CD-JOB

No alt text provided for this image

11.4) Pipeline Syntax for CI-JOB

No alt text provided for this image

Step - 12 : Trigger Jenkins CI Job

12.1) CI Job will execute all the stages and it will trigger CD Job

No alt text provided for this image

12.2) CD Job will fetch Docker image and it will deploy on cluster

No alt text provided for this image

Step - 13 : Access Application in Browser

13.1) We should be able to access our application

URL :?https://Node-public-ip:NodePort/context-path

No alt text provided for this image


Happy Learning :-)

Thank you for reading. I hope you found this article helpful.

~ Mounika Jilakari.

要查看或添加评论,请登录

mouni ka的更多文章

  • GitHub Actions Scouting Myntra App | DevSecOps

    GitHub Actions Scouting Myntra App | DevSecOps

    STEP 1A: Setting up AWS EC2 Instance and IAM Role Sign in to the AWS Management Console Access the AWS Management…

  • Setup ELK Stack Architecture

    Setup ELK Stack Architecture

    Continuous Monitoring: Continuous Monitoring is an important part of software development. It measures the health of…

  • Port Numbers

    Port Numbers

    DevOps engineers often work with a variety of tools and services that communicate over specific port numbers. ????????…

    1 条评论
  • Terraform: Deploying a 2-Tier Architecture

    Terraform: Deploying a 2-Tier Architecture

    Scenario Deploying a 2-tier architecture that includes all our code in a single main.tf file (known as a monolith) with…

  • Lost your Amazon EC2 Keypair?

    Lost your Amazon EC2 Keypair?

    In this, we have created two instances (DB-Server and Helper-EC2), of which one has lost its keypair. We lost our…

  • In this project I’m doing how to deploy a WordPress website on AWS(EC2 Ubuntu Instance) using Docker.

    In this project I’m doing how to deploy a WordPress website on AWS(EC2 Ubuntu Instance) using Docker.

    WordPress is a popular web hosting site that is very easy to use and setup. The platform allows users to create and…

  • Hosting Static Website With AWS S3

    Hosting Static Website With AWS S3

    Hosting Static Website With AWS S3 Steps to develop Static website 1) login to AWS Portal 2) Search for S3 Service 3)…

    2 条评论
  • Jenkins CI/CD Pipeline Setup

    Jenkins CI/CD Pipeline Setup

    Jenkins CI/CD Pipeline with GitHub + Maven + Nexus + SonarQube + Tomcat Here we will complete our setup in 6 steps Step…

    1 条评论
  • DevOps Project Setup

    DevOps Project Setup

    Spring Boot + Angular + Docker + Kubernetes – Project Setup In this project I have deployed one Full Stack Application…

社区洞察

其他会员也浏览了