<p>I successfully, recreated <a href="https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/" rel="nofollow noreferrer">Single-Instance Stateful Application</a> tutorial. Naturally, I'd like to create a periodic backup of all databases. I found this <a href="https://medium.com/@madushagunasekara/export-mysql-db-dump-from-kubernetes-pod-and-restore-mysql-db-on-kubernetes-pod-6f4ecc6b5a64" rel="nofollow noreferrer">article</a> that explains how to make a backup. Unfortunately, it does not work for me. The command that I am running looks like this </p>

<pre class="lang-sh prettyprint-override"><code>$  kubectl exec -n &lt;namespace&gt; &lt;pod&gt; -- mysqldump -u root -p$MYSQL_ROOT_PASSWORD --all-databases &gt; /var/lib/mysql/backup/alldbs.sql
</code></pre>

<p>I found error(s). Backup was not working for two reasons. </p>

<p>1st, incorrect <strong>semantic</strong>. Instead of using <code>kubectl exec -n &lt;namespace&gt; &lt;pod&gt; mysqldump -u root -p$MYSQL_ROOT_PASSWORD --all-databases &gt; dump.sql</code> as article mentions. I had to use a syntax described in <a href="https://hub.docker.com/_/mysql" rel="nofollow noreferrer">mysql dockerhub</a> documentation that looks like this <code>kubectl exec -n &lt;namespace&gt; &lt;pod&gt; -- sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' &gt; dump.sql</code> </p>

<p>2nd, incorrect <strong>path assumption</strong>.  I assumed that <code>dump.sql</code> was created on the pod/container filesystem so, I expected to see backup file inside container. Instead backup file was created relative to your host machine filesystem not pod/container.</p>
