gpt4 book ai didi

mysql - 通过集群重启使用持久卷为MySQL pod持久化数据

转载 作者:行者123 更新时间:2023-12-02 12:25:00 24 4
gpt4 key购买 nike

我正在尝试在Kubernetes上部署MySQL部署,并希望保留数据。我目前能够在pod的整个生命周期中保留数据(先删除Kubectl,然后创建Kubectl)。但是,我无法通过群集重新启动来保留数据。知道为什么会这样吗?
persistent-volume.yml

apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv-volume
spec:
storageClassName: hostpath
persistentVolumeReclaimPolicy: Retain
capacity:
storage: 100Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
持久卷claim.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
spec:
storageClassName: hostpath
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
mysql-deployment.yml
kind: StatefulSet
metadata:
name: powerplus-db
spec:
serviceName: powerplus-db
selector:
matchLabels:
app: powerplus-db
template:
metadata:
labels:
app: powerplus-db
spec:
containers:
- name: powerplus-db
image: mysql:8.0.21
env:
- name: MYSQL_ROOT_PASSWORD
value: password
- name: MYSQL_DATABASE
value: powerplus
ports:
- containerPort: 3306
name: powerplus-db
volumeMounts:
- mountPath: /var/lib/mysql
name: mysql-persistent-storage
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim```

最佳答案

this official guide中,尤其是在有关Create PersistentVolumeClaims and PersistentVolumes的段落中很好地描述了这种情况:

Warning: In local clusters, the default StorageClass uses the hostPathprovisioner. hostPath volumes are only suitable for development andtesting. With hostPath volumes, your data lives in /tmp on the nodethe Pod is scheduled onto and does not move between nodes. If a Poddies and gets scheduled to another node in the cluster, or the node isrebooted, the data is lost.

HostPath仅用于单节点测试目的。您想使用其他类型的 PersisstentVolume
您可以找到有关 PersistentVolumes类型 here的更多详细信息。

关于mysql - 通过集群重启使用持久卷为MySQL pod持久化数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64392262/

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