In order to build the example Docker image, build the openliberty-postgres image, first:
$> cd liberty-postgres/ $> docker build -t openliberty-postgres:1 .
Then you can build the actual project:
$> mvn clean package $> docker build -t config-example:1 .
In order to run the application in a Docker container, it needs the database credentials at runtime. We need access to them locally, without storing them under VCS. We can create the file via command line:
$> cat << EOM > /tmp/bootstrap.properties config-example.db.username=postgres config-example.db.password=postgres EOM
In order to run the Docker containers locally, execute ./docker-run-local.sh.
As a prerequisite, you need to create a Docker network first:
docker network create --subnet=192.168.42.0/24 dkrnet
The Kubernetes deployments expects a secret that contains the database credentials. In order to avoid storing the credentials under VCS, we create the secret via command line:
$> kubectl create secret generic database-credentials --from-file=/tmp/bootstrap.properties
Once the secret database-credentials has been created, we can deploy our Kubernetes application via the definition under deployment/config-example.yaml.
Please be aware that a Postgres database is expected to be resolvable under the hostname config-example-db in the default Kubernetes namespace.
You can either deploy a Postgres database in the same namespace, or use a headless service to point to an external address.
In order to run the Prometheus example on Kubernetes, simply apply all files in the deployment/ directory to your cluster after you have created the database-credentials secret.
kubectl apply -f deployment/
This will create the services and deployments for the example-config application, example-config-db database, Prometheus and Grafana instances, and required RBAC roles.
Also have a look at this blog post on how to discover applications running on Kubernetes with Prometheus.