Struts is a classic web framework for Java, and if your app needs object storage—whether it’s handling file uploads, logs, or media—MinIO is a fantastic, self‑hosted choice. In this guide, we’ll walk through setting up MinIO in a Struts app using Docker for development and Kubernetes for production. We'll also cover how to keep your setup clean by using separate config files and dependencies for each environment.
1. Add Dependencies in pom.xml
In your
pom.xml
, add:
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts.version}</version>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.5.3</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>${fabric8.version}</version>
</dependency>
</dependencies>
This setup gives you Struts for your web layer, MinIO support through its SDK, and optional Kubernetes integration for your production environment.
2. Run MinIO Locally via Docker
Create a
docker-compose.yml
for easy local development:
version: '3.7'
services:
minio:
image: minio/minio
ports:
- "9000:9000"
- "9001:9001"
environment:
MINIO_ROOT_USER: devuser
MINIO_ROOT_PASSWORD: devpass123
volumes:
- minio-data:/data
command: server /data --console-address ':9001'
volumes:
minio-data:
Run it:
docker-compose up -d
Your MinIO console will be accessible at
http://localhost:9001
, with access via
http://localhost:9000
using credentials
devuser/devpass123
.
3. Configure Development in minio-dev.properties
Add a new file
minio-dev.properties
to your classpath:
minio.endpoint=http://localhost:9000
minio.accessKey=devuser
minio.secretKey=devpass123
minio.bucket=dev-bucket
Use a utility class or your Struts action to load these properties:
Properties props = new Properties();
props.load(getClass().getResourceAsStream("/minio-dev.properties"));
MinioClient client = MinioClient.builder()
.endpoint(props.getProperty("minio.endpoint"))
.credentials(
props.getProperty("minio.accessKey"),
props.getProperty("minio.secretKey"))
.build();
// Use the client for bucket or object operations
You can create buckets or upload/download files as needed in your code.
4. Prepare Kubernetes Secrets and ConfigMaps for Production
To securely manage credentials and configuration in production, run:
kubectl create secret generic minio-secret \
--from-literal=MINIO_ACCESS_KEY=produser \
--from-literal=MINIO_SECRET_KEY=prodsecret
kubectl create configmap minio-config \
--from-literal=MINIO_ENDPOINT=http://minio-service:9000 \
--from-literal=MINIO_BUCKET=prod-bucket
These handle your endpoint and credentials securely in Kubernetes.
5. Configure Production in minio-prod.properties
Create
minio-prod.properties
:
minio.endpoint=${MINIO_ENDPOINT}
minio.accessKey=${MINIO_ACCESS_KEY}
minio.secretKey=${MINIO_SECRET_KEY}
minio.bucket=${MINIO_BUCKET}
Your app will parse these just like dev properties, but now they’ll use environment variables set in Kubernetes.
6. Kubernetes Deployment Snippet
Add the following environment variables to your Pod spec:
env:
- name: MINIO_ENDPOINT
valueFrom:
configMapKeyRef:
name: minio-config
key: MINIO_ENDPOINT
- name: MINIO_BUCKET
valueFrom:
configMapKeyRef:
name: minio-config
key: MINIO_BUCKET
- name: MINIO_ACCESS_KEY
valueFrom:
secretKeyRef:
name: minio-secret
key: MINIO_ACCESS_KEY
- name: MINIO_SECRET_KEY
valueFrom:
secretKeyRef:
name: minio-secret
key: MINIO_SECRET_KEY
Ensure both
minio-dev.properties
and
minio-prod.properties
are in your app’s classpath. The production deployment will automatically read the
prod
file using environment values.
7. Why This Setup Works
- Easy local dev: Docker + simple properties = rapid iteration.
- Secure production: Kubernetes manages credentials and config cleanly.
- Minimal code changes: Same client logic works in both environments.
- Maintenance-friendly: Dev and prod settings are clearly separated.
By combining local Docker with Kubernetes-managed config, and using Struts alongside MinIO’s SDK, you get a scalable, secure, and maintainable setup. Whether you're handling uploads, storing logs, or managing media, this approach gives you clean environment separation and reliable storage across your Struts applications.
image quote pre code