<p>I have recently migrated my application from a single server w/ docker into Google Kubernetes Engine for the reasons of scaling. I am new to the kubernetes platform, and I may not yet fully understand the concepts of it but I do get the basics. </p>

<p>I have successfully migrated my application on a <code>cluster size of 3 each with 1vCPU and 3.75 GB RAM</code></p>

<p>Now I came across on what is the best configuration for the php-fpm processes running in a kubernetes cluster. I have read a few articles on how to setup the php-fpm processes such as </p>

<p><a href="https://serversforhackers.com/c/php-fpm-process-management" rel="noreferrer">https://serversforhackers.com/c/php-fpm-process-management</a></p>

<p><a href="https://www.kinamo.be/en/support/faq/determining-the-correct-number-of-child-processes-for-php-fpm-on-nginx" rel="noreferrer">https://www.kinamo.be/en/support/faq/determining-the-correct-number-of-child-processes-for-php-fpm-on-nginx</a></p>

<p>On my cluster I have an Elasticsearch, Redis, Frontend and a REST Api and my understanding about kubernetes, each has their own pods running on my cluster, I tried to access the pod for the REST Api and see 1 vCPU and 3.75 GB RAM which is what I set on my cluster specs. And the RAM has only 1.75GB left, so I think there are other services or pods using the memory.</p>

<p>So now I wanted to increase the size of the following based on the articles I shared above.</p>

<pre><code>pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 4
pm.max_spare_servers = 8 
</code></pre>

<p>But my problem is since the pod is on a worker, if I change the configuration base on the available memory left (base on the articles I shared above on Calculating pm.max_children) I might end up a pod consuming all memory space left, and will not be able to allocate for the other services. Is my problem makes sense? or is there an idea I am missing? </p>

<p>Base on the article since my worker has 3.75 GB RAM and and other services is already consuming 1.5GB ram so my best aim is at 1 GB RAM.</p>

<p>pm.max_children brings us to 1024 Mb / 60 Mb = 17 max_children</p>

<pre><code>pm.max_children = 17
pm.start_servers = 8
pm.min_spare_servers = 7
pm.max_spare_servers = 10
pm.max_requests = 500
</code></pre>

<p>Which leads me to the question How to compute for the php-fpm child process on a Kubernetes Cluster when there are other services or pods shares the same resources. </p>

<p>Thank you for reading until the end, and thanks in advance for your inputs.</p>

Efx
<p>GKE comes with multiple system pods (such as kube-DNS and fluentd). Some of these pods do not scale up much, this means if you add additional nodes, they will have more available resources. </p>

<p>The nodes are also running an OS so some of the memory is being assigned to that.
You can also view the resources available per node by using <code>kubectl describe no | grep Allocatable -A 5</code></p>

<p>This will show you the amount of resources left after the node's consumption. 
Using <code>kubectl describe no | grep Allocated -A 5</code> you can view the amount of memory and CPU that is already requested by current pods.</p>

<p>All this being said, you should choose the number of child processes based on your need.  Once you know the amount of memory the pod will need, set <a href="https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#resource-requests-and-limits-of-pod-and-container" rel="nofollow noreferrer">resource requests and limits</a> to your pod config so that the kubernetes scheduler can put the php-fpm on a node with sufficient resources.</p>

<p>Kubernetes strength is that you tell it what you want and it will try to make that happen. Instead of worrying too much about how much you can fit, choose an amount for your pod based on your expected/required performance and tell kubernetes that's how much memory you need. This way, you can also <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">increase the number of pods using HPA</a> instead of managing and scaling up the number of child processes.</p>
