This is a sample application that uses a PostgreSQL database and consumes the DB configuration via a Kubernetes ConfigMap and Secret.
This allows the configuration to be changed easily based on environment the application is deployed in.
For example, the ConfigMap and Secret when using an AWS RDS instance are as follows
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
kasten.io/config: dataservice
name: dbconfig
data:
dataservice.type: postgres
postgres.manager: awsrds
postgres.host: dbendpoint.adsadasa.us-west-2.rds.amazonaws.com
postgres.databases: mypgsqldb
postgres.user: postgres
postgres.secret: dbcreds # name of K8s secret in the same namespace
---
apiVersion: v1
kind: Secret
metadata:
name: dbcreds
type: Opaque
data:
password: <BASE64 encoded password>make clean
make container
make push# Set namespace to deploy into
export NAMESPACE=pgtestrds
kubectl create namespace ${NAMESPACE}
kubectl apply -f deploy/. --namespace ${NAMESPACE}Use kubectl proxy to connect to the service in the cluster
kubectl proxy&
http://127.0.0.1:8001/api/v1/namespaces/pgtestrds/services/pgtestapp:8080/proxy/http://127.0.0.1:8001/api/v1/namespaces/pgtestrds/services/pgtestapp:8080/proxy/counthttp://127.0.0.1:8001/api/v1/namespaces/pgtestrds/services/pgtestapp:8080/proxy/insert