<p>Just for training purpose, I'm trying to inject those env variables with this ConfigMap in my Wordpress and Mysql app by using a File with a Volume.</p>
<pre class="lang-yaml prettyprint-override"><code>---
apiVersion: v1
kind: ConfigMap
metadata:
  name: wordpress-mysql
  namespace: ex2
data:
  wordpress.conf: |
    WORDPRESS_DB_HOST mysql
    WORDPRESS_DB_USER admin
    WORDPRESS_DB_PASSWORD &quot;1234&quot;
    WORDPRESS_DB_NAME wordpress
    WORDPRESS_DB_PREFIX wp_
  mysql.conf: |
    MYSQL_DATABASE wordpress
    MYSQL_USER admin
    MYSQL_PASSWORD &quot;1234&quot;
    MYSQL_RANDOM_ROOT_PASSWORD &quot;1&quot;
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: mysql
  name: mysql
  namespace: ex2
spec:
  ports:
    - port: 3306
      protocol: TCP
      targetPort: 3306
  selector:
    app: mysql
  type: ClusterIP

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
  namespace: ex2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - image: mysql:5.6
          name: mysql
          volumeMounts:
            - name: config
              mountPath: &quot;/etc/env&quot;
              readOnly: true
          ports:
            - containerPort: 3306
              protocol: TCP
      volumes:
      - name: config
        configMap:
          name: wordpress-mysql
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: wordpress
  name: wordpress
  namespace: ex2
spec:
  ports:
    - nodePort: 30999
      port: 80
      protocol: TCP
      targetPort: 80
  selector:
    app: wordpress
  type: NodePort

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
  namespace: ex2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      containers:
        - image: wordpress
          name: wordpress
          volumeMounts:
            - name: config
              mountPath: &quot;/etc/env&quot;
              readOnly: true
          ports:
            - containerPort: 80
              protocol: TCP
      volumes:
        - name: config
          configMap:
            name: wordpress-mysql


</code></pre>
<p>When I deploy the app the mysql pod fails with this error:<br />
<code>kubectl -n ex2 logs mysql-56ddd69598-ql229</code></p>
<blockquote>
<p>2020-12-26 19:57:58+00:00 [ERROR] [Entrypoint]: Database is
uninitialized and password option is not specified
You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD</p>
</blockquote>
<p>I don't understand because I have specified everything in my configMap. I also have tried by using <code>envFrom</code> and <code>Single Env Variables</code> and it works just fine. I'm just having an issue with <code>File in a Volume</code></p>

<p>@DavidMaze is correct; you're mixing two useful features.</p>
<p>Using <code>test.yaml</code>:</p>
<pre><code>---
apiVersion: v1
kind: ConfigMap
metadata:
  name: wordpress-mysql
data:
  wordpress.conf: |
    WORDPRESS_DB_HOST mysql
    WORDPRESS_DB_USER admin
    WORDPRESS_DB_PASSWORD &quot;1234&quot;
    WORDPRESS_DB_NAME wordpress
    WORDPRESS_DB_PREFIX wp_
  mysql.conf: |
    MYSQL_DATABASE wordpress
    MYSQL_USER admin
    MYSQL_PASSWORD &quot;1234&quot;
    MYSQL_RANDOM_ROOT_PASSWORD &quot;1&quot;
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  labels:
    app: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
        - image: busybox
          name: test
          args:
          - ash
          - -c
          - while true; do sleep 15s; done
          volumeMounts:
            - name: config
              mountPath: &quot;/etc/env&quot;
              readOnly: true
      volumes:
      - name: config
        configMap:
          name: wordpress-mysql
</code></pre>
<p>Then:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl apply --filename=./test.yaml

kubectl exec --stdin --tty deployment/test -- ls  /etc/env
mysql.conf      wordpress.conf

kubectl exec --stdin --tty deployment/test -- more /etc/env/mysql.conf
MYSQL_DATABASE wordpress
MYSQL_USER admin
MYSQL_PASSWORD &quot;1234&quot;
MYSQL_RANDOM_ROOT_PASSWORD &quot;1&quot;
</code></pre>
<blockquote>
<p><strong>NOTE</strong> the files are missing (and should probably include) <code>=</code> between the variable and its value e.g. <code>MYSQL_DATABASE=wordpress</code></p>
</blockquote>
<p>So, what you have is a ConfigMap that represents 2 files (<code>mysql.conf</code> and <code>wordpress.conf</code>) and, if you use e.g. <code>busybox</code> and mount the ConfigMap as a volume, you can see that it includes 2 files and that the files contain the configurations.</p>
<p>So, <strong>if</strong> you can run e.g. WordPress or MySQL and pass a configuration file to them, you're good but what you probably want to do is reference the ConfigMap entries as environment variables, per @DavidMaze suggestion, i.e. run Pods with environment variables set by the ConfigMap entries, i.e.:</p>
<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-using-configmap-data" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-using-configmap-data</a></p>
