<p>I have am using Google Kubernetes Engine 1.8.6 and have a load balancer configured as below:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-load-balancer
spec:
  ports:
  - port: 19222
    name: my-test-port
    protocol: TCP
    targetPort: 19222
  - port: 9222
    name: my-prod-port
    protocol: TCP
    targetPort: 9222
  selector:
    app: test-app-stateful-set
  type: LoadBalancer
</code></pre>

<p>This allows someone connecting to the load balancer's external IP to be routed to my <code>test-app-stateful-set</code> when they use port 19222. However I would like connections to port 9222 from the same external IP sent to my <code>prod-app-stateful-set</code> instead. How can I configure my service to do this?</p>

<p>You can't do this directly, because a <code>Service</code> has a single <code>NodeSelector</code> that is valid for all its ports. </p>

<p>One option you have is to run a third pod that acts as a proxy. It receives connections on both ports and forwards the traffic to your backend a based on the port the incoming traffic is coming through.</p>

<p>You could use <code>nginx</code> for this proxy pod.</p>

<p>A sample configuration for your nginx could be the following:</p>

<pre><code>stream {
  server { 
    listen 19222;
    proxy_pass &lt;test-service-name&gt;:19222;
  }
  server { 
    listen 9222;
    proxy_pass &lt;prod-service-name&gt;:9222;
  }
}
</code></pre>

<p>Of course, your load balancer service has to be adjusted as well in order to make the selector match your new nginx pod and you need to create two different services for your production and test pods</p>
