k8s 運行 mysql 報錯 --initialize specified but the data directory has files in it


最近在 k8s 上面運行 mysql 報錯

$ kubectl -n devops logs mysql-679745f64f-4cdzc 
2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Initializing database files
2021-12-10T01:18:26.354668Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-12-10T01:18:26.355814Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2021-12-10T01:18:26.355851Z 0 [ERROR] Aborting

提示數據目錄非空,什么鬼,好吧,我們先運行一個 initContainers 看看目錄里面到底有啥

      initContainers:
      - name: init-data-path
        image: hub.leffss.com/library/busybox:v1.28.4
        imagePullPolicy: IfNotPresent
        command: ["sh", "-c", "ls -l /var/lib/mysql"]
        securityContext:
          privileged: true
        volumeMounts:
        - name: mysql-pvc
          mountPath: /var/lib/mysql
# 查看 initContainers 的日志
kubectl -n devops logs mysql-679745f64f-4cdzc -c init-data-path
total 16
drwx------    2 root     root         16384 Dec 10 01:18 lost+found

原來是 lost+found,這個目錄啥東西,有啥用這里就不介紹了,自己百度,反正以我工作這么多年的經驗來說,沒啥用

為啥會有這個目錄呢?因為我們 pvc 使用的是 ceph 的 rbd,每次創建時都會格式化,就會產生這個,如果使用 cephfs 或者 nfs 的話,不會有這個目錄

好吧,既然沒用,那就盤它:

      initContainers:
      - name: init-data-path
        image: hub.leffss.com/library/busybox:v1.28.4
        imagePullPolicy: IfNotPresent
        command: ["sh", "-c"]
        args:
        - |
          if [[ -d /var/lib/mysql/lost+found ]];then
            echo "rm -rf /var/lib/mysql/lost+found"
            rm -rf /var/lib/mysql/lost+found
          else
            echo "/var/lib/mysql/lost+found not exist"
          fi
        securityContext:
          privileged: true
        volumeMounts:
        - name: mysql-pvc
          mountPath: /var/lib/mysql

刪除,整個世界清凈了!

$ kubectl -n devops get pod
NAME                     READY   STATUS    RESTARTS   AGE
mysql-774868b794-8d258   1/1     Running   0          13m
redis-7b4c48fd74-g99zg   1/1     Running   0          32m


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM