<p>Is it possible to route ingress controller traffic to different services/deployments based upon the file type in the path? For example if the path was:</p>

<pre><code>domain.com/directory/hello.html -&gt; (Frontend Service)
domain.com/directory/hello.php -&gt; (Backend Service)
</code></pre>

<p>The architecture I have designed looks like this:
<a href="https://i.stack.imgur.com/OZ57H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OZ57H.png" alt="enter image description here"></a></p>

<p>Does this look suitable and is this possible, or is there a better way of achieving this?</p>

<p>My ingress controller looks like:</p>

<pre><code>kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: vote-ingress
  namespace: default
  selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/vote-ingress
  uid: 597158e6-a0ce-11e9-b3b1-00155d599803
  resourceVersion: '268064'
  generation: 1
  creationTimestamp: '2019-07-07T15:46:13Z'
spec:
  rules:
    - host: localhost
      http:
        paths:
          - path: /*.php
            backend:
              serviceName: website-backend
              servicePort: 80
          - path: /
            backend:
              serviceName: website-frontend
              servicePort: 80
status:
  loadBalancer:
    ingress:
      - hostname: localhost
</code></pre>

Matt Davis
<blockquote>
  <p>Is it possible to route ingress controller traffic to different services/deployments based upon the file type in the path?</p>
</blockquote>

<p>No in that way. You would need to route your request to <code>NGINX</code> which will send request for <code>*.php</code> to a <code>PHP_FPM</code>. You can have that as separate Containers inside one Pod or as Services. Service example is nicely explained in <a href="https://www.digitalocean.com/community/tutorials/how-to-deploy-a-php-application-with-kubernetes-on-ubuntu-16-04" rel="nofollow noreferrer">How To Deploy a PHP Application with Kubernetes on Ubuntu 16.04</a></p>

<p>In this example you will have two containers <code>NIGNX</code> and <code>PHP_FPM</code> running on the Pod.
PHP-FPM will handle dynamic PHP processing, and the NGINX will act as a web server.</p>

<p>You will need to use custom <code>nginx.conf</code> configuration and in my opinion the easiest way would be using <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">ConfigMap</a>.</p>

<p>Your ConfigMap might look like the following:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
data:
  config : |
    server {
      index index.php index.html;
      error_log  /var/log/nginx/error.log;
      access_log /var/log/nginx/access.log;
      root /;

      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }

      location ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }
</code></pre>

<p>Nginx will catch and  send all <code>*.php</code> request via localhost:9000 to PHP-FPM container.</p>

<p>You can include the ConfigMap in your <code>POD</code> using the following:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
    - name: nginx-container
      image: nginx:1.7.9
      volumeMounts:
      - name: config-volume
        mountPath: /etc/nginx/nginx.conf
        subPath: nginx.conf
  volumes:
    - name: config-volume
      configMap:
        name: nginx-config
  restartPolicy: Never
</code></pre>
