【问题标题】:Cannot deploy MySQL pod. --initialize specified but the data directory has files in it无法部署 MySQL pod。 --initialize 指定但数据目录中有文件
【发布时间】:2019-07-27 01:57:37
【问题描述】:

我正在尝试使用 Kubernetes 在 Digital Ocean 上设置一个 MySQL pod。

我一直收到这个错误:

Initializing database
2019-03-05T14:32:58.707421Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-03-05T14:32:58.708753Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2019-03-05T14:32:58.711746Z 0 [ERROR] Aborting

我的 yaml 有很多东西,但对这部分配置感兴趣的行如下。

# ------------------- Persistent Volume Claim ------------------- #

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: test-mysql-volume-claim
  ...
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
  storageClassName: do-block-storage

---

# ------------------- Deployment ------------------- #

kind: Deployment
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
...
spec:
      ...
    spec:
      containers:
        - image: mysql:5.7
          ...
          volumeMounts:
            - name: test-mysql-volume
              mountPath: "/var/lib/mysql"
      volumes:
        - name: test-mysql-volume
          persistentVolumeClaim:
            claimName: test-mysql-volume-claim

---

如果我在部署配置中注释掉 PVC 和与 PVC 相关的行,一切正常。

另外,如果我改变了

mountPath: "/var/lib/mysql"

mountPath: "/data"

它有效。但我显然需要/var/lib/mysql...

这也发生在全新的集群上。

有什么想法吗?

【问题讨论】:

  • 显然它自 2015 年以来一直是 known issue
  • 你能提供kubectl get pv的输出吗
  • 你用的是自己的mysql镜像吗?
  • 有时你只是改变路径而不是克服障碍。
  • 我使用的是最新的官方mysql镜像,但后来我又回到了MariaDB。无论如何,如果可以备份卷,从头开始删除并重新启动是最快的解决方案。

标签: mysql kubernetes digital-ocean persistent-volume-claims


【解决方案1】:

我遇到过这个问题。解决方法是删除 pv 和 pvc 并重新创建它们。

【讨论】:

  • 我已经删除了 minikube。不劳而获
【解决方案2】:

我也遇到过类似的问题。

使用 mysql:5.6 修复它。

更多信息请参考:

https://github.com/docker-library/mysql/issues/69

https://github.com/docker-library/mysql/issues/186

【讨论】:

    【解决方案3】:

    Kubernetes 和 MySQL 5.7 也有这个问题。

    将来自 yosifki 的建议添加到我的容器定义中,一切正常。

    一个新的 ext4 磁盘分区通常不是空的; 有一个 lost+found 目录,已知 mysql 会阻塞该目录。你 可以尝试将 --ignore-db-dir=lost+found 添​​加到 CMD 以了解 确定(来自mysql docs

    这是我的工作 YAML 定义的摘录:

    name: mysql-master
    image: mysql:5.7
    args:
      - "--ignore-db-dir=lost+found"
    

    【讨论】:

      猜你喜欢
      • 2018-10-02
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2011-04-26
      • 1970-01-01
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多