This project contains a demo for running Liquibase
migration as an init container
in a Kubernetes environment
Before you're able to run this demo, you need the following already setup on your development environment
- Kubernetes: either one of the following
- kind
- minikube
- Docker Desktop with Kubernetes enabled on Mac or PC
- helm
- cURL
You can run your application in dev mode that enables live coding using:
./mvnw compile quarkus:dev
The following operations have been defined
-
GET http://localhost:8080/clients/:id
curl --location --request GET 'http://localhost:8080/clients/ce74d8f2-ef49-4f2a-b5cc-52ef30046d40'
-
GET http://localhost:8080/clients
curl --location --request GET 'http://localhost:8080/clients'
-
POST http://localhost:8080/clients
curl --location --request POST 'http://localhost:8080/clients' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "evil corp", "code": "EVIL", "contactPerson": "Tyrell Wellick" }'
-
GET http://localhost:8080/clients/:code/code
curl --location --request GET 'http://localhost:8080/clients/acme/code'
-
GET http://localhost:8080/clients/:clientCode/services
curl --location --request GET 'http://localhost:8080/clients/acme/services'
NOTE: Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
The following sections contain instructions on how to:
- Build a native docker image
- Install Postgres operator
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.container-image.build=true
This will result in a docker image with name ${quarkus.container-image.group}/${quarkus.container-image.name}:${version}
.
The following properties are defined in application.properties
quarkus.container-image.group=juliuskrah
quarkus.container-image.name=liquibase-kubernetes
The following commands will be issued to install the PostgreSQL Operator.
# add repo for postgres-operator
helm repo add postgres-operator-charts https://opensource.zalando.com/postgres-operator/charts/postgres-operator
# install the postgres-operator
helm install postgres-operator postgres-operator-charts/postgres-operator
# add repo for postgres-operator-ui
helm repo add postgres-operator-ui-charts https://opensource.zalando.com/postgres-operator/charts/postgres-operator-ui
# install the postgres-operator-ui
helm install postgres-operator-ui postgres-operator-ui-charts/postgres-operator-ui
We will start the PostgreSQL database cluster example-liquibase-cluster
kubectl apply -f k8s/data
Check all components are coming up
# check the deployed cluster
kubectl get postgresql
# check created database pods
kubectl get pods -l application=spilo -L spilo-role
# check created service resources
kubectl get svc -l application=spilo -L spilo-role
Now we're ready to start our application
kubectl apply -f k8s/app
Check all components are coming up
kubectl get pods -l 'app.kubernetes.io/name=liquibase-on-kubernetes'
You should see output similar to what is below
NAME READY STATUS RESTARTS AGE
liquibase-on-kubernetes-667678855d-qmwdj 0/1 Init:0/1 0 4s
Take note of the name of the pod and run the command to follow the logs of the liquibase migration
Replace <pod-name> with the pod name noted earlier
kubectl logs --follow pod/<pod-name> -c liquibase-migration
If all is good, you can port forward
kubectl port-forward services/liquibase-on-kubernetes 8080:80