You should use environment variables in your application.properties
file for this:
spring.datasource.username=${SPRING_DATASOURCE_USERNAME}spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}
Or with a default value (for development):
spring.datasource.username=${SPRING_DATASOURCE_USERNAME:admin}spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:admin}
Then you can add a Kubernetes Secret to your namespace:
apiVersion: v1kind: Secretmetadata: name: mysecret namespace: mynamespacedata: SPRING_DATASOURCE_PASSWORD: YWRtaW4= SPRING_DATASOURCE_USERNAME: YWRtaW4=
And assign it to your Deployment:
apiVersion: apps/v1kind: Deploymentmetadata: name: mydeploymentspec: # omitted... containers: - name: mycontainer envFrom: - secretRef: name: mysecret - configMapRef: name: myconfigmap # omitted...
Another alternative would be to store the entire application.properties
file in your Secret or ConfigMap and mount it into your container as a file.
Both scenarios are explained in further detail here:https://developers.redhat.com/blog/2017/10/03/configuring-spring-boot-kubernetes-configmap