Setup EKS Cluster using eksctl and Deploy Springboot Microservices into EKS using Jenkins Pipeline
Deploy Springboot Microservices App into Amazon EKS Cluster using Jenkins Pipeline and Kubectl CLI Plug-in | Containerize Springboot App and Deploy into EKS Cluster using Jenkins Pipeline
We will learn how to automate springboot microservices builds using Jenkins pipeline and Deploy into AWS EKS Cluster with help of Kubernetes CLI plug-in.
We will use Springboot Microservices based Java application. I have already created a repo with source code + Dockerfile. The repo also have Jenkinsfile for automating the following:
- Automating builds using Jenkins
- Automating Docker image creation
- Automating Docker image upload into AWS ECR
- Automating Docker Containers Deployments to Kubernetes Cluster
- Automating Docker image creation
- Automating Docker image upload into AWS ECR
- Automating Docker Containers Deployments to Kubernetes Cluster
Source Code for this project is here:
Make sure you fork my repo https://github.com/imHarry404/springboot-app.git
Pre-requisites:
1. Amazon EKS Cluster is setup and running. Click here to learn how to create Amazon EKS cluster.
1. Amazon EKS Cluster is setup and running. Click here to learn how to create Amazon EKS cluster.
5. Docker, Docker pipeline and Kubernetes CLI plug-ins are installed in Jenkins
Step # 1 - Create Maven3 variable under Global tool configuration in Jenkins
Make sure you create Maven3 variable under Global tool configuration.
Step #2 - Create Credentials for connecting to Kubernetes Cluster using kubeconfig
Click on Add Credentials, use Kubernetes configuration from drop down.
use secret file from drop down.
execute the below command to login as jenkins user.
sudo su - jenkins
you should see the nodes running in EKS cluster.
kubectl get nodes
cat /var/lib/jenkins/.kube/config
Step # 3 - Create a pipeline in Jenkins
Step # 4 - Copy the pipeline code from below
Make sure you change red highlighted values below as per your settings:
Your docker user id should be updated.
your registry credentials ID from Jenkins from step # 1 should be copied
Make sure you change red highlighted values below as per your settings:
Your docker user id should be updated.
your registry credentials ID from Jenkins from step # 1 should be copied
pipeline {
agent any
tools {
maven "Maven3"
}
environment {
repository = "456137991393.dkr.ecr.ap-south-1.amazonaws.com/harry"
}
stages {
stage('Git Checkout') {
steps {
script {
// Check out code from the specified Git repository
git branch: 'main', url: 'https://github.com/imHarry404/springboot-app.git'
}
}
}
stage('Build Jar') {
steps {
script {
sh "mvn clean install"
}
}
}
stage('Build Docker Image') {
steps {
script {
docker.build repository
}
}
}
stage('Push into ECR') {
steps {
script {
sh "aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 456137991393.dkr.ecr.ap-south-1.amazonaws.com"
sh "docker push 456137991393.dkr.ecr.ap-south-1.amazonaws.com/harry:latest"
}
}
}
stage('Deploy to k8s') {
steps {
script {
withKubeConfig(caCertificate: '', clusterName: '', contextName: '', credentialsId: 'k8s', namespace: '', restrictKubeConfigAccess: false, serverUrl: '') {
sh "kubectl apply -f eks-deploy-from-ecr.yaml"
}
}
}
}
}
}
Step # 5 - Build the pipeline
Once you create the pipeline and changes values per your configuration, click on Build now:
Step # 6 - Verify deployments to K8S
kubectl get pods
kubectl get deployments
kubectl logs <pod_name>
Steps # 7 - Access SpringBoot App in K8S cluster
Once build is successful, go to browser and enter master or worker node public ip address along with port number mentioned above
http://loadbalancer_ip_address
You should see page like below:
Note:
Make sure you fork my repo my-git-repo
and make changes in eks-deploy-k8s.yaml to pull Docker image from your AWS ECR repo.
Connect with me 😊
Labels: aws aws cli linux devops, git cheatsheet commands devops developer, jenkins kubernetes eks, kubernetes aks devops
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home