- Maven
- Git Hub
- Jenkins
- Docker
- Kubernetes
- Launch new Ubuntu VM using AWS Ec2 ( t2.micro )
- 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
- Install AWS CLI latest version using below commands
sudo apt install unzip
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
- 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
-
Create New Role using IAM service ( Select Usecase - ec2 )
-
Add below permissions for the role
- IAM - fullaccess
- VPC - fullaccess
- EC2 - fullaccess
- CloudFomration - fullaccess
- Administrator - acces
- IAM - fullaccess
-
Enter Role Name (eksroleec2)
-
Attach created role to EKS Management Host (Select EC2 => Click on Security => Modify IAM Role => attach IAM role we have created)
-
Attach created role to Jenkins Machine (Select EC2 => Click on Security => Modify IAM Role => attach IAM role we have created)
Syntax:
eksctl create cluster --name cluster-name
--region region-name
--node-type instance-type
--nodes-min 2
--nodes-max 2 \
--zones ,
eksctl create cluster --name ashokit-cluster --region ap-south-1 --node-type t2.medium --zones ap-south-1a,ap-south-1b
Note: Cluster creation will take 5 to 10 mins of time (we have to wait). After cluster created we can check nodes using below command.
kubectl get nodes
- Create Ubuntu VM using AWS EC2 (t2.medium)
- Enable 8080 Port Number in Security Group Inbound Rules
- Connect to VM using MobaXterm
- Instal Java
sudo apt update
sudo apt install fontconfig openjdk-17-jre
java -version
- Install Jenkins
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
- Start Jenkins
sudo systemctl enable jenkins
sudo systemctl start jenkins
- Verify Jenkins
sudo systemctl status jenkins
- Open jenkins server in browser using VM public ip
http://public-ip:8080/
- Copy jenkins admin pwd
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- Create Admin Account & Install Required Plugins in Jenkins
- Manage Jenkins -> Tools -> Maven Installation -> Add maven
curl -fsSL get.docker.com | /bin/bash
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
sudo docker version
URL : https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
Execute below commands to install AWS CLI
sudo apt install unzip
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
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
-
Execute below command in Eks Management host & copy kube config file data
$ cat .kube/config -
Execute below commands in Jenkins Server and paste kube config file
$ cd /var/lib/jenkins
$ sudo mkdir .kube
$ sudo vi .kube/config -
Execute below commands in Jenkins Server and paste kube config file for ubuntu user to check EKS Cluster info
$ cd ~
$ ls -la
$ sudo vi .kube/config -
check eks nodes
$ kubectl get nodes
Note: We should be able to see EKS cluster nodes here.
- Stage-1 : Clone Git Repo
- Stage-2 : Maven Build
- Stage-3 : Create Docker Image
- Stage-4 : Push Docker Image to Registry
- Stage-5 : Deploy app in k8s eks cluster
pipeline {
agent any
tools{
maven "Maven-3.9.9"
}
stages {
stage('Clone Repo') {
steps {
git 'https://github.com/ashokitschool/maven-web-app.git'
}
}
stage('Maven Build') {
steps {
sh 'mvn clean package'
}
}
stage('Docker Image') {
steps {
sh 'docker build -t ashokit/mavenwebapp .'
}
}
stage('k8s deployment') {
steps {
sh 'kubectl apply -f k8s-deploy.yml'
}
}
}
}
- We should be able to access our application
URL : http://LBR/context-path/