我正在尝试在 Minikube 中运行 mysql 数据库。安装了 Docker、Kubectl 和 Minikube 并制作了这三个文件:
secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: mysql
type: Opaque
data:
MYSQL_ROOT_PASSWORD: MTIzNA==
service.yaml
apiVersion: v1
kind: Service
metadata:
name: app-mysql
labels:
app: mysql
app.kubernetes.io/name: mysql
spec:
ports:
- name: mysql
port: 3306
clusterIP: None
selector:
app: mysql
statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
app.kubernetes.io/name: mysql
serviceName: mysql
replicas: 1
template:
metadata:
labels:
app: mysql
app.kubernetes.io/name: mysql
spec:
containers:
- name: mysql
image: mysql:8.3.0
envFrom:
- secretRef:
name: mysql
ports:
- name: mysql
containerPort: 3306
volumeMounts:
- name: data
mountPath: /var/lib/mysql
subPath: mysql
resources:
requests:
cpu: 500m
memory: 1Gi
livenessProbe:
tcpSocket:
port: 3306
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
readinessProbe:
tcpSocket:
port: 3306
initialDelaySeconds: 5
periodSeconds: 2
timeoutSeconds: 1
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 2Gi
我按照与
kubectl apply -f <filename>
相同的顺序应用它们。但是当我获取当前正在运行的 pod 时,这个 mysql-0 pod 的状态为 CrashLoopBackOff。
尝试在日志中找到一些提示。但其实并没有什么帮助。
2024-02-26 14:59:34+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.3.0-1.el8 started.
2024-02-26 14:59:34+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2024-02-26 14:59:34+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.3.0-1.el8 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2024-02-26T14:59:35.016581Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2024-02-26T14:59:35.321366Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.3.0) starting as process 1
2024-02-26T14:59:35.329645Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-02-26T14:59:35.433059Z 1 [ERROR] [MY-012960] [InnoDB] Cannot create redo log files because data files are corrupt or the database was not shut down cleanly after creating the data files.
2024-02-26T14:59:35.433177Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Generic error.
2024-02-26T14:59:35.855906Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2024-02-26T14:59:35.856297Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2024-02-26T14:59:35.856366Z 0 [ERROR] [MY-010119] [Server] Aborting
2024-02-26T14:59:35.858561Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.3.0) MySQL Community Server - GPL.
2024-02-26T14:59:35.858638Z 0 [System] [MY-015016] [Server] MySQL Server - end.
尝试删除服务、statefulset、pvc、minikube 镜像和容器,但没有任何帮助。我是 kubernetes 新手,你能告诉我我缺少什么吗?
正如@Adiii提到的,可能是数据卷已损坏。除了重命名模板之外,您还可以考虑删除现有的 StatefulSet 和 PersistentVolumeClaim,并允许 Kubernetes 使用干净的数据重新创建一个新的。
kubectl delete statefulset mysql
kubectl delete pvc data-mysql-0
删除 StatefulSet 和 PersistentVolumeClaim 后,使用
kubectl apply -f
命令重新应用部署配置(secret、service 和 statefulset)。它将触发使用新的 MySQL 实例创建新的 pod,并有望解决 CrashLoopBackOff 问题。