当 Minikube (k8s) 中的 pods 声明卷时,如何强制所有卷实际位于裸机*主机*上的某个磁盘上?

When pods inside Minikube (k8s) claims Volumes, how to enforce all of them actually lie on a certain disk on the bare metal *host machine*?

我们有 一台 裸机,带有一个 SSD 和一个 HDD。 Minikube (k8s) 中的 pods 将要求一些 pvc 并获得一些卷。我们想要强制这些卷实际上在我们的 SSD 上,而不是 HDD 上。怎么做?非常感谢!

p.s。我尝试了什么:当想要 PVC 时,我们发现 Minikube 会在 /tmp/hostpath-provisioner/... 上分配一个。另外,恕我直言,这是 Minikube 本身运行的 inside Docker 路径,而不是主机路径。因此,我尝试 minikube mount /data/minikube-my-tmp-hostpath-provisioner:/tmp/hostpath-provisioner host 裸机的 /data 位于 SSD(而非 HDD)上。然而,这让 pods 不高兴,重启后它们都失败了...... 另外,我发现只有 new 文件会写入新挂载的路径,而现有文件仍将在容器内...

这听起来与 storage classes 存在的原因完全相同:

A StorageClass provides a way for administrators to describe the “classes” of storage they offer. Different classes might map to quality-of-service levels, or to backup policies, or to arbitrary policies determined by the cluster administrators. Kubernetes itself is unopinionated about what classes represent. This concept is sometimes called “profiles” in other storage systems.

换句话说,您可以创建具有不同性能或其他特征的多个存储 classes。然后决定哪一个最适合他们创建的每个声明。

例如,这是一个可以在 minikube 上使用的存储 class:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast
provisioner: k8s.io/minikube-hostpath
parameters:
  type: pd-ssd

您可能还需要创建一个 PV,您可以使用:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: some-name-pv
spec:
  capacity: 
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
    - ReadOnlyMany
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /tmp/path

然后,最后,PVC 会像这样:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: some-pvc 
spec:
  storageClassName: fast
  resources:
    requests:
      storage: 100Mi
  accessModes:
    - ReadWriteOnce