I have created MySql container in kubernetes Pod by using YAML deployment file.
I am able to execute the mysql queries on that container and created few databases and tables with data in it.
But when I make some changes in other code of project not related to kubernetes files and deployed it.
On the recreation of pod all my previous databases are deleted from MySql container. I have also given mount path to mount the PVC to my container.
So my question is how to store the databases permanently so that on recreation of pod it will not delete the database and able to access that databases through newly created pod
2
Answers
Is PVC mounted on the MySQL data directory like /var/libe/mysql or If you are having different data directory, Use appropriate mount path for PVC where mysql stores data. You can find the sample spec for mysql deployment
here
It’s always best practice to run the single container inside the single POD.
You have to use the PVC and PV to store the data so that data get persistent even if the POD restarts or we update the YAML change to POD definition.
For example here for MySQL database
Ref : https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/