I have one laravel docker container which is build with a custom nginx + php-fpm docker image.
I have deployed successfully to a k8s cluster and can access properly, also logging into the pod and running env I can see all the environment variables being set successfully from my k8s configmap
In the laravel code I read the environment variables like this:
For example at SomeController.php have the following code:
$apiCode = env('API_CODE');
// also tried like this $apiCode = getenv('API_CODE'); still not successful in fetching
My problem and this question is that the env vars are always read empty inside the php code even though inside the pod with env command I can see them properly set, somehow the php code cannot find them.
(I am not caching laravel config so that case we can exclude, also tried with the command php artisan config:clear beforehand, still same result cannot fetch the env vars within the php)
In the kubernetes definition yml I attach the configmap to env variables like below and see them defined properly inside pod:
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
labels:
tier: api
spec:
replicas: 1
selector:
matchLabels:
tier: api
template:
metadata:
labels:
tier: api
spec:
containers:
- name: api
image: somenging-fpm-image:latest
ports:
- containerPort: 80
envFrom:
- configMapRef:
name: api-config-env-file
For the moment I am lost and without any idea why this might happen.
I thought initially that maybe configmap was created late after pod started (php fpm somehow process then did not pick on start the env)
To verify and exclude that case, I destroyed the pod and recreated the deployment+pod in order to use the already existing configmap, and still the result was the same php did not pick up the env vars that were present in pod
I could log into pod by kubectl exec -it [podnamehere] /bin/bash and run env there and could see properly env vars set from my configmap api-config-env-file, but the code would always have them empty not be able to read them