Build a Microservice Architecture with Spring Boot and Kubernetes

Build a Microservice Architecture with Spring Boot and Kubernetes

This tutorial shows you how to use Kubernetes to deploy a Spring Boot microservice architecture to Google Cloud and Google Kubernetes Engine (GKE).

James Harry

such a useful article for me thanks for providing

Tilak Sharma

Hi,
Thanks for this excellent step-by-step tutorial. It’s awesome!

After the step,
docker push gcr.io/$PROJECT_NAME/kayak-…
I’m unable to get the kayak-service pod running.
It fails because of the error: Error: Unable to access jarfile springbootkbe-0.1.0-SNAPSHOT.jar

This is because the DockerFile had it like this:
ENV APP_FILE springbootkbe-0.1.0-SNAPSHOT.jar

I see that the actual file name is 0.0.1 and not 0.1.0.
So I modified the DockerFile accordingly, rebuild the docker image, pushed it again, but somehow the GKE still takes the old configuration of the DockerFile and still doesn’t start the Pod.

Please help.

Jialin Liu

After modifying the Dockerfile,
docker build -t kayak-app:1.0 .
docker tag kayak-app:1.0 gcr.io/projectname/kayak-ap…
docker push gcr.io/projectname/kayak-ap…
then modify the image name in kayak-service’s deployment.yml file:
image: gcr.io/projectname/kayak-ap…

before deploy, you can remove all service/deployment of kayak-service by:
kubectl delete deploy/kayak-service service/kayak-service
then deploy it:
kubectl apply -f deployment.yml

Shanika Wijerathna

Hi Andrew, what would you recommend to use to get the access token in a real world app on kubernetes? implicit flow? I tried to use explicit flow but Spring security rely on http session which is not going to work when we have multiple replicas of the app (OAuth2 client) on kubernetes.

Greg

I wish I would have read the comments before I wasted an hour troubleshooting this. :slight_smile:
But yeah, I just updated the Dockerfile, built/tagged the image, pushed it to the registry, deleted the old deployment, and created a new one with the same deployment.yml file as before.

Matt Raible

You could setup your Spring Boot app as a resource server and then it would be stateless. Another option is to use Spring Session and back it with Redis so you can distribute the session across your cluster.

Matt Raible

Sorry for messing that up. I’ve updated the version number in the post to be 0.0.1. Thank you for letting us know!

AK

Everything seemed to work up until the last point. However, failed at the last step :frowning:
http $INGRESS_HOST:$INGRESS_PORT/kayaks
HTTP/1.1 200 OK
content-type: application/json;charset=UTF-8
date: Wed, 22 Apr 2020 19:49:44 GMT
server: istio-envoy
transfer-encoding: chunked
x-envoy-upstream-service-time: 6

Any ideas?

Matt Raible

AK - can you try comparing your code with the example code on GitHub? It’s possible you’re using newer versions and things have changed since this tutorial was published.