Laravel ENV variable collision in a Kubernetes cluster Laravel ENV variable collision in a Kubernetes cluster kubernetes kubernetes

Laravel ENV variable collision in a Kubernetes cluster


@Florian's reply to himself on github:

My solution was to change the config in config/database.php like that:

'redis' => [    'client' => 'predis',    'default' => [        'scheme' => 'tcp',        'host' => env('REDIS_SERVICE_HOST', env('REDIS_HOST','127.0.0.1')),        'port' => env('REDIS_SERVICE_PORT', env('REDIS_PORT',6379)),        'password' => env('REDIS_PASSWORD', null),        'database' => 0,    ],],

Now, the config checks first, if the REDIS_SERVICE_HOST and REDIS_SERVICE_PORT are present as ENV variable. This is the case, if you have a container in a docker/kubernetes cluster which is called REDIS.

Advantage of this solution is, that REDIS_SERVICE_HOST returns the IP address of the container, not a hostname. Therefore, there is no dns resolution anymore for this internal connections.