ZBLOG

nfs-client-provisioner 使用k8s安装部署与绑定pvc 步骤

  1. 安装 nfs-client-provisioner

使用以下命令安装 nfs-client-provisioner:

kubectl apply -f https://raw.githubusercontent.com/kubernetes-incubator/external-storage/master/nfs-client/deploy/rbac.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-incubator/external-storage/master/nfs-client/deploy/deployment.yaml
  1. 创建 storage class

创建一个新的 storage class,用于指定 pvc 的存储类型和绑定规则。

例如,可以使用以下 YAML 文件创建一个名为 nfs-storage 的 storage class:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: nfs-storage
provisioner: nfs-client.provisioner.io
parameters:
  archiveOnDelete: "false"
  server: "<nfs-server-ip>"
  share: "/path/to/share"

其中,<nfs-server-ip> 是 NFS 服务器的 IP 地址,/path/to/share 是共享目录路径。

  1. 创建 PVC

使用下面的 YAML 文件创建一个名为 test-pvc 的 PVC,并将其绑定到 nfs-storage 存储类上:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nfs-storage 
  resources:
    requests:
      storage: 1Gi 

其中,accessModes 指定访问模式(这里是 ReadWriteMany),storageClassName 指定要使用的存储类名称,resources.requests.storage 指定 PVC 所需的存储大小。

  1. 验证 PVC 是否正常挂载

创建一个 Pod,并将其挂载到 test-pvc 上:

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
    - name: nginx
      image: nginx:latest
      volumeMounts:
        - name: data 
          mountPath: /usr/share/nginx/html 
  volumes:
    - name: data
      persistentVolumeClaim:
        claimName: test-pvc 

在创建完成后,使用 kubectl get pod 命令查看 Pod 的状态,如果处于 Running 状态,则表示 PVC 成功挂载。可以通过访问该 Pod 的 IP 地址来验证是否能够读写 PVC 中的数据。

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=6100

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?