|
1 | 1 | # DockerPoc-1 |
2 | 2 |
|
3 | | -A Spring Boot application demonstrating Docker, Kubernetes, and CI/CD best practices with GitHub Actions. |
4 | | - |
5 | | -## 🚀 Overview |
6 | | - |
7 | | -This project is a Spring Boot application that showcases: |
8 | | -- Docker containerization |
9 | | -- Kubernetes deployment |
10 | | -- CI/CD with GitHub Actions |
11 | | -- Remote debugging capabilities |
12 | | -- Database integration (PostgreSQL) |
13 | | -- API documentation with OpenAPI/Swagger |
14 | | -- Monitoring with Spring Boot Actuator |
15 | | - |
16 | | -## 🛠️ Tech Stack |
17 | | - |
18 | | -- Java 17 |
19 | | -- Spring Boot 3.4.5 |
20 | | -- PostgreSQL |
21 | | -- Docker |
22 | | -- Kubernetes |
23 | | -- GitHub Actions |
24 | | -- Maven |
25 | | -- Lombok |
26 | | -- Spring Data JPA |
27 | | -- SpringDoc OpenAPI |
28 | | -- Spring Boot Actuator |
29 | | - |
30 | | -## 📋 Prerequisites |
31 | | - |
32 | | -- JDK 17 |
33 | | -- Maven |
34 | | -- Docker |
35 | | -- Kubernetes cluster (for deployment) |
36 | | -- kubectl (for Kubernetes operations) |
37 | | -- PostgreSQL (for production) |
38 | | - |
39 | | -## 🏗️ Project Structure |
| 3 | +*A personal endeavor to learn and demonstrate various DevOps concepts: Docker, Kubernetes, Helm, and Terraform — all wrapped around a Spring Boot application.* |
40 | 4 |
|
41 | | -``` |
42 | | -. |
43 | | -├── src/ # Source code |
44 | | -├── K8s_Yaml/ # Kubernetes manifests |
45 | | -│ ├── App/ # Application deployments |
46 | | -│ ├── Config/ # ConfigMaps and Secrets |
47 | | -│ ├── Ingress/ # Ingress configurations |
48 | | -│ ├── Network/ # Network policies |
49 | | -│ ├── Probe/ # Health checks |
50 | | -│ ├── RBAC/ # Role-based access control |
51 | | -│ ├── Schedule/ # Scheduled jobs |
52 | | -│ ├── Storage/ # Persistent storage |
53 | | -│ └── kubevela/ # KubeVela configurations |
54 | | -├── nginx/ # Nginx configurations |
55 | | -├── .github/workflows/ # GitHub Actions workflows |
56 | | -├── Dockerfile # Docker build file |
57 | | -├── docker-compose.yml # Docker Compose configuration |
58 | | -└── pom.xml # Maven configuration |
59 | | -``` |
| 5 | +--- |
| 6 | + |
| 7 | +## ✨ Project Highlights |
| 8 | + |
| 9 | +* **Spring Boot Application:** A simple RESTful API built with Spring Boot, showcasing basic CRUD operations and exposing monitoring endpoints. |
| 10 | +* **Docker:** Containerization of the Spring Boot application for consistent environments. |
| 11 | +* **Kubernetes:** Deployment and management of the application on a Kubernetes cluster using various manifest types (Deployments, Services, etc.). |
| 12 | +* **Helm:** Packaging and deploying the application to Kubernetes using Helm charts for easier management and versioning. |
| 13 | +* **Terraform:** Infrastructure as Code (IaC) for provisioning and managing the necessary cloud resources (current state focuses on local configurations, but the structure is in place for cloud integration). |
| 14 | +* **CI/CD:** *(Implied/Expandable)* The project structure allows for the integration of CI/CD pipelines to automate builds, tests, and deployments. |
| 15 | + |
| 16 | +--- |
60 | 17 |
|
61 | 18 | ## 🚀 Getting Started |
62 | 19 |
|
63 | | -### Local Development |
| 20 | +### 🔧 Prerequisites |
64 | 21 |
|
65 | | -1. Clone the repository: |
66 | | - ```bash |
67 | | - git clone https://github.com/vishal210893/DockerPoc-1.git |
68 | | - cd DockerPoc-1 |
69 | | - ``` |
| 22 | +Ensure the following are installed before you begin: |
70 | 23 |
|
71 | | -2. Build the application: |
72 | | - ```bash |
73 | | - mvn clean package |
74 | | - ``` |
| 24 | +* JDK 17 |
| 25 | +* Maven |
| 26 | +* Docker |
| 27 | +* `kubectl` |
| 28 | +* Helm |
| 29 | +* Terraform |
| 30 | +* A running Kubernetes cluster (Minikube, Docker Desktop with Kubernetes enabled, or a cloud-based cluster) |
75 | 31 |
|
76 | | -3. Run with Docker Compose: |
77 | | - ```bash |
78 | | - docker-compose up |
79 | | - ``` |
| 32 | +### 📦 Cloning the Repository |
| 33 | + |
| 34 | +```bash |
| 35 | +git clone https://github.com/your-username/DockerPoc-1.git |
| 36 | +cd DockerPoc-1 |
| 37 | +``` |
| 38 | + |
| 39 | +### 🏗️ Building the Spring Boot Application |
| 40 | + |
| 41 | +```bash |
| 42 | +mvn clean package |
| 43 | +``` |
| 44 | + |
| 45 | +This will create an executable JAR file in the `target` directory. |
| 46 | + |
| 47 | +--- |
80 | 48 |
|
81 | | -### Remote Debugging |
| 49 | +## 🐳 Docker Deployment |
82 | 50 |
|
83 | | -The application supports remote debugging on port 5005. To enable debugging: |
| 51 | +1. **Build the Docker Image:** |
84 | 52 |
|
85 | | -1. Start the application with debug mode: |
86 | 53 | ```bash |
87 | | - java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar target/dockerpoc-1.jar |
| 54 | + docker build -t dockerpoc-1 . |
88 | 55 | ``` |
89 | 56 |
|
90 | | -2. Configure your IDE to connect to localhost:5005 |
| 57 | + This command builds a Docker image named `dockerpoc-1` using the `Dockerfile` in the root directory. |
91 | 58 |
|
92 | | -## 🐳 Docker |
| 59 | +2. **Run the Docker Container:** |
93 | 60 |
|
94 | | -### Building the Image |
95 | | - |
96 | | -```bash |
97 | | -docker build -t dockerpoc-1 . |
98 | | -``` |
| 61 | + ```bash |
| 62 | + docker run -p 8080:8080 dockerpoc-1 |
| 63 | + ``` |
99 | 64 |
|
100 | | -### Running the Container |
| 65 | + This runs the Docker container and maps port 8080 on your host to port 8080 in the container. |
101 | 66 |
|
102 | | -```bash |
103 | | -docker run -p 8005:8005 -p 5005:5005 dockerpoc-1 |
104 | | -``` |
| 67 | +--- |
105 | 68 |
|
106 | 69 | ## ☸️ Kubernetes Deployment |
107 | 70 |
|
108 | | -### Prerequisites |
109 | | - |
110 | | -- Kubernetes cluster |
111 | | -- kubectl configured |
112 | | -- Docker image pushed to registry |
| 71 | +Kubernetes manifests are located in the `K8s_Yaml` directory. |
113 | 72 |
|
114 | | -### Deployment Steps |
| 73 | +1. **Apply the Manifests:** |
115 | 74 |
|
116 | | -1. Apply Kubernetes configurations: |
117 | 75 | ```bash |
118 | 76 | kubectl apply -f K8s_Yaml/ |
119 | 77 | ``` |
120 | 78 |
|
121 | | -2. Verify deployment: |
| 79 | + This command applies all the Kubernetes configuration files in the `K8s_Yaml` directory to your connected Kubernetes cluster. |
| 80 | + |
| 81 | +2. **Verify the Deployment:** |
| 82 | + |
122 | 83 | ```bash |
123 | 84 | kubectl get pods |
124 | 85 | kubectl get services |
125 | 86 | ``` |
126 | 87 |
|
127 | | -## 🔄 CI/CD Pipeline |
| 88 | + Check the status of your pods and services to ensure the application is running correctly. |
128 | 89 |
|
129 | | -The project uses GitHub Actions for CI/CD. The workflow includes: |
| 90 | +--- |
130 | 91 |
|
131 | | -1. Build and test |
132 | | -2. Docker image creation |
133 | | -3. Push to container registry |
134 | | -4. Kubernetes deployment |
| 92 | +## 📈 Helm Chart Deployment |
135 | 93 |
|
136 | | -## 📊 Monitoring |
| 94 | +The Helm chart for this project is located in the `charts/Helm` directory. |
137 | 95 |
|
138 | | -The application includes Spring Boot Actuator endpoints for monitoring: |
| 96 | +1. **Add the Helm Repository (if hosted):** |
| 97 | + If you have hosted your Helm chart in a repository, you can add it using: |
139 | 98 |
|
140 | | -- Health check: `/actuator/health` |
141 | | -- Metrics: `/actuator/metrics` |
142 | | -- Info: `/actuator/info` |
| 99 | + ```bash |
| 100 | + helm repo add my-repo https://your-helm-repo-url |
| 101 | + helm repo update |
| 102 | + ``` |
143 | 103 |
|
144 | | -## 📚 API Documentation |
| 104 | +2. **Install the Helm Chart:** |
| 105 | + Navigate to the `charts/Helm` directory and install the chart: |
145 | 106 |
|
146 | | -OpenAPI/Swagger documentation is available at: |
147 | | -``` |
148 | | -http://localhost:8005/swagger-ui.html |
149 | | -``` |
| 107 | + ```bash |
| 108 | + cd charts/Helm |
| 109 | + helm install dockerpoc-release . |
| 110 | + ``` |
150 | 111 |
|
151 | | -## 🔐 Environment Variables |
| 112 | + This will deploy the application to your Kubernetes cluster using the configurations defined in the Helm chart. |
152 | 113 |
|
153 | | -Key environment variables: |
154 | | -- `SPRING_PROFILES_ACTIVE`: Application profile (default: prod) |
155 | | -- `DB_PASSWORD`: Database password |
156 | | -- `DEBUG_PORT`: Remote debugging port (default: 5005) |
| 114 | +3. **Uninstall the Helm Chart:** |
| 115 | + To remove the deployment created by Helm: |
157 | 116 |
|
158 | | -## 🛡️ Security |
| 117 | + ```bash |
| 118 | + helm uninstall dockerpoc-release |
| 119 | + ``` |
159 | 120 |
|
160 | | -- RBAC configurations in `K8s_Yaml/RBAC/` |
161 | | -- Network policies in `K8s_Yaml/Network/` |
162 | | -- Secure secret management |
| 121 | +--- |
163 | 122 |
|
164 | | -## 📝 Logging |
| 123 | +## 🏗️ Terraform Configuration |
165 | 124 |
|
166 | | -Logs are stored in the `logs/` directory and can be accessed through: |
167 | | -- Container logs |
168 | | -- Kubernetes pod logs |
169 | | -- Spring Boot Actuator endpoints |
| 125 | +Terraform files are located in the `Terraform` directory. While the current configuration might be minimal, the intention is to use Terraform for provisioning infrastructure. |
170 | 126 |
|
171 | | -## 🔧 Troubleshooting |
| 127 | +1. **Initialize Terraform:** |
172 | 128 |
|
173 | | -1. Check container logs: |
174 | 129 | ```bash |
175 | | - docker logs <container-id> |
| 130 | + cd Terraform |
| 131 | + terraform init |
176 | 132 | ``` |
177 | 133 |
|
178 | | -2. Check Kubernetes pod logs: |
| 134 | +2. **Review the Plan:** |
| 135 | + |
179 | 136 | ```bash |
180 | | - kubectl logs <pod-name> |
| 137 | + terraform plan |
181 | 138 | ``` |
182 | 139 |
|
183 | | -3. Verify Kubernetes resources: |
| 140 | + This command shows you the changes Terraform will make to your infrastructure. |
| 141 | + |
| 142 | +3. **Apply the Configuration:** |
| 143 | + |
184 | 144 | ```bash |
185 | | - kubectl get all |
| 145 | + terraform apply |
186 | 146 | ``` |
187 | 147 |
|
| 148 | + This command applies the Terraform configuration to provision the resources. |
| 149 | + |
| 150 | +--- |
| 151 | + |
| 152 | +## 🔍 Exploring the Application |
| 153 | + |
| 154 | +Once the application is deployed, you can typically access it through a Service (Kubernetes) or by port-forwarding to a pod. Refer to the specific deployment method's documentation for details. |
| 155 | + |
| 156 | +* **API Endpoints:** The Spring Boot application exposes various REST endpoints. |
| 157 | +* **Actuator Endpoints:** Monitoring information is available via Spring Boot Actuator (e.g., `/actuator/health`, `/actuator/metrics`). |
| 158 | +* **Swagger UI:** API documentation is available through Swagger UI (commonly `/swagger-ui.html`, depending on your configuration). |
| 159 | + |
| 160 | +--- |
| 161 | + |
| 162 | +## 📚 Learning and Exploration |
| 163 | + |
| 164 | +This project is designed as a learning tool. Feel free to explore the code and configurations to understand how the different technologies are integrated. Experiment with different deployment strategies, modify the application, and observe the impact on the deployment process. |
| 165 | + |
| 166 | +--- |
| 167 | + |
188 | 168 | ## 🤝 Contributing |
189 | 169 |
|
190 | | -1. Fork the repository |
191 | | -2. Create a feature branch |
192 | | -3. Commit your changes |
193 | | -4. Push to the branch |
194 | | -5. Create a Pull Request |
| 170 | +As this is a personal learning project, contributions are not actively sought, but you are welcome to fork the repository and use it for your own learning purposes. |
195 | 171 |
|
196 | | -## 📄 License |
| 172 | +--- |
197 | 173 |
|
198 | | -This project is licensed under the MIT License - see the LICENSE file for details. |
| 174 | +## 📄 License |
199 | 175 |
|
200 | | -## 👥 Authors |
| 176 | +This project is licensed under the **MIT License**. |
201 | 177 |
|
202 | | -- Vishal Kumar - [vishal210893](https://github.com/vishal210893) |
| 178 | +--- |
203 | 179 |
|
204 | 180 | ## 🙏 Acknowledgments |
205 | 181 |
|
206 | | -- Spring Boot team |
207 | | -- Docker community |
208 | | -- Kubernetes community |
209 | | - |
210 | | -``` helm |
211 | | -helm repo add vishal210893 https://vishal210893.github.io/DockerPoc-1/ |
212 | | -helm repo update vishal210893 |
213 | | -helm install dockerpoc-chart vishal210893/dockerpoc-chart --atomic |
214 | | -helm uninstall dockerpoc-chart |
215 | | -kc port-forward svc/ingress-nginx-controller 8080:80 -n ingress-nginx |
216 | | -http://localhost:8080/ingress/dockerpoc/swagger-ui/index.html |
217 | | -``` |
| 182 | +Thanks to the open-source communities of Spring Boot, Docker, Kubernetes, Helm, and Terraform for providing these incredible tools. |
0 commit comments