kubernetes 使用 nfs作为存储

安装nfs

服务端安装

yum install -y nfs-utils rpcbind
mkdir /nfsdata
echo "/nfsdata <client-ip>(rw,sync,root_squash)" >> /etc/exports
service firewalld stop
systemctl enable rpcbind
systemctl start rpcbind
systemctl enable nfs
systemctl start nfs

客户端安装

在k8s的每个节点上执行:

yum install -y nfs-utils rpcbind
systemctl enable rpcbind
systemctl start rpcbind

检查时候可以连接nfs

showmount -e <server-ip>
mount -t nfs <server-ip>:/nfsdata/ /<Existing path>/

k8s中安装nfs的provisioner

下载k8s nfs provisioner的helmchart

kubectl create ns nfs-provisioner
helm install nfs-client-provisioner-1.2.0.tgz --set nfs.server=<servver-ip> --set nfs.path=/nfsdata --set image.repository=s7799653/nfs-client-provisioner --set image.tag=v3.1.0-k8s1.11 --namespace nfs-provisioner --tls

测试

创建pvc文件 claim.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: claim1
spec:
  storageClassName: nfs-client
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
kubectl apply -f claim.yaml
kubectl get pvc # pvc STATUS Bound

创建pod文件 pod.yaml

kind: Pod
apiVersion: v1
metadata:
  name: test-pod
spec:
  containers:
  - name: test-pod
    image: busybox:1.24
    command:
      - "/bin/sh"
    args:
      - "-c"
      - "touch /mnt/SUCCESS && exit 0 || exit 1"
    volumeMounts:
      - name: pvc
        mountPath: "/mnt"
  restartPolicy: "Never"
  volumes:
    - name: pvc
      persistentVolumeClaim:
        claimName: claim1
kubectl apply -f pod.yaml
kubectl get pod # pod STATUS Completed

清理测试数据

kubectl delete po test-pod
kubectl delete pvc claim1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值