作者:家居生活我最大_386 | 来源:互联网 | 2023-06-18 16:29
最近在k8s上面运行mysql报错$kubectl-ndevopslogsmysql-679745f64f-4cdzc2021-12-1001:18:26+00:00[Note][
最近在 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