Docker 桌面上的 K8s 本地持久卷在 Docker 桌面重启后丢失数据
K8s local Persistent Volume on Docker Desktop loses data after Docker Desktop restart
我在本地 K8s 集群中遇到 PersistentVolume 问题。当我重新启动 PC 或关闭并打开桌面时 Docker 我的 PV 中的数据丢失了。
这是我的 PV 配置:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pvolume
labels:
name: pvolume
spec:
storageClassName: manual
volumeMode: Filesystem
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
是否有可能保留数据而不使用外部 PV 提供程序(如 GCP volume)?
解决方案:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pvolume
labels:
name: pvolume
spec:
capacity:
storage: 3Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: your-local-storage-class-name
local:
path: /c/yourDir
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- docker-desktop
正如我在评论部分提供的链接中提到的那样 - 阅读更多:docker-desktop-pv, docker-desktop-pv-local - solution/workaround is to use different volume type. Change hostPath volume to local. Your PV yaml 文件应如下所示:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pvolume
labels:
name: pvolume
spec:
storageClassName: manual
volumeMode: Filesystem
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
local:
path: /c/yourDirectory
local.path
直接显示您引用 Windows 文件夹的位置,以便您可以在 Windows 机器上本地连接 PersistentVolume。
参见:types-of-pv。
我在本地 K8s 集群中遇到 PersistentVolume 问题。当我重新启动 PC 或关闭并打开桌面时 Docker 我的 PV 中的数据丢失了。
这是我的 PV 配置:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pvolume
labels:
name: pvolume
spec:
storageClassName: manual
volumeMode: Filesystem
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
是否有可能保留数据而不使用外部 PV 提供程序(如 GCP volume)?
解决方案:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pvolume
labels:
name: pvolume
spec:
capacity:
storage: 3Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: your-local-storage-class-name
local:
path: /c/yourDir
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- docker-desktop
正如我在评论部分提供的链接中提到的那样 - 阅读更多:docker-desktop-pv, docker-desktop-pv-local - solution/workaround is to use different volume type. Change hostPath volume to local. Your PV yaml 文件应如下所示:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pvolume
labels:
name: pvolume
spec:
storageClassName: manual
volumeMode: Filesystem
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
local:
path: /c/yourDirectory
local.path
直接显示您引用 Windows 文件夹的位置,以便您可以在 Windows 机器上本地连接 PersistentVolume。
参见:types-of-pv。