K8s使用NFS持久卷配置

coding

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

以上是 K8s使用NFS持久卷配置 的全部内容, 来源链接: utcz.com/z/509396.html

回到顶部