- Replies:
- 0
- Words:
- 6597

application.properties
file. We’ll look at two environments: a local development setup and a production setup where MinIO settings are provided through a Kubernetes ConfigMap
.To use MinIO in your Spring Boot app, you'll typically need three pieces of information:
These credentials are needed to authenticate your application with MinIO and perform operations like uploading or downloading files.
When deploying to production (especially on Kubernetes), you don’t want to hard-code sensitive values in your .properties
file. Instead, it’s a best practice to inject them using environment variables, ideally from a Kubernetes ConfigMap
.
Create a ConfigMap
named minio-config
with the necessary values. Here’s an example:
apiVersion: v1
kind: ConfigMap
metadata:
name: minio-config
namespace: your-namespace
data:
urlMinIO: http://minio-service:9000
accesskey: prod-access-key
secretkey: prod-secret-key
In your Kubernetes Deployment YAML, inject the values into the container environment:
containers:
- name: spring-boot-app
image: your-app-image
env:
- name: MINIO_URL
valueFrom:
configMapKeyRef:
name: minio-config
key: urlMinIO
- name: MINIO_ACCESS_KEY
valueFrom:
configMapKeyRef:
name: minio-config
key: accesskey
- name: MINIO_SECRET_KEY
valueFrom:
configMapKeyRef:
name: minio-config
key: secretkey
These values will now be available as environment variables inside your Spring Boot app.
Now, back in your Spring Boot project, use environment variable placeholders in application.properties
like this:
minio.url=${MINIO_URL}
minio.accessKey=${MINIO_ACCESS_KEY}
minio.secretKey=${MINIO_SECRET_KEY}
Spring Boot will automatically resolve these using the environment variables set by Kubernetes.
To keep things clean and separate between dev and prod environments, use Spring Boot profiles.
Create:
application-dev.properties
minio.url=http://localhost:9000
minio.accessKey=minioadmin
minio.secretKey=minioadmin123
application-prod.properties
minio.url=${MINIO_URL}
minio.accessKey=${MINIO_ACCESS_KEY}
minio.secretKey=${MINIO_SECRET_KEY}
Then, when you run the app, just specify the profile:
SPRING_PROFILES_ACTIVE=prod
Spring Boot will load the correct config file based on the active profile.
image quote pre code