By Animesh Singh and Erin Schnabel Microservices! Java! Yes, we know, you’ve heard both terms, and hopefully you also know these two terms go together very well: there are excellent frameworks in place to support building epic microservices in Java. Microservices are containerized in one way or another, and there’s some movement in the Java ecosystem around how those containers are built. You can pack everything into one “uber-jar” that you shove into a more generic Java container, or you can deploy a thinner WAR file into a more tailored image. The end goal for either approach is similar — a lightweight container with simple configuration that boots quickly using only essential components. Some frameworks that are becoming popular in this space include MicroProfile and Spring Boot. We talked about MicroProfile in a previous post. In this post, we’re focusing on Spring Boot. We just released a new developer pattern, Deploy Spring Boot microservices on Kubernetes, that shows off the power and convenience of Spring Boot. This framework takes an opinionated view of building Spring applications and is focused on getting you up and running as quickly as possible. You get the rapid deployment benefits of Spring Boot and the capabilities of the Spring framework, and you can then rely on services provided by the infrastructure for consistent behavior of key functions in a microservice architecture, even if other services aren’t written in Java. When you combine the convention-first approach with containers and container orchestrator systems like Kubernetes, you multiply your benefits. You not only get the microservices features from Spring Boot, but you can also rely on Kubernetes features like service routing, load balancing, scaling, and so on. In this developer pattern, you’ll learn how to deploy a sample Java microservices application based on Spring Boot on a Kubernetes cluster. We’re relying on Kubernetes to provide typical cloud capabilities: service discovery, load balancing, and cloud-managed configuration through Kubernetes ConfigMaps. To summarize:
  • Spring Boot manages the build of the microservices (jar/war) and the dependency injection (DI) context at runtime.
  • Docker manages the packaging of microservice in a container and initializing the application’s phase-specific variables through OS/cluster-level environment variables.
  • Kubernetes manages the actual network layout and provides the service discovery, load-balancing, and scaling.
Additionally, you’ll see a demonstration of how serverless functions from OpenWhisk can be called from within Spring Boot microservices. The pattern is also integrated with Bluemix DevOps Toolchain, providing a one-click deployment for anyone who wants to try it out quickly. Every pattern we post is intended to be used, extended, and improved. We hope you’ll post your feedback, and all pull requests to extend the pattern are welcome!

1 comment on"Spring Boot and Kubernetes: A great combination for your microservices!"

  1. Alok Kumar Singh February 09, 2018

    We been running Spring boot java app in kubernetes as containers. The problem we face is we have to assign huge CPU limits around 1.3 cores for the java container to boot in 1-2 minutes. This is a big problem for us as a single pod can consume 1.3 cores of CPU and can effect all the others pods in the same node. How are you solving this?

Join The Discussion

Your email address will not be published. Required fields are marked *