Saturday 6 June 2020

Connection to Backend service from Frontend Route in Openshift using proxypass method

Connection to Back end service from Front end Route in Openshift using proxypass rule:


We all know service object is used to connect the front end application to the back end application . Similarly route object when accessing outside the cluster.

Here i am going to show about how we can connect to back end application (not exposed as route) from front end application outside the cluster.


As we need to understand in reality back end application should not be exposed outside the cluster as route. This can be done using front end Apache configuration (pod running in the same cluster where back end pod is running).

 The FE Apache server other than returning the angular sources , it should also be configure to reverse proxy. So every call to the back end will passthrough the route of the front end.

Ex: Let us assume the Front end application is available as route and running in the path
       https://hpvbalaji.blogspot.com/
      So here every call to https://hpvbalaji.blogspot.com/api  should be a reverse proxy request to the back end .
  Here Apache will be configured to call the service of the back end every time it get's a call to the https://hpvbalaji.blogspot.com/api. By doing this no need to expose the back end service as route.

......I know it's quite difficult to understand with the above example , let me show the Apache configuration now so that u guys can understand better.....

1. Navigate to /etc/httpd/conf.d Directory or  /etc/httpd/httpd.conf file
2. Add the below two lines in the httpd configuration file.

               <VirtualHost *:80>

           ServerName sub.domain.com
           ServerAdmin me@domain.com
           <Proxy *>
            Order deny,allow
            Allow from all
       
           </Proxy>
 
           ProxyPass /api/ http://backend:8080/
   ProxyRequests Off
           ProxyPreserveHost On
       </VirtualHost>

    Note: back end is the service name of the back end pod.

3. Here in case of openshift we can create volume with the below command using configmap and mount this new modified Apache configuration file on the container file system as below.

          oc set volume dc/frontend --add --name=httpdconf --type=configmap --configmap-                              name=kerberos-auth --mount-path=/etc/httpd/conf.d/


More infomation on Proxy pass can be found here: https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypassreverse