Connecting to services remotely
🌐 This document is available in both English and Ukrainian. Use the language toggle in the top right corner to switch between versions. |
If you need to debug a service remotely from your local machine, follow these steps to connect.
-
Log in to the OpenShift console.
-
Navigate to the Workloads > Deployments menu. Select your project from the Project dropdown list where the remote service connection will be used. In the search bar, enter the name of the service, and from the filtered results, select the necessary one, for example,
user-task-management
.Before editing registry resources in Openshift, consult with the Platform administrator for rights to edit YAML configurations and port forwarding within the registry namespace, as these rights are not granted by default to the registry administrator. -
Go to the YAML menu, and in the editor window, add the following value for the
JAVA_OPTS
property:-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
Figure 1. Resource appearance BEFORE editingFigure 2. Resource appearance AFTER editingNext, proceed with the pod restart.
-
Download the OpenShift command line interface.
-
Click the question mark icon in the upper right corner of the page.
-
Select the Command line tools menu.
-
Choose the utility from the list to download according to your operating system.
-
Open the downloaded file.
-
-
Launch the command line (CMD) from where the
oc.exe
file is located. -
Obtain the token for authentication in OpenShift.
-
Click on your profile name in the upper right corner of the page and select the
Copy login command
menu item. -
Re-authenticate in the system.
-
Click
Display Token
. -
Copy the value from the Log in with this token field.
-
-
Execute the copied command in the command line (CMD), for example:
oc login --token=sha256~1aWEXnvr4IBVNaaaaaaaAAQ10NkhokA9aa-s_-trO8k --server=https://api.example.com:6443
If you encounter an
error: x509: certificate is not trusted
error during login due to a missing certificate on the API endpointhttps://api.example.com:6443
, use the--insecure-skip-tls-verify
flag to bypass TLS verification. For instance:oc login --insecure-skip-tls-verify --token=sha256~1aWEXnvr4IBVNaaaaaaaAAQ10NkhokA9aa-s_-trO8k --server=https://api.example.com:6443
-
Next, select the appropriate project by executing the command:
oc project some_name
where
some_name
is the name of your project. -
Retrieve the pod identifier of the service by executing the command:
oc get pods
-
Execute the port forwarding command:
oc port-forward user-task-management-c8b9695d6-rg92b 5005:5005
-
-
Add a new configuration in IntelliJ IDEA.
-
Go to the
. -
Click
Add New Configuration
and select theRemote JVM Debug
configuration type. -
Specify the name, check the settings, and click
OK
.
-
-
Start the service.
-
The service can now be intercepted on the local machine on the subsequent request.