This application is built for Vault-Kubernetes sidecar container testing. It shows Vault secrets on a page. Here is the documentation we follow to configure Vault with Kubernetes and add test secrets.
Basically, this application prints a content of a file. We assume that the file holds a Vault secret received via Vault Agent sidecar container.
- Default secret data (database-config.txt) - http://localhost:8080/secret/
- Custom secret data (database-config.txt) - http://localhost:8080/secret/
- Example with custom secret data (database-config.txt) - http://localhost:8080/secret/database-config.txt
SECRETS_LOCATION=/tmp ./gradlew bootRun
./gradlew test
./gradlew bootBuildImage
We should get Successfully built image 'docker.io/library/vault-kubernetes-java:v1'
docker tag vault-kubernetes-java:v1 grenader/vault-kubernetes-java:v2
docker push grenader/vault-kubernetes-java:v2
docker container run --name vkj-test -dt --rm -e SECRETS_LOCATION=anything -p 8088:8080 grenader/vault-kubernetes-java:v2
docker logs vkj-test
k apply -f k8s/show-secret-app.yml
# Get External IP address:
SHOW_SECRET_SERVICE_IP=$(k get svc vkjservice -o jsonpath="{.status.loadBalancer.ingress[0].ip}")
# open a new browser to see the page
open http://$SHOW_SECRET_SERVICE_IP/secret
This page should show a formatted String with POSTGRES connection URL.
k apply -f k8s/get-env-var-app.yml
SHOW_ENV_SERVICE_IP=$(k get svc springboot-service -o jsonpath="{.status.loadBalancer.ingress[0].ip}")
open http://$SHOW_ENV_SERVICE_IP/actuator/env/POSTGRESS_CONNECTION
This page shows POSTGRESS_CONNECTION environment variable loaded into the SpringBoot app