I am trying to run mysql database in Minikube. Installed Docker, Kubectl and Minikube and made these three files:
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
I applied them in the same order with kubectl apply -f <filename>. But when I get current running pods this one mysql-0 pod has status CrashLoopBackOff.
Tried to find some hints in logs. But it didn't really help.
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.
Tried to delete service, statefulset, pvc, minikube image and container but nothing helps. I am new to kubernetes, could you tell please what I am missing?
As @Adiii mentioned, it may be that the data volume was corrupted. Aside from renaming the template, you can consider deleting the existing StatefulSet and PersistentVolumeClaim and allow Kubernetes to recreate a new one with clean data.
kubectl delete statefulset mysqlkubectl delete pvc data-mysql-0After deleting the StatefulSet and PersistentVolumeClaim, reapply your deployment configurations (secret, service and statefulset) using
kubectl apply -fcommands. It will trigger the creation of a new pod with a fresh instance of MySQL and hopefully resolve the CrashLoopBackOff issue.