DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Fast Deployments of Microservices Using Ansible and Kubernetes
  • Kubernetes for Java Developers
  • Deploy Maven Apps to Kubernetes With JKube Kubernetes Maven Plugin
  • Java CI/CD: From Local Build to Jenkins Continuous Integration

Trending

  • How to Format Articles for DZone
  • Medallion Architecture: Efficient Batch and Stream Processing Data Pipelines With Azure Databricks and Delta Lake
  • How AI Agents Are Transforming Enterprise Automation Architecture
  • Build Your First AI Model in Python: A Beginner's Guide (1 of 3)
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Kubernetes Remote Development in Java Using Kubernetes Maven Plugin

Kubernetes Remote Development in Java Using Kubernetes Maven Plugin

Learn how to effectively develop and debug java applications in Kubernetes cluster using Eclipse JKube's remote development functionality.

By 
Rohan Kumar user avatar
Rohan Kumar
·
Dec. 16, 22 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
5.4K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

In this article, we’re going to look at some pain points while developing Java applications on top of Kubernetes. We’re going to look at newly added functionality in Eclipse JKube’s Kubernetes Maven Plugin that allows your application running on your local machine to get exposed in Kubernetes Cluster.

If you haven’t heard about Eclipse JKube or Kubernetes Maven Plugin, I’d suggest you read the following DZone articles first:

  • DZone: Deploy Maven Apps to Kubernetes With JKube Kubernetes Maven Plugin
  • DZone: Containerize Gradle Apps and Deploy to Kubernetes With JKube Kubernetes Gradle Plugin

Target Audience:

  • This blog post targets Java developers who are working with Kubernetes and are familiar with containerized application development. We’re assuming that the reader has experience with Docker and Kubernetes.
  • Eclipse JKube’s Kubernetes Remote Development functionality is suitable for Java developers working on Java applications communicating with several micro-services in Kubernetes, which is difficult to replicate on your local machine.

Current Solutions

  • Docker Compose: You can provide your own YAML file to configure your application services and start all services by your provided YAML configuration. This is only limited to Docker environment. Sometimes these services can be impossible to start due to resource constraints. Also, we may not be allowed to duplicate sensitive data locally.
  • Dev Services: Some popular frameworks also support the automatic provisioning of dependent services in development/testing environments. Developers only need to worry about enabling this feature, and the framework takes care of starting the service and wiring it with your application. This is also limited to Docker environment.
  • Build and Deploy Tooling: Use Kubernetes-related tooling to deploy all dependent services and then deploy your application to Kubernetes.
    • Not smooth as compared to previous alternatives that are limited to Docker
    • Building and deploying applications on every small change leads to slower development iterations

What Is Eclipse JKube Kubernetes Remote Development

Our team at Eclipse Cloud Tooling is focused on creating tools that ease developer activity and development workflow across distributed services. While working and testing on Kubernetes Maven Plugin, we noticed that repeatedly building and deploying applications to Kubernetes while developing locally isn’t the most effective way of working. 

In v1.10.1 of Kubernetes Maven Plugin, we added a new goal k8s:remote-dev . This goal tries to ease java developer workflow across distributed services via:

  • Consuming remote services that are running inside the Kubernetes cluster
  • Live application coding while interacting with other services running in Kubernetes Cluster
  • Exposing applications running locally or by connecting to remote services

Why Kubernetes Remote Development?

Let’s consider a scenario where we’re writing a joke microservice that tries to fetch joke strings from other microservices. Here is a diagram for you to get a better understanding:

Joke Microservice

Figure 1: Simple Joke application using two existing services


Custom Joke Service is our main application which has one endpoint /random-joke. It depends on two other microservices ChuckNorris and Jokes via /chuck-norris and /joke endpoints, respectively. The user requests a joke using /random-joke endpoint, and our application fetches a joke string from one of the two microservices randomly.

