Why can't mount pvc dir in pod?

When I deploy a MySQL, it need a data dir. So i monut a pvc. But when the pod start, it is error. The message below.

This is because mysql is probably running as the mysql user, and the pvc is owned by root.

The only way I found to get around this, is to use a sub-directory inside the pvc.

  1. Scale down your mysql workload
  2. Create another container (Ubuntu) in the same namespace, and then mount the pvc in that container.
  3. Exec into the Ubuntu container, and cd to the pvc volume. Create a directory called data, and change the ownership of the directory to the UID that mysql runs as.
  4. Turn off the Ubuntu pod, and then modify the mysql workload’s volume mount and set the Sub Path in Volume to the data directory from step 3 and start mysql.