<p>I am working on a project on GCP and I need to create a system that works like a load balancer, but the load is the number of items in a pub/sub queue. </p>

<p>Here is more detail:</p>

<ol>
<li>I have a message queue which is based on pub/sub.</li>
<li>A lot of messages are posted to this ques and I have one service which consume them.</li>
<li>It would takes some hours to process each items in the queue. </li>
<li>I want to start a new service ( a docker image) when the number of items in the queue became very big (say I want to start anew service when the number of items in the queue became more than 10 items and start another one when the number of items in the queue became more than 20 and so on) and shutdown the services when the number of items in the queue reduces (so for example if the number of items in the queue is come to under 20, shut down all services and only 2 services became live)</li>
</ol>

<p>Now my questions are:</p>

<ol>
<li>How can I do this?</li>
<li>Is kubernties a good solution? if yes, where can I find more information about it. </li>
<li>Can I do it by pub/sub? If yes, where can I find information?</li>
</ol>

mans
<p>I have a similar requirement (that I am struggling with). I would suggest you look at an horizontal pod autoscaler based on an external stackdriver monitoring metric to see if it will meet your needs. This process is discussed here:</p>

<p><a href="https://cloudplatform.googleblog.com/2018/05/Beyond-CPU-horizontal-pod-autoscaling-comes-to-Google-Kubernetes-Engine.html" rel="nofollow noreferrer">https://cloudplatform.googleblog.com/2018/05/Beyond-CPU-horizontal-pod-autoscaling-comes-to-Google-Kubernetes-Engine.html</a></p>

<p>and here:</p>

<p><a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/external-metrics-autoscaling" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/tutorials/external-metrics-autoscaling</a></p>
