gpt4 book ai didi

mysql - Kubernetes -- Helm -- Mysql Chart 在停止 pod 后丢失存储的数据

转载 作者:行者123 更新时间:2023-11-29 15:34:20 24 4
gpt4 key购买 nike

使用https://github.com/helm/charts/tree/master/stable/mysql (所有代码都在这里),能够将 mysql 作为本地 kubernetes 集群的一部分运行(使用 docker kubernetes)真是太酷了。

问题是,一旦我停止运行 pod,然后再次运行 pod,存储的所有数据现在都消失了。

我的问题是如何保留添加到 mysql pod 的数据?我已经阅读了有关持久卷的内容,并且来自 github 的 mysql helm 示例显示它正在使用 PersistentVolumeClaim。我还在values.yaml 文件上启用了持久性,但我似乎无法拥有保存在数据库中的相同数据。

我的docker kubernetes版本当前是1.14.6。

最佳答案

请验证您的 msql POD 您应该注意volumes 和volumeMount 选项:

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

此外,请验证您的 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>

请运行kubectl描述permanentvolumeclaim/msq-mysql(在您的示例中,您应该更改pvc名称)

您可以注意到 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

我已经创建了一行表,删除了 Pod,然后进行了验证(正如预期的那样,一切都很好):

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

原因:存储的所有数据现在都消失了。

根据 helm chart docs :

The MySQL image stores the MySQL data and configurations at the /var/lib/mysql path of the container.

By default a PersistentVolumeClaim is created and mounted into that directory. In order to disable this functionality you can change the values.yaml to disable persistence and use an emptyDir instead.

主要是 pv、pvc 绑定(bind)有问题。用户定义的或非默认的存储类也可能出现问题。

  • 因此,请如上所述验证 pv,pvc
  • 看看StorageClass

    A claim can request a particular class by specifying the name of a StorageClass using the attribute storageClassName. Only PVs of the requested class, ones with the same storageClassName as the PVC, can be bound to the PVC.

    PVCs don’t necessarily have to request a 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 ""). 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.

关于mysql - Kubernetes -- Helm -- Mysql Chart 在停止 pod 后丢失存储的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58402101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com