To run this example on Kubernetes, you can use any Kubernetes distribution.
We install Dapr on a Kubernetes cluster and then we will deploy both the producer-app
and consumer-app
.
If you don't have any Kubernetes cluster you can use Kubernetes KIND to create a local cluster. We will create a cluster with a local container registry, so we can push our container images to it. This is covered in the KIND documentation here.
./kind-with-registry.sh
Once you have the cluster up and running you can install Dapr:
helm repo add dapr https://dapr.github.io/helm-charts/
helm repo update
helm upgrade --install dapr dapr/dapr \
--version=1.14.4 \
--namespace dapr-system \
--create-namespace \
--wait
Now that we have our cluster set up with a local container registry, we need to build our producer-app
and consumer-app
containers.
For this we will use Spring Boot build it functions to create container images using Buildpacks:
From inside the spring-boot-examples/producer-app
directory you can run the following command to create a container:
mvn spring-boot:build-image
Once we have the container image created, we need to tag and push to the local registry, so the image can be used from our local cluster. Alternatively, you can push the images to a public registry and update the Kubernetes manifests accordingly.
docker tag producer-app:0.14.0-SNAPSHOT localhost:5001/sb-producer-app
docker push localhost:5001/sb-producer-app
From inside the spring-boot-examples/consumer-app
directory you can run the following command to create a container:
mvn spring-boot:build-image
Once we have the container image created, we need to tag and push to the local registry, so the image can be used from our local cluster. Alternatively, you can push the images to a public registry and update the Kubernetes manifests accordingly.
docker tag consumer-app:0.14.0-SNAPSHOT localhost:5001/sb-consumer-app
docker push localhost:5001/sb-consumer-app
Now we are ready to install our application into the cluster.
Now that we have a running Kubernetes cluster, we need to first install the components needed by the application. In this case RabbitMQ and PostgreSQL. We will use Helm to do so:
Let's start with RabbitMQ:
helm install rabbitmq oci://registry-1.docker.io/bitnamicharts/rabbitmq --set auth.username=guest --set auth.password=guest --set auth.erlangCookie=ABC
Then PostgreSQL:
helm install postgresql oci://registry-1.docker.io/bitnamicharts/postgresql --set global.postgresql.auth.database=dapr --set global.postgresql.auth.postgresPassword=password
Once we have these components up and running we can install the application by running from inside
the spring-boot-examples/kubernetes/
directory:
kubectl apply -f .
Next you need to use kubectl port-forward
to be able to send requests to the applications.
kubectl port-forward svc/producer-app 8080:8080
In a different terminals you can check the logs of the producer-app
and consumer-app
:
kubectl logs -f producer-app-<POD_ID>
and
kubectl logs -f consumer-app-<POD_ID>