在AWS上装载卷的Mysql k8s Pod失败

时间:2018-04-16 09:59:28

标签: mysql amazon-web-services kubernetes

我尝试使用mount-volume的mysql来获取/var/lib/mysql

之间的持久性
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
 ---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: mysql
spec:
 selector:
   matchLabels:
     app: mysql
 strategy:
   type: Recreate
 template:
   metadata:
     labels:
       app: mysql
   spec:
    containers:
    - image: mysql:5.6
      name: mysql
      env:
      - name: MYSQL_ROOT_PASSWORD
        value: password
      ports:
      - containerPort: 3306
        name: mysql
      volumeMounts:
      - name: mysql-persistent-storage
        mountPath: /var/lib/mysql
     volumes:
     - name: mysql-persistent-storage
       persistentVolumeClaim:
         claimName: mysql-pv-claim

kubelogs如下

sh-3.2# kubectl logs acds-catchup-db-6f7d4b6c5b-2jwds  
Initializing database
2018-04-16T09:23:18.020740Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-16T09:23:18.022014Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2018-04-16T09:23:18.022037Z 0 [ERROR] Aborting

在调查时,我在MountVolume中找到了一个名为Lost+Found的目录。

可以帮我解决这个问题

1 个答案:

答案 0 :(得分:1)

该目录始终存在于卷的根路径中,因此您无法将其删除。

您有两种选择如何解决它:

  1. --ignore-db-dir=lost+found选项添加到MySQL配置中。我认为这是更好的方式。
  2. 将数据库目录设置为卷内的路径,而不是卷的根路径。您可以通过--datadir=选项指定数据库目录。
  3. 以下是args设置的示例:

    spec:
      containers:
      - name: mysql
        image: mysql:5.6
        args: ["--ignore-db-dir=lost+found"]