使用hostpath作为VolumeClaimsTemplate

手动方式

kind: PersistentVolume
apiVersion: v1
metadata:
  name: hp-pv-001
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/tmp/data01"

kind: PersistentVolume
apiVersion: v1
metadata:
  name: hp-pv-002
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/tmp/data02"
volumeClaimTemplates:
- metadata:
    name: my-hostpath-volume
  spec:
    storageClassName: manual
    accessModes: ["ReadWriteOnce"]
    resources:
      requests:
        storage: 5Gi
    selector:
      matchLabels:
        type: local

或者使用

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

第三种选择

kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
kubectl create -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pvc/pvc.yaml
kubectl create -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pod/pod.yaml
Send a Message