We have a PHP-based application running in Kubernetes and uses settings from a
/app/.env file plus environment variables.
The problem is that application running in a Docker container can’t see an
$TEST_VAR variable although it’s present in the Deployment:
... containers: - name: application-dev-web image: bttrm-application:119 ... - name: TEST_VAR valueFrom: secretKeyRef: name: bttrm-app-secret key: test_var ...
And its value is set via Kubernetes Secrets:
apiVersion: v1 kind: Secret metadata: name: bttrm-app-secret namespace: application-dev-ns type: Opaque data: test_var: dGVzdF92YWwK
In a pod, this variable also accessible and can be found with the
Still, if create a php-file with the
phpinfo() function – in the resulted Environment block we will see only two variables –
The first solution can be to add an explicit variable export:
... env[TEST_VAR] = $TEST_VAR
Deploy and check:
Okay, it’s working but you’ll have to add such a string for each variable used.
clear_env = no
Another solution can be by setting the
clear_env PHP-FPM’s parameter no.
/etc/php7/php-fpm.d/www.conf file and add the following:
... ;env[DB_PASSWORD] = $DB_PASSWORD clear_env = no
Now we can access all the environment variables.
variables_order in the
PHP also has a parameter which defines an order of the variables sources, see the
Sets the order of the EGPCS (Environment, Get, Post, Cookie, and Server) variable parsing. For example, if variables_order is set to “SP” then PHP will create the
superglobals $_SERVERand $_POST, but not create $_ENV, $_GET, and $_COOKIE. Setting to “” means no superglobalswill be set.
Check the current value:
The suggestion was that the issue can be fixed by adding the E (Environment) – but setting
variables_order = "EGPCS" didn’t help.