<p>my deployment.yml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: kazi-db
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - image: mysql/mysql-server:8.0
          name: mysql
          imagePullPolicy: IfNotPresent
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: kazi-db-secret
                  key: root-password
            - name: MYSQL_DATABASE
              valueFrom:
                secretKeyRef:
                  name: kazi-db-secret
                  key: kazi-db-name
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  name: kazi-db-secret
                  key: kazi-db-user
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: kazi-db-secret
                  key: kazi-db-user-pwd
          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
            - name: mysql-initdb
              mountPath: /docker-entrypoint-initdb.d
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-pv-claim
        - name: mysql-initdb
          configMap:
            name: kazi-initdb
</code></pre>
<p>My persistence-volume:</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  persistentVolumeReclaimPolicy:  Delete #only for test
  storageClassName: manual
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: &quot;/var/lib/mysql&quot;
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
</code></pre>
<p>The error:</p>
<pre><code>kubectl logs kazi-db-6c4dd7f68f-5rnv7
[Entrypoint] MySQL Docker Image 8.0.28-1.2.7-server
[Entrypoint] Initializing database
2022-01-21T10:46:47.114000Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 17
2022-01-21T10:46:47.114940Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2022-01-21T10:46:47.114944Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2022-01-21T10:46:47.115128Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-01-21T10:46:47.115243Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.28)  MySQL Community Server - GPL.
</code></pre>
<p>kubectl describe returns</p>
<pre><code>kubectl describe pod kazi-db-6c4dd7f68f-5rnv7
Name:         kazi-db-6c4dd7f68f-5rnv7
Namespace:    default
Priority:     0
Node:         docker-desktop/192.168.65.4
Start Time:   Fri, 21 Jan 2022 11:46:01 +0100
Labels:       app=mysql
              pod-template-hash=6c4dd7f68f
Annotations:  &lt;none&gt;
Status:       Running
IP:           10.1.7.158
IPs:
  IP:           10.1.7.158
Controlled By:  ReplicaSet/kazi-db-6c4dd7f68f
Containers:
  mysql:
    Container ID:   docker://b6cf1c51bb662c923b122651dc0288d517f4de6ae3312e854aedb4b22d4924ad
    Image:          mysql/mysql-server:8.0
    Image ID:       docker-pullable://mysql/mysql-server@sha256:6fca505a0d41c7198b577628584e01d3841707c3292499baae87037f886c9fa2
    Port:           3306/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Fri, 21 Jan 2022 11:57:03 +0100
      Finished:     Fri, 21 Jan 2022 11:57:04 +0100
    Ready:          False
    Restart Count:  7
    Environment:
      MYSQL_ROOT_PASSWORD:  &lt;set to the key 'root-password' in secret 'kazi-db-secret'&gt;     Optional: false
      MYSQL_DATABASE:       &lt;set to the key 'kazi-db-name' in secret 'kazi-db-secret'&gt;      Optional: false
      MYSQL_USER:           &lt;set to the key 'kazi-db-user' in secret 'kazi-db-secret'&gt;      Optional: false
      MYSQL_PASSWORD:       &lt;set to the key 'kazi-db-user-pwd' in secret 'kazi-db-secret'&gt;  Optional: false
    Mounts:
      /docker-entrypoint-initdb.d from mysql-initdb (rw)
      /var/lib/mysql from mysql-persistent-storage (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-rnwk8 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  mysql-persistent-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  mysql-pv-claim
    ReadOnly:   false
  mysql-initdb:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      kazi-initdb
    Optional:  false
  default-token-rnwk8:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-rnwk8
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  &lt;none&gt;
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                  From               Message
  ----     ------     ----                 ----               -------
  Normal   Scheduled  11m                  default-scheduler  Successfully assigned default/kazi-db-6c4dd7f68f-5rnv7 to docker-desktop
  Normal   Pulled     9m48s (x5 over 11m)  kubelet            Container image &quot;mysql/mysql-server:8.0&quot; already present on machine
  Normal   Created    9m48s (x5 over 11m)  kubelet            Created container mysql
  Normal   Started    9m47s (x5 over 11m)  kubelet            Started container mysql
  Warning  BackOff    75s (x48 over 11m)   kubelet            Back-off restarting failed container

</code></pre>
<p>I tried it with <code>args: -ignore-db-dir=lost+found</code> but it is no more available in mysql.8</p>
<pre><code>[Entrypoint] MySQL Docker Image 8.0.28-1.2.7-server
2022-01-21T10:18:15.004191Z 0 [ERROR] [MY-000067] [Server] unknown variable 'ignore-db-dir=lost+found'.
2022-01-21T10:18:15.004338Z 0 [ERROR] [MY-010119] [Server] Aborting
[Entrypoint] ERROR: Unable to start MySQL. Please check your configuration.
</code></pre>
<p>One possibility in to change to volume path but i want to use <code>/var/lib/mysql</code></p>
<p>I have removed mysql-server locally. I removed the docker image too but same issue.</p>

<p>If you tried multiple times i would suggest trying deleting everything first and applying changes again mainly PV and PVC. There could be changes in PVC, PVC old files exist which causes issues.</p>
<p>So try by deploying everything again and also check MySQL image you are using doesn't have any issue and running without PVC first also.</p>
<p>Try and update necessary things like an image of MySQL only</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: &quot;/mnt/data&quot;
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
</code></pre>
<p><strong>Deployment</strong> and <strong>service</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
          # Use secret in real usage
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
</code></pre>
<p>Reference document : <a href="https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/</a></p>
