Creating a Docker image

We’ll create a Dockerfile to package the Java application into a Docker image. The Dockerfile will copy the compiled Java class file into the image and specify the command to run the application.

FROM openjdk:11-jre-slim
WORKDIR /app
COPY Main.class .
CMD ["java", "Main"]

Java Application Deployment In Kubernetes With Jenkins CI/CD Pipeline

In modern software development, deploying applications to Kubernetes clusters has become a common practice due to their scalability and reliability. Automating this deployment process using continuous integration and continuous deployment (CI/CD) pipelines with Jenkins streamlines the development workflow and ensures consistent, reliable deployments. This article demonstrates deploying a sample Java application on a Kubernetes cluster using Minikube.

Similar Reads

1. Creating a sample Java application

We’ll start by creating a simple Java application. Compile the Java code using the javac command....

2. Creating a Docker image

We’ll create a Dockerfile to package the Java application into a Docker image. The Dockerfile will copy the compiled Java class file into the image and specify the command to run the application....

3. Defining Kubernetes Deployment YAML File

The deployment YAML file specifies the desired state of the application, including the number of replicas, container image, and other configurations....

4. Creating Jenkins Role YAML File (Optional)

If Jenkins needs permission to interact with Kubernetes resources, you can create a Kubernetes role YAML file to define the required permissions....

5. Creating a Service Account in Kubernetes

Start the minikube....

6. Generating Token using OpenSSl and setting it for the service account

This command generates a random 32-byte token encoded in base64. Copy the generated token as we need it in the next step....

7. Finding the URL and port of the Minikube cluster

The minikube dashboard –url command is used to retrieve the URL of the Kubernetes dashboard running on your Minikube cluster....

8. Configuring Jenkins

Install Jenkins LTS version for your Operating System and complete the on screen setup. On new browser tab visit http://localhost:8080/...

9. Creating Jenkins Pipeline

On Dashboard click on New Item. Enter the item name, example myapp, and select Pipeline Option....

Java application deployment in Kubernetes with Jenkins CI/CD pipeline – FAQ’s

How do I deploy an application in Kubernetes using Jenkins?...

Contact Us