<p>I would like my application hosted in an Openshift cluster to target an external REST API without hardcoding IP/PORT in the client application, and also to be able to change IP/PORT without redelivering the application.</p>

<p>I managed to do it through ConfigMap, but I saw it may also be possible to do through Service <a href="https://docs.openshift.com/enterprise/3.0/dev_guide/integrating_external_services.html" rel="nofollow noreferrer">in OpenShift doc</a>.</p>

<p>However I did not manage to understand how it is working. I did the following:</p>

<h2>Creating a service</h2>

<pre><code>sylvain@HP:~$ oc export svc example-external-service
apiVersion: v1
kind: Service
metadata:
   creationTimestamp: null
   name: example-external-service
 spec:
   ports:
   - name: http
     port: 80
     protocol: TCP
     targetPort: 80
   sessionAffinity: None
   type: ClusterIP
 status:
   loadBalancer: {}
</code></pre>

<h2>Creating an endpoint</h2>

<pre><code>sylvain@HP:~$ oc export endpoints example-external-service
apiVersion: v1
kind: Endpoints
metadata:
  creationTimestamp: null
  name: example-external-service
subsets:
- addresses:
  - ip: 216.58.198.195
  ports:
  - name: "80"
    port: 80
    protocol: TCP
</code></pre>

<h2>Doing a curl to my service from the POD where my app is running</h2>

<pre><code>sylvain@HP:~$ oc get pods
NAME                     READY     STATUS    RESTARTS   AGE
nodejs-example-1-qnq46   1/1       Running   0          36m
sylvain@HP:~$ oc rsh nodejs-example-1-qnq46
sh-4.2$ env | grep "EXAMPLE_EXTERNAL"
EXAMPLE_EXTERNAL_SERVICE_SERVICE_PORT_HTTP=80
EXAMPLE_EXTERNAL_SERVICE_SERVICE_PORT=80
EXAMPLE_EXTERNAL_SERVICE_PORT_80_TCP_PORT=80
EXAMPLE_EXTERNAL_SERVICE_SERVICE_HOST=172.30.51.168
EXAMPLE_EXTERNAL_SERVICE_PORT_80_TCP_ADDR=172.30.51.168
EXAMPLE_EXTERNAL_SERVICE_PORT_80_TCP_PROTO=tcp
EXAMPLE_EXTERNAL_SERVICE_PORT=tcp://172.30.51.168:80
EXAMPLE_EXTERNAL_SERVICE_PORT_80_TCP=tcp://172.30.51.168:80
sh-4.2$ curl 172.30.51.168
curl: (7) Failed connect to 172.30.51.168:80; No route to host
sh-4.2$ curl 216.58.198.195
&lt;HTML&gt;&lt;HEAD&gt;&lt;meta http-equiv="content-type" content="text/html;     charset=utf-8"&gt;
&lt;TITLE&gt;301 Moved&lt;/TITLE&gt;&lt;/HEAD&gt;&lt;BODY&gt;
&lt;H1&gt;301 Moved&lt;/H1&gt;
The document has moved
&lt;A HREF="http://www.google.com/"&gt;here&lt;/A&gt;. 
&lt;/BODY&gt;&lt;/HTML&gt;
sh-4.2$ 
</code></pre>

<p>In the first curl using the address defnined in the endpoint is working, however using the one in the environment variable:</p>

<pre><code>EXAMPLE_EXTERNAL_SERVICE_SERVICE_HOST=172.30.51.168
</code></pre>

<p>It is failing, so the routing is not correcty done. </p>

<p>What am I doing wrong? What did I miss?</p>

<p>Cheers</p>

scoulomb
<p>In your endpoint configuration, change the name of port 80 (<code>"80"</code>) to <code>http</code>. It needs to be the same as in the service configuration.</p>
