How To Deploy Sample java-springboot Application To AWS Elastic Kubernetes Service (EKS cluster) With RazorOps CICD

Created by Shiva G, Modified on Thu, 27 Apr 2023 at 03:29 PM by Shyam Mohan K


Prerequisite :

 

  • An existing Razorops account

  • Creating clusters on cloud AWS


Github Repository : https://github.com/Razorops-code/spring-boot.git 


You can follow the these steps for creating AWS-EKS cluster click here


After creating EKS cluster 

Setting Up Cluster Access

In order to utilize kubectl to access a cluster, it is necessary to create a Kubernetes configuration file (often referred to as a 'kubeconfig' file) for that particular cluster. The kubeconfig file, which is typically stored in the $HOME/.kube directory and named config by default, contains all the necessary information for accessing the cluster. Once the kubeconfig file has been properly set up, you can begin managing the cluster using kubectl. For Razorops, you can follow the steps to gain access to the cluster. Click here

Next sign in to razorops with working github account


Next move to kubernetes section and click on Add New 

Next you navigate to existing cluster 

At this point, you have the option to specify a name for the cluster and choose an authentication method

In this case, we can proceed with the Kubernetes ConfigFile. (which is generated by connect credentials )

This is what your configuration file appears to be


Just copy and past at authentication section and click on Create Cluster


Once you've completed the previous step, your cluster will be successfully added to the Kubernetes section in Razorops and should be displayed accordingly.



The process of adding the cluster is now complete. The next step is to move on to the workflow section and run a pipeline to deploy our application onto the Kubernetes EKS cluster.


Now your in workflow dashboard

Afterward, proceed to click on "pipeline" and you will be directed to the dashboard where you can add a new pipeline.

SELECT GITHUB


SELECT REPOSITORY

 

And confirm it 


After adding the .razororps.yaml file to the repository, a pipeline will be automatically triggered in the workflow based on the commit ID.


.razorops.yaml

tasks:

  build-job:

    steps:

    - checkout

    - commands:

      - |

        mvn clean package                  # build the package

        ls -a

        ls target

    - docker/build:

       image: razoropsrepocode/spring       # build the image with Dockerfile

       push: true                   # push image to docker hub repository Which is integrated  

       tags: ["latest-v2"]

        # kubernetes deployment

  deploy-kubernetes:

    when: branch == 'master' # only run if code is pushed to develop branch

    depends: [build-job]

    steps:

    - checkout

    - commands:

      - |

        kubectl create -f deployment.yml

        kubectl create -f service.yml

        kubectl get svc


Kubernetes deployment manifest files are a essential component for running applications in containers. In this case, we utilize the deployment.yml file to deploy a Sample Java Spring Boot application.

deployment.yml

apiVersion: apps/v1

kind: Deployment

metadata:

   name: sample-java-app

spec:

   replicas: 1

   selector:

     matchLabels:

       app: java-app

   template:

     metadata:

       labels:

         app: java-app

    spec:

       containers:

       - name: java-app

         image: razoropsrepocode/spring:latest-v2

         imagePullPolicy: Always

         ports:

         - containerPort: 8080


Service.yaml is a Kubernetes manifest file that describes a Kubernetes Service resource. The Service resource provides a stable, network endpoint for accessing a set of pods that provide the same functionality.

Service.yml


apiVersion: v1

kind: Service

metadata:

   name: sample-java-app

spec:

   type: NodePort

   ports:

   - port: 8080

     targetPort: 8080

   selector:

     app: java-app



The following steps will be executed automatically in sequence:

  1. Cloning the source code from the repository.
  2. Building the code using Maven.

  3. Creating an image using the Dockerfile.

  4. Pushing the image to the DockerHub repository.

  5. Pulling the image from the DockerHub repository.

  6. Deploying the container on the EKS cluster using the Kubernetes manifest files - deployment.yml and service.yml.

  7. Accessing the application using the NodePort IP service.


After pipeline running succeeded 

We can find logs in logs section 

    The Sample-java-app pod is up and running successfully, and it can be accessed through the NodePort service on port 31103. You can find it using the <node-external-ip>:31103 address.

In my case i.e  3.109.54.147:31103/spring3/

Note:- This application working on tomcat server we need to mention application name i.e spring3

   

Conclusion:

        

        integrating an EKS cluster with RazorOps CICD allows for efficient and automated deployment of code changes to the Kubernetes cluster. With RazorOps, you can easily create pipelines that automatically build, test, and deploy your applications to the EKS cluster, streamlining the development process and ensuring consistency and reliability in the deployment process. This integration enables organizations to focus on developing their applications and delivering new features quickly, while RazorOps takes care of the deployment and management of the underlying infrastructure.



If you require assistance with this guide, please feel free to ask for help by booking a ticket here.




Visit and Signup - https://razorops.com/








Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article