赞
踩
演示环境信息:单机K3s 1.28.2
操作系统:CentOS Linux release 7.8.2003 (Core)
虚拟机基础信息:4C4G
NFS服务器:同1台服务器
服务端
## 安装服务端程序
yum -y install nfs-utils rpcbind
## 配置NFS
mkdir /opt/data
## (vi /etc/exports)
/opt/data *(rw,no_root_squash,no_all_squash,anonuid=0,anongid=0,sync)
##启动服务
systemctl enable rpcbind --now
systemctl enable nfs --now
客户端
##安装客户端程序
rpm -qa |grep nfs-utils
yum -y install nfs-utils
克隆项目
git clone https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner.git
修改 YAML 文件
### 进入deploy目录
cd nfs-subdir-external-provisioner/deploy
### 生效 rbac
kubectl apply -f rbac.yaml
###修改部署文件deployment.yaml
#修改可拉取的镜像地址
sed -i 's#registry.k8s.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2#k8s.m.daocloud.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2#g' deployment.yaml
#修改NFS服务器地址和共享路径(NFS_SERVER和NFS_PATH)
10.0.16.4
/opt/data
### 部署驱动程序
kubectl apply -f deployment.yaml
### 查看
kubectl get pod
部署文件位置:nfs-subdir-external-provisioner/deploy/class.yaml
### class.yaml 示例文件
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-client
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner
parameters:
pathPattern: "${.PVC.namespace}/${.PVC.annotations.nfs.io/storage-path}"
onDelete: delete
### 部署
kubectl apply -f class.yaml
验证文件
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-claim
spec:
storageClassName: nfs-client ### 指明动态存储类名称(上面的class.yaml的metadata字段)
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Mi
### 应用
kubectl apply -f test-claim.yaml
kind: Pod
apiVersion: v1
metadata:
name: test-pod
spec:
containers:
- name: test-pod
image: busybox:stable
command:
- "/bin/sh"
args:
- "-c"
- "touch /mnt/SUCCESS && exit 0 || exit 1"
volumeMounts: ### 声明需要挂载出去的容器路径
- name: nfs-pvc
mountPath: "/mnt"
restartPolicy: "Never"
volumes:
- name: nfs-pvc
persistentVolumeClaim:
claimName: test-claim
### 生效
kubectl apply -f test-pod.yaml
查看效果
is ok
k8s设置默认存储类:改变默认 StorageClass | Kubernetes
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。