This guide shows how to deploy a
Spring Boot application with
Apache Derby on
Kubernetes for scalable and containerized environments.
1. Prepare Spring Boot App with Derby
In
application.properties
:
spring.datasource.url=jdbc:derby:/app/data/derbyDB;create=true
spring.datasource.driver-class-name=org.apache.derby.jdbc.EmbeddedDriver
spring.jpa.hibernate.ddl-auto=update
Store Derby data in
/app/data
for persistence.
2. Create Dockerfile
FROM openjdk:17-jdk-slim
VOLUME /app/data
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Build and push the image:
mvn clean package -DskipTests
docker build -t your-dockerhub/springboot-derby .
docker push your-dockerhub/springboot-derby
3. Kubernetes Deployment
Create
deployment.yml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: springboot-derby
spec:
replicas: 1
selector:
matchLabels:
app: springboot-derby
template:
metadata:
labels:
app: springboot-derby
spec:
containers:
- name: springboot-derby
image: your-dockerhub/springboot-derby
ports:
- containerPort: 8080
volumeMounts:
- name: derby-storage
mountPath: /app/data
volumes:
- name: derby-storage
persistentVolumeClaim:
claimName: derby-pvc
4. Persistent Volume Claim
pvc.yml
:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: derby-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Apply PVC first:
kubectl apply -f pvc.yml
5. Expose Service
service.yml
:
apiVersion: v1
kind: Service
metadata:
name: springboot-derby-service
spec:
type: LoadBalancer
selector:
app: springboot-derby
ports:
- port: 80
targetPort: 8080
6. Deploy to Kubernetes
Apply all configs:
kubectl apply -f pvc.yml
kubectl apply -f deployment.yml
kubectl apply -f service.yml
Get external IP:
kubectl get svc springboot-derby-service
image quote pre code