Ubuntu 24.04 AMI t2.medium ALL TCP
sudo su - root sudo apt-get update sudo apt-get upgrade
sudo apt-get install default-jdk java -version
Install Jenkins on Ubuntu server using the Link Jenkins Access Jenkins Url with Public ip on port 8080 cat /var/lib/jenkins/secrets/initialAdminPassword Install the Suggested Plugins Setup UserName and Password
Create a Empty Github Repository switch to root dir mkdir DeveloperDir cd DeveloperDir/ vi main.py vi pod.yaml vi requirements.txt vi Dockerfile vi form.html
git init git add . git commit -m "First commit" git remote add origin https://github.com/Iam-mithran/SaturdayProject git push origin master Generate a access Classic token from the GitHub Repo Settings
Install Stageview plugin from manageJenkins -> Plugins -> Available plugins
pipeline { agent any stages { stage('Pull Code From GitHub') { steps { git 'https://github.com/Iam-mithran/SaturdayProject.git' } } } }
sudo apt install docker.io Open DockerHub account docker login
vi /etc/sudoers jenkins ALL=(ALL) NOPASSWD: ALL exit sudo su - root
pipeline { agent any
stages {
stage('Pull Code From GitHub') {
steps {
git 'https://github.com/Iam-mithran/SaturdayProject.git'
}
}
stage('Build the Docker image') {
steps {
sh 'sudo docker build -t weekendimage /var/lib/jenkins/workspace/weekendproj'
sh 'sudo docker tag weekendimage iammithran/weekendimage:latest'
sh 'sudo docker tag weekendimage iammithran/weekendimage:${BUILD_NUMBER}'
}
}
stage('Push the Docker image') {
steps {
sh 'sudo docker image push iammithran/weekendimage:latest'
sh 'sudo docker image push iammithran/weekendimage:${BUILD_NUMBER}'
}
}
}
}
curl -Lo kops https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64 chmod +x ./kops sudo mv ./kops /usr/local/bin/
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" sudo apt install unzip unzip awscliv2.zip sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update Create IAM user with Admin access policy and generate IAM access & Secret Key aws configure aws s3 ls
ssh-keygen
export AWS_ACCESS_KEY_ID= export AWS_SECRET_ACCESS_KEY= export NAME=mithran.k8s.local export KOPS_STATE_STORE=s3://kops22042022
kops create cluster --zones ap-south-1a ${NAME} kops update cluster --name mithran.k8s.local --yes --admin
pipeline { agent any
stages {
stage('Pull Code From GitHub') {
steps {
git 'https://github.com/Iam-mithran/SaturdayProject.git'
}
}
stage('Build the Docker image') {
steps {
sh 'sudo docker build -t weekendimage /var/lib/jenkins/workspace/weekendproj'
sh 'sudo docker tag weekendimage iammithran/weekendimage:latest'
sh 'sudo docker tag weekendimage iammithran/weekendimage:${BUILD_NUMBER}'
}
}
stage('Push the Docker image') {
steps {
sh 'sudo docker image push iammithran/weekendimage:latest'
sh 'sudo docker image push iammithran/weekendimage:${BUILD_NUMBER}'
}
}
stage('Deploy on Kubernetes') {
steps {
sh 'sudo kubectl apply -f /var/lib/jenkins/workspace/weekendproj/pod.yaml'
sh 'sudo kubectl rollout restart deployment loadbalancer-pod'
}
}
}
}
Github Repo Setting -> Webhooks -> http://43.205.203.11:8080/github-webhook/ Jenkins Job -> Build Triggers -> GitHub hook trigger for GITScm polling
make changes in the pod.yaml for correct image name git -am commit "Test Run" git push origin master Check Deployment in Kubernetes