Background:

Basic environment: Centos8 + Kubead 1.20.5+ Cilium + Hubble environment construction, Traefik to provide external services: Kubernetes 1.20.5 installation Traefik in Tencent cloud practice. Run a few basic PHP services. Base image is a reference https://github.com/richarvey/nginx-php-fpm. Alleged memory size of 134217728 bytes exhausted (tried to allocate 6291488 bytes) I don’t want to mirror it again. How to do?

1. Problem review and solution:

1. Find the configuration item that caused the error report

Alleged memory size of 134217728 bytes exhausted (tried to allocate 6291488 bytes) The limit should be 128M. PHP running a script that needs to use 134M resources over? First go inside the container and take a peek to see what this might be:

php -i 



The memory_limit parameter limits 128M

2. In-depth understanding of configuration item parameter Settings and meaning

The memory_limit parameter can be used to specify the memory_limit parameter.

How much memory can a PHP worker process (php-fpm) use?



And then:



Both feelings are not a matter of time, huh?



With reference to:https://docs.rackspace.com/support/how-to/php-memory-limit/

Let’s not worry about that for a second. Anyway, this is the first understanding:

Prevent poorly written scripts from eating up all available memory on the server

3. How to modify the parameters and verify whether they are valid

Start memory_limit this parameter set is 128 m since not enough, the first expansion?

The dockerfile parameter is set to 128M in the start.sh startup script:



Shall I change the start.sh script now? Or can I set the environment variable?



After trying to modify the YAML file and redeploy the service, verify the following:



OK is in effect. Are environment variables higher in priority than variables in startup scripts? Can I understand it this way?

Analyse:

  1. How do I set the appropriate range for the memory_limit parameter? I think I set it to 256M which is a little bit larger.
  2. This parameter is set large after my concurrent threads how to control…. . Will my resources be insufficient? Cause all kinds of crashes? Let’s expand the memory of my container first.

  1. In fact, I still feel that PHP script is too bad to eat the memory…… It’s a relatively simple service. It would be amazing to eat that much memory. Just ask them to find problems and optimize the script.
  2. Mainly think to learn to use. Use variables to do as many configurations as possible. Avoid building base images repeatedly.