<p>I've dockerized a legacy desktop app.  This app does resource-intensive graphical rendering from a command line interface.</p>
<p>I'd like to offer this rendering as a service in a &quot;compute farm&quot;, and I wondered if Kubernetes could be used for this purpose.</p>
<p>If so, how in Kubernetes would I ensure that each pod only serves one request at a time (this app is resource-intensive and likely not thread-safe)?  Should I write a single-threaded wrapper/invoker app in the container and thus serialize requests?  Would K8s then be smart enough to route subsequent requests to idle pods rather than letting them pile up on an overloaded pod?</p>

<p>Interesting question.</p>
<p>The inbuilt default Service object along with kube-proxy does route the requests to different pods, but only does so in a round-robin fashion which does not fit our use case.</p>
<p>Your use-case would require changes to be made to the kube-proxy setup during the cluster setup. This approach is tedious and will require you to have your own cluster setup (not supported by cloud services). As described <a href="https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-ipvs" rel="nofollow noreferrer">here</a>.</p>
<p>Best bet would be to setup a service-mesh like Istio which provides the features with little configuration along with a lot of other useful functionalities.</p>
<p>See if <a href="https://istio.io/latest/docs/reference/config/networking/destination-rule/#ConnectionPoolSettings" rel="nofollow noreferrer">this</a> helps.</p>
