无法将MySQL数据卷安装到Kubernetes Minikube pod

时间:2016-08-29 20:26:34

标签: docker kubernetes

我正在尝试通过Minikube与Kubernetes建立开发环境。我使用Docker for Mac成功地将相同的卷安装到同一图像上的相同数据目录上,但我遇到了Minikube的问题。

相关文件和日志: db-pod.yml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    name: msyql
  name: db
  namespace: default
spec:
  containers:
    - name: mysqldev
      image: mysql/mysql-server:5.6.32
      ports:
        - containerPort: 3306
          hostPort: 3306
      volumeMounts:
        - mountPath: "/var/lib/mysql"
          name: volumesnew
  volumes:
    - name: volumesnew
      hostPath:
        path: "/Users/eric/Volumes/mysql"

kubectl get pods

NAME      READY     STATUS    RESTARTS   AGE
db        0/1       Error     1          3s

kubectl logs db

2016-08-29 20:05:55 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-08-29 20:05:55 0 [Note] mysqld (mysqld 5.6.32) starting as process 1 ...
2016-08-29 20:05:55 1 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive

kubectl describe pods db

Name:       db
Namespace:      default
Node:       minikubevm/10.0.2.15
Start Time:     Wed, 31 Aug 2016 07:48:39 -0700
Labels:     name=msyql
Status:     Running
IP:         172.17.0.3
Controllers:    <none>
Containers:
  mysqldev:
    Container ID:       docker://af0937edcd9aa00ebc278bc8be00bc37d60cbaa403c69f71bc1b378182569d3d
    Image:          mysql/mysql-server:5.6.32
    Image ID:       docker://sha256:0fb418d5a10c9632b7ace0f6e7f00ec2b8eb58a451ee77377954fedf6344abc5
    Port:           3306/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:        1
      Started:      Wed, 31 Aug 2016 07:48:42 -0700
      Finished:     Wed, 31 Aug 2016 07:48:43 -0700
    Ready:          False
    Restart Count:      1
    Environment Variables:
      MYSQL_ROOT_PASSWORD:      test
Conditions:
  Type      Status
  Initialized   True
  Ready         False
  PodScheduled  True
Volumes:
  volumesnew:
    Type:       HostPath (bare host directory volume)
    Path:       /Users/eric/Volumes/newmysql
  default-token-il74e:
    Type:       Secret (a volume populated by a Secret)
    SecretName: default-token-il74e
QoS Tier:       BestEffort
Events:
  FirstSeen     LastSeen        Count   From            SubobjectPath           Type        Reason      Message
  ---------     --------        -----   ----            -------------           --------        ------      -------
  7s        7s          1       {default-scheduler }                    Normal      Scheduled       Successfully assigned db to minikubevm
  6s        6s          1       {kubelet minikubevm}    spec.containers{mysqldev}       Normal      Created     Created container with docker id 568f9112dce0
  6s        6s          1       {kubelet minikubevm}    spec.containers{mysqldev}       Normal      Started     Started container with docker id 568f9112dce0
  6s        4s          2       {kubelet minikubevm}    spec.containers{mysqldev}       Normal      Pulled      Container image "mysql/mysql-server:5.6.32" already present on machine
  4s        4s          1       {kubelet minikubevm}    spec.containers{mysqldev}       Normal      Created     Created container with docker id af0937edcd9a
  4s        4s          1       {kubelet minikubevm}    spec.containers{mysqldev}       Normal      Started     Started container with docker id af0937edcd9a
  3s        2s          2       {kubelet minikubevm}    spec.containers{mysqldev}       Warning     BackOff     Back-off restarting failed docker container
  3s        2s          2       {kubelet minikubevm}                    Warning     FailedSync      Error syncing pod, skipping: failed to "StartContainer" for "mysqldev" with CrashLoopBackOff: "Back-off 10s restarting failed container=mysqldev pod=db_default(012d5178-6f8a-11e6-97e8-c2daf2e2520c)"

我能够将数据目录从主机安装到测试目录中的容器中,但是我无法安装到MySQL数据目录。此外,我尝试使用相应的MySQL环境变量设置将空目录挂载到容器的数据目录,在Docker for Mac中允许我在新目录中执行SQL转储,但我在Minikube中看到相同的错误。

如果想到可能是什么原因,或者如果我没有将我的开发环境设置为首选的Kubernetes / Minikube方式,请分享您的想法。

1 个答案:

答案 0 :(得分:1)

我能够通过以下方式解决这个问题:

echo "/Users -network 192.168.99.0 -mask 255.255.255.0 -alldirs -maproot=root:wheel" | sudo tee -a /etc/exports
sudo nfsd restart
minikube start
minikube ssh -- sudo umount /Users
minikube ssh -- sudo /usr/local/etc/init.d/nfs-client start
minikube ssh -- sudo mount 192.168.99.1:/Users /Users -o rw,async,noatime,rsize=32768,wsize=32768,proto=tcp

我在VirtualBox中运行Minikube。我不知道这是否适用于其他VM驱动程序 - xhyve等。

参考:https://github.com/kubernetes/minikube/issues/2

编辑:我应该提一下,这适用于minikube v0.14.0。