简体   繁体   English

Kubernetes — Helm — Mysql 停止 Pod 后图表丢失存储的数据

[英]Kubernetes — Helm — Mysql Chart loses stored data after stopping pod

Using https://github.com/helm/charts/tree/master/stable/mysql (all the code is here), it is cool being able to run mysql as part of my local kubernetes cluster (using docker kubernetes). Using https://github.com/helm/charts/tree/master/stable/mysql (all the code is here), it is cool being able to run mysql as part of my local kubernetes cluster (using docker kubernetes).

The problem though is that once I stop running the pod, and then run the pod again, all the data that was stored is now gone.但问题是,一旦我停止运行 pod,然后再次运行 pod,所有存储的数据现在都消失了。

My question is how do I keep the data that was added to the mysql pod?我的问题是如何保留添加到 mysql pod 的数据? I have read about persistent volumes, and the mysql helm example from github is showing that it is using PersistentVolumeClaim.我已经阅读了有关持久卷的信息,并且来自 github 的 mysql helm 示例显示它正在使用 PersistentVolumeClaim。 I have also enabled persistence on the values.yaml file, but I cannot seem to have the same data that was saved in the database.我还启用了 values.yaml 文件的持久性,但我似乎无法拥有保存在数据库中的相同数据。

My docker kubernetes version is currently 1.14.6.我的docker kubernetes版本目前是1.14.6。

Please verify your msql POD You should notice volumes and volumesMount options:请验证您的 msql POD 您应该注意 volumes 和 volumesMount 选项:

    volumeMounts:
    - mountPath: /var/lib/mysql
      name: data
.
.
.
  volumes:
  - name: data
    persistentVolumeClaim:
      claimName: msq-mysql

In additions please verify your PersistentVolume and PersistentVolumeClaim, storageClass:此外,请验证您的 PersistentVolume 和 PersistentVolumeClaim、storageClass:

kubectl get pv,pvc,pods,sc:

NAME                                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM               STORAGECLASS   REASON   AGE
persistentvolume/pvc-2c6aa172-effd-11e9-beeb-42010a840083   8Gi        RWO            Delete           Bound    default/msq-mysql   standard                24m

NAME                              STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/msq-mysql   Bound    pvc-2c6aa172-effd-11e9-beeb-42010a840083   8Gi        RWO            standard       24m

NAME                            READY   STATUS    RESTARTS   AGE     IP         NODE                                  NOMINATED NODE   READINESS GATES
pod/msq-mysql-b5c48c888-pz6p2   1/1     Running   0          4m28s   10.0.0.8   gke-te-1-default-pool-36546f4e-5rgw   <none>           <none>

Please run kubectl describe persistentvolumeclaim/msq-mysql (in your example you should change the pvc name)请运行kubectl describe persistentvolumeclaim/msq-mysql (在您的示例中,您应该更改 pvc 名称)

You can notice that pvc was provisioned successfully using gce-pd and mounted by msq-mysql POD.您可以注意到 pvc 已使用gce-pd成功配置并由 msq-mysql POD 挂载。

 Normal     ProvisioningSucceeded  26m   persistentvolume-controller  Successfully provisioned volume pvc-2c6aa172-effd-11e9-beeb-42010a840083 using kubernetes.io/gce-pd
Mounted By:  msq-mysql-b5c48c888-pz6p2

I have created table with on row, deleted the pod and verified after that (as expected everything is alright):我已经在行上创建了表,删除了 pod 并在此之后进行了验证(正如预期的那样,一切都很好):

mysql> SELECT * FROM t;
+------+
| c    |
+------+
| ala  |
+------+
1 row in set (0.00 sec)

Why: all the data that was stored is now gone.原因: all the data that was stored is now gone.

As per helm chart docs :根据舵图文档

The MySQL image stores the MySQL data and configurations at the /var/lib/mysql path of the container. MySQL 镜像将 MySQL 数据和配置存储在容器的 /var/lib/mysql 路径下。

By default a PersistentVolumeClaim is created and mounted into that directory.默认情况下,会创建一个 PersistentVolumeClaim 并将其挂载到该目录中。 In order to disable this functionality you can change the values.yaml to disable persistence and use an emptyDir instead.为了禁用此功能,您可以更改 values.yaml 以禁用持久性并改用 emptyDir。

Mostly there is problem with pv,pvc binding.主要是pv,pvc绑定有问题。 It can be also problem with user defined or non default storageClass.用户定义或非默认存储类也可能存在问题。

  • So please verify pv,pvc as stated above.所以请如上所述验证pv,pvc
  • Take a look at StorageClass看一下StorageClass

    A claim can request a particular class by specifying the name of a StorageClass using the attribute storageClassName.声明可以通过使用属性 storageClassName 指定 StorageClass 的名称来请求特定的 class。 Only PVs of the requested class, ones with the same storageClassName as the PVC, can be bound to the PVC.只有请求的 class 的 PV,与 PVC 具有相同 storageClassName 的 PV,才能绑定到 PVC。

    PVCs don't necessarily have to request a class. PVC 不一定要请求 class。 A PVC with its storageClassName set equal to "" is always interpreted to be requesting a PV with no class, so it can only be bound to PVs with no class (no annotation or one set equal to ""). storageClassName 设置为“”的 PVC 总是被解释为请求一个没有 class 的 PV,因此它只能绑定到没有 class 的 PV(没有注释或一组等于“”)。 A PVC with no storageClassName is not quite the same and is treated differently by the cluster, depending on whether the DefaultStorageClass admission plugin is turned on.一个没有 storageClassName 的 PVC 不太一样,会被集群区别对待,这取决于 DefaultStorageClass 准入插件是否开启。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM