Mysql kubernetes pod abort execution - CrashLoopbackOff

wgx48brx  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(1)|浏览(112)

我有一个主节点和一个工作节点。我正在为mysql运行一个带有pv/pvc/persistant卷声明的yaml。日志显示mysql找到(每次重启时)数据库保存的前一个目录(用于持久化)。即使我删除了文件/directory /var/lib/mysql,mysql服务器仍然以某种方式检测到它。下面是日志:

] /usr/sbin/mysqld (mysqld 8.0.33) initializing of server in progress as process 10
2023-06-29T16:30:30.612865Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2023-06-29T16:30:30.612875Z 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.
2023-06-29T16:30:30.614055Z 0 [ERROR] [MY-010119] [Server] Aborting

字符串
我尝试了--ignore-db-dir=lost+foundfsGgroup: 1000,因为我在谷歌上找到了这些解决方案,但它们不适合我。这是我的yaml文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      securityContext:
        fsGroup: 10000
      tolerations:
        - key: "app"
          operator: "Equal"
          value: "mysql"
          effect: "NoSchedule"
      containers:
        - name: mysql
          image: mysql:latest
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: mypassword
          ports:
            - containerPort: 3306
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
          args:
            - --datadir=/var/lib/mysql
            - "--ignore-db-dir=lost+found"
            - --initialize
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-pv
        - name: mysql-data
          emptyDir: {}

enxuqcxy

enxuqcxy1#

我通过逐行检查yaml清单并将配置减少到以下内容来解决这个问题:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-pod
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mysql:latest
          ports:
            - containerPort: 3306
          envFrom:
            - secretRef:
                  name: app-mysql-secret
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-pvc

字符串

相关问题