<p>I am a newbee in Kubernetes/Openshift.</p>

<p>I am trying to update MySQL configuration using configmap. I have the below yaml</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: slave-replcmap
data:
  my.conf: |
    [mysqld]
    server-id=2
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-slave
spec:
  selector:
    matchLabels:
      app: mysql-slave
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql-slave
    spec:
      volumes:
        - name: slave-mysql-persistent-storage
          persistentVolumeClaim:
            claimName: slave-nfs-claim1
        - name: slave-replcmap-vol
          configMap:
            name: slave-replcmap
        - name: slave-mysqlinitconf-vol
          configMap:
            name: slave-mysqlinitcmap
      containers:
      - image: mysql:5.7
        name: mysql-slave
        env:
        - name: MYSQL_SERVER_CONTAINER
          value: mysql
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
              secretKeyRef:
                name: mysql-secret
                key: MYSQL_ROOT_PASSWORD
        - name: MYSQL_DATABASE
          valueFrom:
              secretKeyRef:
                name: mysql-secret
                key: MYSQL_DATABASE
        - name: MYSQL_USER
          valueFrom:
              secretKeyRef:
                name: mysql-secret
                key: MYSQL_USER
        - name: MYSQL_PASSWORD
          valueFrom:
              secretKeyRef:
                name: mysql-secret
                key: MYSQL_PASSWORD
        ports:
        - containerPort: 3306
          name: mysql-slave
        volumeMounts:
        - name: slave-mysql-persistent-storage
          mountPath: /var/lib/mysql
        - name: slave-mysqlinitconf-vol
          mountPath: /docker-entrypoint-initdb.d
        - name: slave-replcmap-vol
          mountPath: /etc/mysql/my.cnf
          subPath: my.conf
</code></pre>

<p>Its updating the config file no issues in that.</p>

<p>But the issue is its deleting the existing content from my.cnf file and adding configmap data. I need to append this configmap data to my.cnf file without deleting the existing data.</p>

<p>Please let me know how i have to modify the yml file for to achieve that.</p>

<p>Thanks in advance.</p>

<p>Your current configuration mount volume directly to <code>my.cnf</code> file - <code>mountPath: /etc/mysql/my.cnf</code>. When you are doing that you are replacing it. <code>subPath</code> property is used to reference the file by key. Similar example can be found <a href="https://carlos.mendible.com/2019/02/10/kubernetes-mount-file-pod-with-configmap/" rel="nofollow noreferrer">here</a>.</p>

<p>Ive deployed this image on my local env. As default <code>my.cnf</code> inside have only some commented text and:</p>

<pre><code>!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
</code></pre>

<p>It means that all configuration files from both folders are included in main configuration.</p>

<p>Instead of mounting main config you might mount this config to one of the folders. For example:</p>

<pre><code>...
          mountPath: /etc/mysql/conf.d/new.conf
          subPath: my.conf
</code></pre>

<p>Ohter ways how to pass <code>ConfigMaps</code> are describe <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">here</a>.</p>

<p>I would also recommended you to check this <a href="https://github.com/helm/charts/tree/master/stable/mysql#custom-mysql-configuration-files" rel="nofollow noreferrer">MySQL HELM Chart</a> about configuration files in <code>MySQL</code>.</p>
