Skip to content

Commit

Permalink
#284 Add documentation on k8s local cluster deployment & run (#287)
Browse files Browse the repository at this point in the history
* #284 Add documentation on k8s local cluster deployment & run

* #284 Update README.md with screen shots

* #284 Update README.md

* Update README.md

* Update build.gradle
  • Loading branch information
conorheffron authored Nov 29, 2024
1 parent e9e18cf commit c3f7617
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 4 deletions.
59 changes: 56 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
[ironoc-db docker hub](https://hub.docker.com/repository/docker/conorheffron/ironoc-db/general)

## Summary
This project is a sample data manager. It provides a basic template for Java/Spring developers. This project also includes form validation of controller model objects and request parameters.
This project is a sample data manager. It provides a basic template for Java/Spring developers.
This project also includes form validation of controller model objects and request parameters.
Users can view, add, delete person objects from the database via web UI.

## Technologies Used
Java 21 (LTS Version), Spring Boot 3, Hibernate, MySQL or H2 databases supported, JSP, Gradle 8.10
Java 21 (LTS Version), Spring Boot 3, Hibernate, MySQL or H2 databases supported, JSP, Gradle 8.10,
GKE, Docker, minikube, & kubectl.

## Run
### - See db.StarterDb.sql for sample Schema to get started with ironoc-db
Expand Down Expand Up @@ -54,12 +56,14 @@ docker inspect network my-network
gradle clean build
```

## Run 'com.ironoc.db.App.java' directly from IntelliJ (can use localhost for spring.datasource.url) or via CLI (build & spin up docker image, use docker network IP address for test-mysql process):
## Run 'com.ironoc.db.App.java' directly from IntelliJ (can use localhost for spring.datasource.url) or
## via CLI (build & spin up docker image, use docker network IP address for test-mysql process):
```
docker image build -t ironoc-db .
docker compose up -d
docker logs ironoc-db-web-1 -f
```

### Run locally with Gradle & H2 database
```
gradle bootRun --args='--spring.profiles.active=h2'
Expand All @@ -78,6 +82,55 @@ docker stop test-mysql
docker remove test-mysql
```

## Run ironoc-db on local k8s cluster
```
minikube start --driver=docker
kubectl cluster-info
minikube dashboard
```
- Then change namespace in browser after creation of 'ironoc-db' namespace.

![minikube-dash](./screenshots/minikube-dash.png?raw=true "Minikube Dashboard")
```
docker images
docker image build -t ironoc-db .
minikube image load ironoc-db:latest
kubectl create ns ironoc-db-ns
kubectl get ns
kubectl apply -f ./kubernetes/ironoc-db-local.yml --namespace=ironoc-db-ns
kubectl get pods --namespace=ironoc-db-ns
kubectl get deployment --namespace=ironoc-db-ns
```
![minikube-dash-deployments](./screenshots/minikube-dash-deployments.png?raw=true "ironoc-db kube Deployment")
```
kubectl expose deployment ironoc-db-app-deployment --type=NodePort --namespace=ironoc-db-ns
kubectl get services --namespace=ironoc-db-ns
minikube service ironoc-db-app-deployment --url --namespace=ironoc-db-ns
```
- Open a new terminal tab & follow the logs
```
% kubectl get pods --namespace=ironoc-db-ns
NAME READY STATUS RESTARTS AGE
ironoc-db-app-deployment-6c566784bc-q29xs 1/1 Running 0 2m40s
% kubectl logs ironoc-db-app-deployment-6c566784bc-q29xs -f --namespace=ironoc-db-ns
```

![minikube-dash-logs](./screenshots/minikube-dash-logs.png?raw=true "ironoc-db kube logs viewer")

![deployment](./screenshots/deployment.png?raw=true "ironoc-db local k8s Deployment")

```
minikube delete
```

## Alternatively, Docker Desktop is good if you prefer to not use the terminal/command line (CLI)
![docker-desktop-containers](./screenshots/docker-desktop-containers.png?raw=true "Docker Desktop containers")

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ apply plugin: 'war'
apply plugin: 'maven-publish'

group = 'conorheffron'
version = '5.3.7'
version = '5.3.8'
description = "Sample Data Manager"

sourceCompatibility = 21
Expand Down
207 changes: 207 additions & 0 deletions kubernetes/ironoc-db-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: ironoc-db-app-deployment
managedFields:
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
'f:spec':
'f:replicas': {}
manager: vpa-recommender
operation: Update
subresource: scale
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
'f:metadata':
'f:labels':
.: {}
'f:app': {}
'f:spec':
'f:progressDeadlineSeconds': {}
'f:revisionHistoryLimit': {}
'f:selector': {}
'f:strategy':
'f:rollingUpdate':
.: {}
'f:maxSurge': {}
'f:maxUnavailable': {}
'f:type': {}
'f:template':
'f:metadata':
'f:labels':
.: {}
'f:app': {}
'f:spec':
'f:containers':
'k:{"name":"ironoc-db-app-sha256-1"}':
.: {}
'f:image': {}
'f:imagePullPolicy': {}
'f:name': {}
'f:resources': {}
'f:terminationMessagePath': {}
'f:terminationMessagePolicy': {}
'f:dnsPolicy': {}
'f:restartPolicy': {}
'f:schedulerName': {}
'f:securityContext': {}
'f:terminationGracePeriodSeconds': {}
manager: unknown
operation: Update
time: '2024-10-15T11:53:53Z'
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
'f:metadata':
'f:annotations':
'f:deployment.kubernetes.io/revision': {}
'f:status':
'f:availableReplicas': {}
'f:conditions':
.: {}
'k:{"type":"Available"}':
.: {}
'f:lastTransitionTime': {}
'f:lastUpdateTime': {}
'f:message': {}
'f:reason': {}
'f:status': {}
'f:type': {}
'k:{"type":"Progressing"}':
.: {}
'f:lastTransitionTime': {}
'f:lastUpdateTime': {}
'f:message': {}
'f:reason': {}
'f:status': {}
'f:type': {}
'f:observedGeneration': {}
'f:readyReplicas': {}
'f:replicas': {}
'f:unavailableReplicas': {}
'f:updatedReplicas': {}
manager: kube-controller-manager
operation: Update
subresource: status
time: '2024-10-15T12:04:58Z'
name: ironoc-db-app-deployment
namespace: ironoc-db-ns
spec:
replicas: 1
selector:
matchLabels:
app: ironoc-db-app-deployment
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: ironoc-db-app-deployment
spec:
containers:
- image: ironoc-db:latest
imagePullPolicy: Never
ports:
- containerPort: 8080
name: ironoc-db-app-sha256-1
resources:
limits:
ephemeral-storage: 1Gi
requests:
cpu: 500m
ephemeral-storage: 1Gi
memory: 2Gi
securityContext:
capabilities:
drop:
- NET_RAW
securityContext:
seccompProfile:
type: RuntimeDefault
tolerations:
- effect: NoSchedule
key: kubernetes.io/arch
operator: Equal
value: amd64
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
labels:
app: ironoc-db-app-deployment
managedFields:
- apiVersion: autoscaling/v2
fieldsType: FieldsV1
fieldsV1:
'f:metadata':
'f:labels':
.: {}
'f:app': {}
'f:spec':
'f:maxReplicas': {}
'f:metrics': {}
'f:minReplicas': {}
'f:scaleTargetRef':
'f:apiVersion': {}
'f:kind': {}
'f:name': {}
manager: unknown
operation: Update
time: '2024-10-15T11:53:54Z'
- apiVersion: autoscaling/v2
fieldsType: FieldsV1
fieldsV1:
'f:status':
'f:conditions':
.: {}
'k:{"type":"AbleToScale"}':
.: {}
'f:lastTransitionTime': {}
'f:message': {}
'f:reason': {}
'f:status': {}
'f:type': {}
'k:{"type":"ScalingActive"}':
.: {}
'f:lastTransitionTime': {}
'f:message': {}
'f:reason': {}
'f:status': {}
'f:type': {}
'k:{"type":"ScalingLimited"}':
.: {}
'f:lastTransitionTime': {}
'f:message': {}
'f:reason': {}
'f:status': {}
'f:type': {}
'f:currentMetrics': {}
'f:currentReplicas': {}
'f:desiredReplicas': {}
'f:lastScaleTime': {}
manager: vpa-recommender
operation: Update
subresource: status
time: '2024-10-15T12:03:57Z'
name: ironoc-db-app-deployment-hpa-kbij
namespace: ironoc-db-ns
spec:
maxReplicas: 1
metrics:
- resource:
name: cpu
target:
averageUtilization: 80
type: Utilization
type: Resource
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: ironoc-db-app-deployment
Binary file added screenshots/deployment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/minikube-dash-deployments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/minikube-dash-logs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/minikube-dash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c3f7617

Please sign in to comment.