K8s使用NFS持久卷配置

原创
2019/11/15 16:40
阅读数 973

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