This repository contains the deployment files and instructions for deploying a Java application as a container in Kubernetes using Jenkins, GitHub, Docker, and Kubernetes.
- Overview
- Prerequisites
- Project Structure
- Deployment Steps
- Configuration
- Accessing the Application
- Cleaning Up
This project demonstrates the deployment of a Java application as a container in Kubernetes using a CI/CD pipeline with Jenkins, GitHub for version control, Docker for containerization, and Kubernetes for orchestration.
Before you begin, ensure you have the following prerequisites:
- Jenkins CI/CD pipeline configured with appropriate plugins and credentials.
- Docker installed on the Jenkins server or build machine.
- GitHub repository for your Java application code.
- Kubernetes cluster configured and accessible from Jenkins.
The project structure is as follows:
java-containerized-app/
├── Dockerfile
├── src/
│ ├── main ----
│ └── java - file ----
└── README.md
├── deploymentservice.yaml
├── kubernetes-cd.hpi
├── mvnw
├── mvnw.cmd
└── pom.xml
Dockerfile
: Contains instructions to build the Docker image for the Java application.deploymentservice.yaml
: To create Deployement and Services in Kubernetes.pom.xml
: java dependenices to run this applicationJenkins file/
: To create a pipeline for each stages.README.md
: Instructions and documentation (you're reading it now).
-
Clone this repository to your Jenkins workspace or build machine:
git clone https://github.com/your/repository.git
-
Configure Jenkins pipeline to build the Docker image using the provided Dockerfile.
-
Push the Docker image to a Docker registry (e.g., Docker Hub, AWS ECR).
-
Update Kubernetes deployment and service files (
deployment.yaml
,service.yaml
) with your Docker image details. -
Configure Jenkins to apply the Kubernetes deployment and service using kubectl commands.
- Set up a Jenkins pipeline with stages for building the Docker image, pushing to the registry, and deploying to Kubernetes.
- Use Jenkins environment variables or credentials to store sensitive information such as Docker registry credentials.
- Update
deployment.yaml
with your Docker image repository and tag. - Define Kubernetes resources such as CPU, memory limits, environment variables, etc., in the deployment file.
- Modify
service.yaml
for exposing the application via a Kubernetes service.
After successful deployment, access the Java application using the provided service URL or external IP exposed by Kubernetes.
To clean up resources:
-
Delete the Kubernetes deployment and service:
kubectl delete -f kubernetes/deployment.yaml kubectl delete -f kubernetes/service.yaml
-
Remove the Docker image from the registry if no longer needed.