In order to develop and test our application, we need access to these dependent ChuckNorris and Jokes services, respectively. Let’s see what the developer’s workflow would look like:

  • While developing and testing Custom Joke Microservice locally, the developer has to set up dependent microservices locally again and again.
  • In order to verify the application is working properly in Kubernetes. The developer has to build, package and deploy the Custom Joke application to Kubernetes in every development iteration.
  • The dependent Services (ChuckNorris and Joke) might be quite heavyweight services and might have some dependent services of their own. It might not be straightforward to set up these locally in the developer’s environment.

Exposing Remote Kubernetes Services Locally

Let’s assume you have two applications already running in Kubernetes Cluster on which your current application is dependent:

 
$ kubectl get svc
NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service1                 NodePort    10.101.224.227   <none>        8080:31878/TCP   113s
service2                 NodePort    10.101.224.227   <none>        8080:31879/TCP   113s


Let us expose these remote services running in Kubernetes Cluster to our local machine. Here is a diagram for you to better understand:

Eclipse JKube's Remote Dev goal/task simplifying developing with remote services

Figure 2: JKube's remote development simplifying remote development


In order to do that, we need to provide XML configuration to our plugin for exposing these services:

XML
 
      <plugin>
        <groupId>org.eclipse.jkube</groupId>
        <artifactId>kubernetes-maven-plugin</artifactId>
        <version>${jkube.version}</version>
        <configuration>
          <remoteDevelopment>
            <remoteServices>
              <remoteService>
                <hostname>service1</hostname> <!-- Name of Service -->
                <port>8080</port>                 <!-- Service port -->
                <localPort>8081</localPort>       <!-- Local Port where to expose -->
              </remoteService>
              <remoteService>
                <hostname>service2</hostname>  <!-- Name of Service -->
                <port>8080</port>           <!-- Service Port -->
                <localPort>8082</localPort> <!-- Local Port where to expose -->
              </remoteService>
            </remoteServices>
          </remoteDevelopment>
        </configuration>
      </plugin>


The above configuration is doing these two things:

  • Expose Kubernetes service named service1 on port 8081 on your local machine
  • Expose Kubernetes service named service2 on port 8082 on your local machine

Run Kubernetes Remote Development goal:

Shell
 
$ mvn k8s:remote-dev
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------< org.eclipse.jkube.demos:random-jokes-generator >-----------
[INFO] Building random-jokes-generator 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.10.1:remote-dev (default-cli) @ random-jokes-generator ---
[INFO] k8s: Waiting for JKube remote development Pod [jkube-remote-dev-9cafc1e1-054b-4fab-8f4e-b4345056478e] to be ready...
[INFO] k8s: JKube remote development Pod [jkube-remote-dev-9cafc1e1-054b-4fab-8f4e-b4345056478e] is ready
[INFO] k8s: Opening remote development connection to Kubernetes: jkube-remote-dev-9cafc1e1-054b-4fab-8f4e-b4345056478e:54252


[INFO] k8s: Kubernetes Service service1:8080 is now available at local port 8081

[INFO] k8s: Kubernetes Service service2:8080 is now available at local port 8082


Try accessing services available locally on ports:

Shell
 

$ curl localhost:8081/
Chuck Norris's OSI network model has only one layer - Physical.

$ curl localhost:8082/
Why do Java programmers have to wear glasses? Because they don't C#.


As you can see, You are able to access Kubernetes services service1 and service2 locally on ports 8081 and 8082, respectively.

Conclusion

In this article, you learned about Eclipse JKube’s Kubernetes Maven Plugin’s remote development goal and how you can expose your local applications to the Kubernetes cluster and vice versa.

In case you’re interested in knowing more about Eclipse JKube, you can check these links:

  • Documentation
  • Github Issue Tracker
  • StackOverflow
  • YouTube Channel
  • Twitter
  • Gitter Chat
Apache Maven Kubernetes Docker (software) Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Fast Deployments of Microservices Using Ansible and Kubernetes
  • Kubernetes for Java Developers
  • Deploy Maven Apps to Kubernetes With JKube Kubernetes Maven Plugin
  • Java CI/CD: From Local Build to Jenkins Continuous Integration

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!