使用longhorn创建共用的PVC

原创
2022/04/12 13:39
阅读数 949

引言
不同pod共享同一个volume的话,一般会要求PVC的accessMode是RWX(ReadWriteMany),能不能用这个storage provider的StorageClass在于它支不支持RWX,longhorn是支持的。如果不支持的话,创建RWX模式的PVC时,会一直处于pending状态。我们不用配置PV,只需要选择好能支持RWX模式的StorageClass,然后使用它去创建RWX访问模式的PVC,最后共用的pod引用这个PVC就行了。

$ helm repo add longhorn https://charts.longhorn.io
$ helm repo update

$ kubectl create namespace longhorn-system
$ helm install longhorn longhorn/longhorn --namespace longhorn-system

$ cat << EOF | kubectl create -f -
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 1Gi

$ cat << EOF | kubectl create -f -
apiVersion: v1
kind: Pod
metadata:
  name: pod
spec:
  containers:
  - name: container
    image: alpine:latest
    imagePullPolicy: IfNotPresent
    command: ["/bin/sh", "-c", "--"]
    args: ["sleep infinity"]
    volumeMounts:
    - name: ws
      mountPath: /workspace
  volumes:
    - name: ws
      persistentVolumeClaim:
        claimName: pvc

更多 longhorn 细节请参考:Longhorn 企业级云原生容器存储解决方案-部署篇

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部