<p>I use kustomize as a standalone binary (installed with Homebrew) and have the following <strong>base/kustomization.yaml</strong> file:</p>

<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonLabels:
  app: myservice
  app.kubernetes.io/name: myservice
  service: myservicename
  vendor: mycompany
  app.kubernetes.io/version: "0.1.0"
namePrefix: myservice-
namespace: mynamespace
commonAnnotations:
  supportMail: support@sagich.net
resources:
- pre-install-job.yaml
- cronjob.yaml
- service.yaml
- api.yaml
- worker.yaml
configMapGenerator:
- files:
  - env.properties
  name: configmap
secretGenerator:
- envs:
  - env.properties
  name: env-file-secret
</code></pre>

<p>The <strong>env.properties</strong> file looks like:</p>

<pre><code>APP_NAME="vendor-service-whatever"
APP_ENV="production"
APP_KEY="base64:onKQb...LtU="
APP_DEBUG="false"
APP_URL="https://myamazingsite.com"
LOG_CHANNEL="stderr"
DB_CONNECTION="mysql"
DB_HOST="mariadb-slave"
DB_DATABASE="incredibledb"
</code></pre>

<p>And within my <strong>pre-install-job.yaml</strong> configuration I declare a container like this:</p>

<pre><code>containers:
    - name: "pre-install-job"
      image: "registry.myamazingdomain.com/vendor/whatever/service:latest"
      imagePullPolicy: "Always"
      args:
        - /bin/bash
        - -c
        - php artisan migrate --force -v;
      envFrom:
        - configMapRef:
            name: "configmap"
</code></pre>

<p>The problem: the environment variables are not available within the pod/container. I also tried to mount the configmap as .env file within the container but no success as well. Maybe someone can point me in the right direction.</p>

<p>The resulting error is: </p>

<blockquote>
  <p>Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002]
  Connection refused (SQL: select * from information_schema.tables where
  table_schema = forge and table_name = migrations and table_type =
  'BASE TABLE')</p>
</blockquote>

<p>Because the default values are used rather than the ones defined within the environment variables.</p>

<p>Ok, I tried again to mount the confirmap as .env file within the project. But this time I also provided a subPath definition. Now it works and the "php artisan migrate" command runs successful.</p>

<pre><code>  volumes:
    - name: "env-volume"
      configMap:
        name: "configmap"
  containers:
    - name: "pre-install-job"
      image: "registry.myamazingdomain.com/vendor/whatever/service:latest"
      imagePullPolicy: "Always"
      args:
        - /bin/bash
        - -c
        - php artisan migrate --force -v;
      volumeMounts:
        - name: "env-volume"
          mountPath: "/var/www/html/app/.env"
          subPath: "env.properties"
</code></pre>

<p>The subPath definition is part of the configMapGenerator:</p>

<pre><code>configMapGenerator:
  - name: configmap
    files:
      - env.properties
</code></pre>

<p>E.g.:</p>

<pre><code>$ kubectl -n mynamespace get configmap blablubb-configmap-8c4m97m94g -o yaml

apiVersion: v1
data:
  env.properties: |
    APP_NAME="vendor-service-whatever"
    APP_ENV="production"
    APP_KEY="base64:onKQb...LtU="
    APP_DEBUG="false"
</code></pre>
