Openshift router to open a nginx-php page - Mapping port doesn't work
Hello guys! I have one image with nginx-php-fpm, that has been pushed to my Openshift Private Registry. I created a namespace "fap" and made a deploy of that nginx-php-fpm image.
My nginx is listening in port 9080:
# curl -I 192.168.169.8:9080
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 15 Sep 2016 15:26:00 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
I created a route to Target Port 9080:


If I try to open my index.php page in the browser, using the URL "http://pxlodocker001:9080", nothing occurs.
If I try to open my index.php page in the browser, using the URL "http://pxlodocker001", I can see the expected result.
I don't understand why the mapping port isn't working...
The router is listening on port 80 and 443, and transforms internally to the target port (9080). You cannot access 9080 from outside the cluster.
@Shyckymn as mentioned, the router always accepts traffic on 80 and 443 and handles sending the traffic to the specific pod ports. Please reopen if this does not address your question.
More details on the router plugins can be found at https://docs.openshift.org/latest/architecture/core_concepts/routes.html
Hello @smarterclayton and @pweil! Ok, I understood... I want to try some IP address and port that points to a service, with multiple pods, so that I can see the round robin working, as a load balancer. My index.php file has some functions that show me the server/client IP address to evidence this. If I scale up my service to have two pods, by example, when I call the URL, the answer always show me the same server address, so I think that round robin is not working... Any ideas?
@Shyckymn by default, haproxy will balance using the 'leastconn' algorithm. You can control this using the haproxy.router.openshift.io/balance annotation on your route to set it to "roundrobin", "leastconn", or "source". Also, the router will set a cookie to maintain session stickiness so be sure that you're clearing cookies when testing.
One other thing to check is that your new pod is showing up in the service endpoints. If the pod is running and ready you should see multiple ip addresses when you run oc get endpoints <service name>. These endpoints are what the router uses to direct traffic.
Finally, if you are curling the service ip directly to test this (rather than using a route) make sure your service's SessionAffinity is not set to ClientIP.
Hi @pweil! Please, could you help me with the steps to put the annotation in my router config? I navigate in my openshift web console but I didn't found how to do that...
Endpoints are working fine...
# oc get endpoints nginx-php-fpm
NAME ENDPOINTS AGE
nginx-php-fpm 192.168.169.7:9443,192.168.169.8:9443,192.168.169.9:9443 + 3 more... 20h
@Shyckymn this annotation goes on the route.
oc annotate route <name> haproxy.router.openshift.io/balance=roundrobin should give you what you need
You can view the route to see that it is properly annotated with oc describe route <name>
@pweil, Ok, I did it.
But refreshing my web page (F5), doesn't show me round robin working... The same server IP address appears in the browser. Do I have to restart the environment?
$ oc annotate route nginx-php-fpm haproxy.router.openshift.io/balance=roundrobin
route "nginx-php-fpm" annotated
$ oc describe routes/nginx-php-fpm
Name: nginx-php-fpm
Namespace: fap
Created: 20 hours ago
Labels: app=nginx-php-fpm
Annotations: haproxy.router.openshift.io/balance=roundrobin
Requested Host: pxl0docker001
exposed on router router 20 hours ago
Path: <none>
TLS Termination: <none>
Insecure Policy: <none>
Endpoint Port: 9080-tcp
Service: nginx-php-fpm
Weight: 100 (100%)
Endpoints: 192.168.169.7:9443, 192.168.169.8:9443, 192.168.169.9:9443 + 3 more...
@Shyckymn since you're using a browser, did you clear cookies (after each refresh) as noted in https://github.com/openshift/origin/issues/10927#issuecomment-247575472?
I did a quick test of this to make sure the router picks up the annotation change and saw the correct behavior. Using curl I was able to see the router balance between two pods:
[pweil@localhost unsecure]$ oc get pods
NAME READY STATUS RESTARTS AGE
hello-nginx-docker 1/1 Running 4 9m
hello-nginx-docker2 1/1 Running 0 9m
router-2-udawh 1/1 Running 0 4m
[pweil@localhost unsecure]$ oc get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-nginx-http 172.30.201.57 <none> 27017/TCP 10m
kubernetes 172.30.0.1 <none> 443/TCP,53/UDP,53/TCP 16m
router 172.30.4.40 <none> 80/TCP,443/TCP,1936/TCP 6m
[pweil@localhost unsecure]$ oc describe route route-unsecure
Name: route-unsecure
Namespace: default
Created: 4 minutes ago
Labels: <none>
Annotations: haproxy.router.openshift.io/balance=roundrobin
Requested Host: www.example.com
exposed on router router 4 minutes ago
Path: <none>
TLS Termination: <none>
Insecure Policy: <none>
Endpoint Port: <all endpoint ports>
Service: hello-nginx-http
Weight: 100 (100%)
Endpoints: 172.17.0.2:80, 172.17.0.3:80
[pweil@localhost unsecure]$ curl -H "Host:www.example.com" 0.0.0.0
Hello World
[pweil@localhost unsecure]$ curl -H "Host:www.example.com" 0.0.0.0
Hello World 2
[pweil@localhost unsecure]$ curl -H "Host:www.example.com" 0.0.0.0
Hello World
[pweil@localhost unsecure]$ curl -H "Host:www.example.com" 0.0.0.0
Hello World 2
@pweil Yeah! Now it works! Thanks for your support!