Jenkins Pipeline (Docker + Kubernetes)
Step - 1: Jenkins Server Setup
1.1) Create Ubuntu VM (20.04) using AWS EC2 (t2.medium)
1.2) Enable SSH & 8080 Ports in Ec2 Security Group
1.3) Connect through MobaXterm
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
1.5) Copy Jenkins admin password
$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
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
?1.8) Jenkins ready
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
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
Step - 4: Create EKS Management Host in AWS
4.1) Launch new Ubuntu VM using AWS Ec2 ( t2.micro )
4.2) Connect to machine and install kubectl using below commands
$ 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
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
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
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
5.3) IAM Role Created
5.4) Attach created role to EKS Management Host (Select EC2 => Click on Security => Modify IAM Role => attach IAM role we have created)
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
6.2) After cluster created we can check nodes using below command.
$ kubectl get nodes
Step - 7: Install AWS CLI in JENKINS Server
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
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
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
$ sudo vi .kube/config
9.3) Check EKS nodes
$ kubectl get nodes
Step - 10: Create Jenkins CI Job
10.1) Create New Project
10.2) Clone GitHub Repository
10.3) Git Clone Success
10.4) Maven build
10.5) Create Docker file
10.6) Pipeline syntax to create docker Image
10.7) Docker image build success
10.8) Push Docker image to DockerHub Registry
10.9) Docker image build success
Step - 11: Create Jenkins CD Job
11.1) Create CD-JOB New Pipeline
11.2) K8S Manifest file
11.3) Pipeline Syntax for CD-JOB
11.4) Pipeline Syntax for CI-JOB
Step - 12 : Trigger Jenkins CI Job
12.1) CI Job will execute all the stages and it will trigger CD Job
12.2) CD Job will fetch Docker image and it will deploy on cluster
Step - 13 : Access Application in Browser
13.1) We should be able to access our application
Happy Learning :-)
Thank you for reading. I hope you found this article helpful.
~ Mounika Jilakari.