如何在 Homelab 中使用 Shared Drive 作为多个 Kubernetes PV
How to use Shared Drive as multiple Kubernetes PV in Homelab
我有家庭实验室。
Window Host
和 Vmware workstation
1 Master Node
3 Worker Nodes
所有节点都安装了 windows 驱动器并且可用 /external
我想要 运行 多个工具,如 jenkins、nexus、nessus 等,并希望在外部驱动器中使用持久卷,这样即使我创建了新的 EKS 集群,卷也会永远保留在那里,我可以重用它们
所以我想知道最好用什么
- 我可以创建单个
hostPath
PV,然后每个 pod 可以从中申请 exmaple 20GB
- 或者我必须使用
hostPath
为每个 pod 创建 PV,然后在 POD 中声明它
那么PV和PVC有1:1关系吗?或者一个 PV 可以在 diff 文件夹中有多个声明?
- 此外,如果重新创建 Cluster 并从相同的 hostPath 创建 PV,我的数据会在那里吗?
您可以使用 local
音量而不是 hostPath
来试验 SC/PVC/PC。首先,创建 StorageClass:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: shared
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
然后在每个节点上提供可用的 PersistentVolume ,这是一个节点的示例:
apiVersion: v1
kind: PersistentVolume
metadata:
name: shared-pv-1
spec:
capacity:
storage: 20Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: shared
local:
path: <path to the shared folder>
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- <your node name>
以及允许您在 pod 中安装已配置卷的声明:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: shared-pv-1
spec:
storageClassName: shared
volumeMode: Filesystem
resources:
requests:
storage: 20Gi
accessModes:
- ReadWriteOnce
这是一个装载卷并向其写入数据的示例 pod:
apiVersion: v1
kind: Pod
metadata:
name: busybox-1
spec:
restartPolicy: Never
volumes:
- name: shared
persistentVolumeClaim:
claimName: shared-pv-1
containers:
- name: busybox-1
image: busybox
imagePullPolicy: IfNotPresent
volumeMounts:
- name: shared
mountPath: /data
command: ["ash","-c","while :; do echo \"$(date)\tmessage from busybox-1.\" >> /data/message.txt; sleep 1; done"]
对于local volume, by default the data written will require manual cleanup and deletion. A positive side effect for you as you would like the content to persist. If you like go further to experiment CSI alike local volume, you can use this Local Persistence Volume Static Provisioner。
我有家庭实验室。
Window Host
和 Vmware workstation
1 Master Node
3 Worker Nodes
所有节点都安装了 windows 驱动器并且可用 /external
我想要 运行 多个工具,如 jenkins、nexus、nessus 等,并希望在外部驱动器中使用持久卷,这样即使我创建了新的 EKS 集群,卷也会永远保留在那里,我可以重用它们
所以我想知道最好用什么
- 我可以创建单个
hostPath
PV,然后每个 pod 可以从中申请 exmaple 20GB - 或者我必须使用
hostPath
为每个 pod 创建 PV,然后在 POD 中声明它
那么PV和PVC有1:1关系吗?或者一个 PV 可以在 diff 文件夹中有多个声明?
- 此外,如果重新创建 Cluster 并从相同的 hostPath 创建 PV,我的数据会在那里吗?
您可以使用 local
音量而不是 hostPath
来试验 SC/PVC/PC。首先,创建 StorageClass:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: shared
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
然后在每个节点上提供可用的 PersistentVolume ,这是一个节点的示例:
apiVersion: v1
kind: PersistentVolume
metadata:
name: shared-pv-1
spec:
capacity:
storage: 20Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: shared
local:
path: <path to the shared folder>
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- <your node name>
以及允许您在 pod 中安装已配置卷的声明:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: shared-pv-1
spec:
storageClassName: shared
volumeMode: Filesystem
resources:
requests:
storage: 20Gi
accessModes:
- ReadWriteOnce
这是一个装载卷并向其写入数据的示例 pod:
apiVersion: v1
kind: Pod
metadata:
name: busybox-1
spec:
restartPolicy: Never
volumes:
- name: shared
persistentVolumeClaim:
claimName: shared-pv-1
containers:
- name: busybox-1
image: busybox
imagePullPolicy: IfNotPresent
volumeMounts:
- name: shared
mountPath: /data
command: ["ash","-c","while :; do echo \"$(date)\tmessage from busybox-1.\" >> /data/message.txt; sleep 1; done"]
对于local volume, by default the data written will require manual cleanup and deletion. A positive side effect for you as you would like the content to persist. If you like go further to experiment CSI alike local volume, you can use this Local Persistence Volume Static Provisioner。