As a follow on to my previous post, I thought it would be interesting to describe how to live debug a Java application running on OpenShift.
Setup
sudo oc cluster up --version=latest # Any OpenShift environment will work
oc login # as developer:developer
oc new-app openshift/wildfly-101-centos7~https://github.com/danmcp/openshift-jee-sample.git
oc expose service/openshift-jee-sample
oc set env dc/openshift-jee-sample DEBUG=true # Enable the debug port
Next, browse to the web console and log in as developer:developer. Select My Project and click on the url for openshift-jee-sample in the upper right. You should see the index.html page. Add /HelloWorld to the end of the url and you should see the output of the HelloWorld Servlet.
You'll need to use port forwarding to expose the debug port from the container to a local port on your host. Using port forwarding is ideal because it keeps you from having to expose the container debug port to the rest of the cluster.
oc get pods # To get the name of the running pod you will sync to
oc port-forward <pod_name> 8787:8787 # Replace <pod_name> with the value from the previous step
I'm going to use Eclipse for my example, but you can use any IDE or CLI (such as jdb) that supports remote debugging. If you are using Eclipse, you'll want to download the source and add it to your workspace.
git clone https://github.com/danmcp/openshift-jee-sample.git
Demo
At this point, you're all set to connect your debugger and start stepping through some code:
[video width="1920" height="1080" webm="https://blog.openshift.com/wp-content/uploads/java_debug.webm"][/video]
Wrap Up
My example was with oc cluster up but the basic steps of setting DEBUG=true and oc port-forward will work with any OpenShift environment and with all of our JBoss images. Happy debugging!
Über den Autor
Ähnliche Einträge
From maintenance to enablement: Making your platform a force-multiplier
NGINX Gateway Fabric certified for Red Hat OpenShift
The Ground Floor | Compiler: Tales From The Database
Bad Bosses | Compiler: Tales From The Database
Nach Thema durchsuchen
Automatisierung
Das Neueste zum Thema IT-Automatisierung für Technologien, Teams und Umgebungen
Künstliche Intelligenz
Erfahren Sie das Neueste von den Plattformen, die es Kunden ermöglichen, KI-Workloads beliebig auszuführen
Open Hybrid Cloud
Erfahren Sie, wie wir eine flexiblere Zukunft mit Hybrid Clouds schaffen.
Sicherheit
Erfahren Sie, wie wir Risiken in verschiedenen Umgebungen und Technologien reduzieren
Edge Computing
Erfahren Sie das Neueste von den Plattformen, die die Operations am Edge vereinfachen
Infrastruktur
Erfahren Sie das Neueste von der weltweit führenden Linux-Plattform für Unternehmen
Anwendungen
Entdecken Sie unsere Lösungen für komplexe Herausforderungen bei Anwendungen
Virtualisierung
Erfahren Sie das Neueste über die Virtualisierung von Workloads in Cloud- oder On-Premise-Umgebungen