K8s使用NFS持久卷配置

孤人 提交于 2021-02-18 12:55:34

nfs服务部署

参照网上文档操作,太简单,这里不提。

创建storageclass

kind: StorageClass
metadata:
  name: slow
  namespace: ns1
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: Immediate

创建持久卷

apiVersion: v1
kind: PersistentVolume
metadata:
  name: vulfiles
  namespace: ns1
  labels:
    name: vulfiles
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadOnlyMany
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /opt/data
    server: 192.168.199.150

申请使用持久卷部分空间

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: vulpvc
  namespace: ns1
spec:
  accessModes:
    - ReadOnlyMany
  volumeMode: Filesystem
  resources:
    requests:
      storage: 5Gi
  storageClassName: slow
  selector:
    matchLabels:
      name: vulfiles

pvc 通过 matchLabels和pv中的label匹配,来关联要使用的存储空间。

容器中配置

      volumes:
        - name: vuldata
          persistentVolumeClaim:
            claimName: vulpvc
      containers:
      - name: container-xxx
        image: xxx/kkk
        imagePullPolicy: Always
        volumeMounts:
          - mountPath: "/opt/data"
            name: vuldata
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!