kubernetes安装和配置nfs

半兽人 发表于: 2022-09-26   最后更新时间: 2022-10-13 20:14:06  
{{totalSubscript}} 订阅, 1,776 游览

Step 1:安装NFS服务

Step 2:Kubernetes安装NFS驱动

Kubernetes 不包含内部 NFS 驱动。所以需要使用外部驱动和创建StorageClass

国内yaml:

wget -O all.yaml https://www.kubebiz.com/raw/KubeBiz/nfs-client-provisioner/latest/all

官方默认的:

git clone https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner

以上yaml源任选其一。

Step 3:修改配置

将默认的10.3.243.101/data/nfs改成你自己的nfs地址和存储路径。

官方默认的在deploy/objects/deployment.yaml中,进行修改。

Step 4:应用

执行yaml

kubectl apply -f all.yaml

或官方的

kubectl apply -f deploy/objects/.

输出:

deployment.apps/nfs-client-provisioner created
storageclass.storage.k8s.io/nfs-storage created
serviceaccount/nfs-client-provisioner created
clusterrole.rbac.authorization.k8s.io/nfs-client-provisioner-runner created
clusterrolebinding.rbac.authorization.k8s.io/run-nfs-client-provisioner created
role.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner created
rolebinding.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner created

Step 5:排错

kubectl get pods | grep nfs-client-provisioner

输出:

nfs-client-provisioner-66db4f7c-9kmfn   0/1     ContainerCreating   0          3m20s

如果不是Running,通过logs获取详细报错原因:

kubectl logs -f nfs-client-provisioner-66db4f7c-9kmfn -n manager

Step 6:验证

获取storageClassName的名称:

kubectl get sc

返回:

NAME                    PROVISIONER                                   RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
nfs-storage (default)   k8s-sigs.io/nfs-subdir-external-provisioner   Delete          Immediate           true                   35m

sc的名称是nfs-storage

下载测试yaml:

wget -O test-nfs.yaml https://www.kubebiz.com/raw/KubeBiz/nfs-client-provisioner/test/all

注意,storageClassName的名字要是你上面获取到的,如:

storageClassName: nfs-storage

执行应用:

kubectl apply -f test-nfs.yaml

同样,如果报错了,就通过以下命令查看错误原因:

kubectl describe pods test-pod

如果状态为Completed,则一切正常。

$ kubectl get pods 
NAME                                     READY   STATUS      RESTARTS   AGE
test-pod                                 0/1     Completed   0          18s

现在到nfs文件里,查询生产的文件了,如果看到SUCCESS,则说明nfs正常工作了,如下:

$ ls /data/nfs/default-test-claim-pvc-baea188a-5204-4081-b693-4a35e90dbffa/        
SUCCESS

最后,查看生成pv和pvc:

$ kubectl get pvc,pv

NAME                               STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/test-claim   Bound    pvc-baea188a-5204-4081-b693-4a35e90dbffa   1Mi        RWX            nfs-storage    5m28s

NAME                                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                STORAGECLASS   REASON   AGE
persistentvolume/pvc-baea188a-5204-4081-b693-4a35e90dbffa   1Mi        RWX            Delete           Bound    default/test-claim   nfs-storage             5m28s

相关链接

https://kubernetes.io/zh-cn/docs/concepts/storage/storage-classes/

更新于 2022-10-13
在线,27分钟前登录

查看kubernetes更多相关的文章或提一个关于kubernetes的问题,也可以与我们一起分享文章