MicroServices Example (MessageService)
About
This project should show the the possibilities 'docker' and 'kubernetes' are capable of. It could be used as a skeleton for further projects. It will cover each step from building a 'Spring-Boot' application in kotlin to running the application in a docker-container. As well as running the MicroServices in a docker-compose. In the last step you can see how to run the services easily in a kubernetes cluster, without even generating kubernetes files - just by translating the docker-compose via 'kompose'.
Preparation
Checkout both services:
Install the following software:
Installation
Compile
gradle build
Build Docker Image
docker build -t timogruen.com/kubernetes/example/messageservice .
Run Docker Images
Make sure you are in the root directory of the project. You can use either one of those:
cd ./docker && docker-compose up -d
docker run timogruen.com/kubernetes/example/timeservice
docker run timogruen.com/kubernetes/example/messageservice
Access the services
To curl the services just use:
curl 127.0.0.1:9001/api/v1/message/{text}
curl 127.0.0.1:9000/api/v1/time
Note: This will work using docker, but not while using minikube
Run inside MiniKube
Make sure minikube is started and running properly. Since this can be rather handy, keep in mind, that this step could take some time.
minikube start
Docker has to push his images to the minikube instance - to add them into path, use the following:
eval $(minikube docker-env)
docker build -t timogruen.com/kubernetes/example/messageservice:1.0.0 .
Note: that you publish the TimeService as well!
Access the services
To connect to the VM running minikube use:
minikube ssh
Now you are able to access the services using:
curl 127.0.0.1:9001/api/v1/message/{text}
while true; do curl 127.0.0.1:32209/api/v1/message/test; sleep 1; done
Scale your services
To scale your service use:
kubectl scale deployment --replicas=<AMOUNT> <DEPLOYMENT>
To scale the timeservice to 2 replicas, just use:
kubectl scale deployment --replicas=2 timeservice
Stop Minikube
Since minikube mimics a complete kubernetes cluster, make sure to stop minikube, once you are finished.
minikube stop