<p>I'm trying to get logs from mysql container. I have to set the variable :</p>
<blockquote>
<p>&quot;SET GLOBAL general_log= 1&quot;</p>
</blockquote>
<p>I'm trying to set the variable by using kubernetes poststart but it's not working . Here is my config :</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  serviceName: mysql
  replicas: 1
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.7
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-secret
              key: password
        lifecycle:
          postStart:
            exec:
              command: [&quot;/bin/bash&quot;, &quot;-c&quot;,&quot;/etc/init.d/mysql start&quot;, &quot;mysql -p${MYSQL_ROOT_PASSWORD} &lt;&lt;&lt; 'SET GLOBAL general_log= 1;'&quot; ]
 
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql  #The path used to mount the hostPath share inside the pod.
   
  - name: log-mysql
    image: alpine
    args: [/bin/sh, -c, &quot;tail -n+1 -f /tmp/logs/mysql-0.log&quot;] 
    volumeMounts:
    - name: mysql-persistent-storage
      mountPath: /tmp/logs
  
  volumes:                    
  - name: mysql-persistent-storage
    persistentVolumeClaim:
      claimName: mysql-pvclaim
  
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
</code></pre>
<p>I don't have any error when I apply this config but the value of the general_log variable stay OFF and doesn't turn ON.</p>
<p>PS: when I connect to my pod and manually type</p>
<blockquote>
<p>mysql -p${MYSQL_ROOT_PASSWORD} &lt;&lt;&lt; 'SET GLOBAL general_log= 1;'</p>
</blockquote>
<p>the value of the variable turn ON. I don't understand why it's not working using Poststart.</p>
<p>Can I have some help ?
Thanks</p>

adam b
<p>The command is excuted too early, right after the container is created and before mysqld is ready to accept commands.</p>
<p>You can use a different method to achieve your goal:</p>
<ul>
<li>proivde a container command and use &quot;--general-log=1&quot;</li>
<li>create a custom custom.cnf file with the settings and volume mount it to /etc/mysql/conf.d</li>
</ul>
