Java Champion Elder Moraes | From the Commit to the Cloud: Why Java and Kubernetes are Your Best Friends
January 30, 2023
In our new Java Monthly edition, we’d like to introduce you to Elder Moraes. He was kind enough to share his experience on 10 more Java-related questions.
Elder helps Java developers to build and deliver fast and high available server-side applications, so they can work on amazing projects. He is a Java Champion, a published author of six books, and a board member at SouJava, one of the biggest JUGs in the world. As a Developer Advocate, Elder shares experiences and best practices through online content and at international events like JavaOne, The Developers Conference, QCon, Oracle Code One, Campus Party, and Devnexus.
Dreamix: Is there an alternative to Docker? Why is Docker the most famous containerization platform?
Elder Moraes: Docker is famous for one simple reason: standardization. Containers technology has been around for years before the first Docker release. But without any standard, there was not that much appeal for adoption, mainly due to lock-in risk. Once the industry found a standard… boom! Now vendors and developers working on open-source projects, platforms, and cloud-native initiatives found one single way to distribute their applications, using an interchangeable approach between different environments.
That said, for me the best alternative to Docker is Containerd. It’s a CNCF-graduated containers runtime that you can use to create, execute and destroy containers in the same way you do with Docker. And if you are looking for something to just build images (like in a CI/CD pipeline, for example), you can also take a look at tools like Podman and Buildah.
Dreamix: When is it better to use Kubernetes and when is Docker-compose?
Elder Moraes: When the complexity of the needed solution demands it. Both are containers orchestration platforms, but with different usage scenarios.
Docker compose is commonly used when you have more straightforward container usage. In this approach, you have a lot of responsibility for the configuration details. Integration with other platforms, though possible, is not that easy.
Kubernetes is used when you need to run your applications using a complex combination of multiple hosts simultaneously. You have more flexibility to configure both your environment and your application to improve scalability, availability, elasticity, and security right from the platform, which gives you more opportunities to focus your code more on business purposes and less on infrastructure.
Also with Kubernetes, you can use operators to run other platforms under the same runtime, which will provide the same Kubernetes features and advantages to them. Examples of those platforms are Kafka, Istio, Tekton, Knative, etc.
But I don’t recommend using Vanilla Kubernetes (plain installation of Kubernetes), as it will demand a lot of manual configuration and a lack of tooling (that yes, you can solve using operators, but will demand more work to be done). So I always stick with a Kubernetes implementation like OpenShift, which leverages what is already great on Kubernetes, turning it into something awesome (and preserving compatibility with tools like kubectl).
Dreamix: What are the best practices and tools for resource management with Kubernetes?
Elder Moraes: From the Java perspective, you need to start by understanding JVM ergonomics. In this case, two things are essential: defining the heap size configuration and choosing the right Garbage Collector for your scenario.
From the Kubernetes perspective, resource management starts with two words: Requests and Limits. Both are defined at the Deployment level and are the most fundamental practices to manage your application’s resources under Kubernetes.
Requests will define the minimal resources (CPU and memory) needed to start your application. If there are no resources available in your cluster, your application won’t start.
Limits, as the name suggests, are the maximum resources that your application can allocate. If it tries to allocate above this limit, the pod will be killed/restarted.
Dreamix: Do you think that Kubernetes will kill/take over Docker one day?
Elder Moraes: No. They are used in different stages during the development time. It’s way simpler to test your code during its early stages of development in a local Docker than to deploy it to a Kubernetes cluster (even if it’s also local).
Dreamix: What is a native image, and when and how to use it?
Elder Moraes: It’s a technology that uses Ahead of Time compilation to create a standalone executable. This executable contains application classes, dependencies, classes from runtime libraries, and static code native from JDK. It also contains a runtime system called Substrate VM, which has super simple versions of some JVM services like memory management, thread scheduling, GC, etc.
So basically you can use it to run a Java application without a JVM.
If you compare a native image to a regular JVM-based application, it has a faster startup and a smaller memory footprint, given that a lot of runtime processes were already done during build time. On the other hand, it also has some limitations due to the lack of runtime optimizations and other full services offered by the JVM.
In other words: there are no silver bullets!
Native images are ideal when your application is small, has a small heap, will be invoked multiple times in a short period, and has a short life cycle (ex: CLI apps and serverless functions).
Dreamix: Do you think that Quarkus is good enough for long-living applications?
Elder Moraes: This question probably comes from the misunderstanding that Quarkus depends on the native image. It doesn’t! All Quarkus optimizations are JVM-compatible, so you can use them with whatever JDK you like. But if you want to deploy a Quarkus application as a native image, it’s 100% compatible as well. So you have the best of both worlds.
Dreamix: When starting a new project, how to choose which frameworks are right for us? Quarkus or Spring Boot?
Elder Moraes: Don’t choose a framework that is right for you: choose one that is right for the problem you need to solve. It can be Quarkus, Spring Boot, Jakarta EE, Micronaut, etc.
For example: if you are using a Java framework and you need to reduce the memory footprint of your application, and/or make it crazily fast, and/or make it super short (to downsize your container image, for example), Quarkus is the right tool to solve your problem. And it will even give you hundreds of extensions to integrate with top open-source projects.
Dreamix: What is the future of Java? (or As a Java Champion, what do you think is the future of Java?)
Elder Moraes: Java will keep as one of the top most relevant languages in the world for the next decades for sure. No other platform has the same amount of investment that has been made to Java for over 27 years. No other language has kept evolving and improving for such a long time as Java. No other language matches the same level of scalability for huge systems as Java does.
And the most important: community. No other technology in the world has a most vibrant community. Since day one, everything in the Java ecosystem is created from the community and for the community. And we are something around 10 million developers around the world today. Not bad, right?
All these aspects will keep Java alive and kicking until some generations of developers retire.
Dreamix: How do you update yourself on the latest trends in Java?
Elder Moraes: Usually, I pay attention to the main Java conferences around the world (JavaOne, Devoxx, Devnexus, etc) and get insights about the most relevant Java topics at the moment. Then I look for content (articles, books, workshops) from these insights to teach myself about them. And most important: everything that I’m learning has to involve some kind of implementation (coding, creating an article, a talk, etc). We all have different ways of learning, but I truly believe that we all learn a lot more by doing.
Dreamix: Can you recommend a favorite book about programming?
Elder Moraes: Effective Java, from Joshua Block. It’s just a masterpiece! There is a lot of talking about code improvement, but Mr. Block brought it to real life through this amazing book.
Is there anything else you would like to ask Elder Moraes? What is your opinion on the questions asked? Who would you like to see featured next? Let’s give back to the Java community together!