I have openshift namespace (SomeNamespace), in that namespace I have several pods.
I have route associated to that namespace (SomeRoute).
In one of pods I have my spring application. It has REST controllers.
I want to send message to that REST controller, how can I do it?
I have route URL https://some.namespace.company.name, what should I find next?
I tried to send requests to https://some.namespace.company.name/rest/api/route , but it didnt work. I guess, I must somehow specify pod in my URL, so route will redirect requests to concrete pod but I dont know how I can do it
CodePudding user response:
You don't need to specify the pod in the route.
The chain goes like this:
Route
exposes a given port of aService
Service
selects some pod to route the traffic to by its.spec.selector
field
You need to check your Service
and Route
definitions.
Example service and route (including only the related parts of the resources):
Service
spec:
ports:
- name: 8080-tcp
port: 8080
protocol: TCP
targetPort: 8080
selector:
<label-key>: <label-value>
Where label-key
and label-value
is any label key-value combination that selects your pod with the http application.
Route
spec:
port:
targetPort: 8080-tcp <port name of the service>
to:
kind: Service
name: <service name>
When your app exposes some endpoint on :8080/rest/api
, you can invoke it with <route-url>/rest/api
You can try it out with some example application (some I found randomly on github, to verify everything works correctly on your cluster):
create a new app using s2i build from github repository:
oc new-app registry.redhat.io/openjdk/openjdk-11-rhel7~https://github.com/redhat-cop/spring-rest
wait until the s2i build is done and the pod is started
expose the service via route:
oc expose svc/spring-rest
grab the route url:
oc get route spring-rest -o jsonpath='{.spec.host}'
invoke the api:
curl -k <route-url>/v1/greeting
response should be something like:
{"id":3,"content":"Hello, World!"}