前言
k8s集群搭建参考:
https://blog.csdn.net/centrl/article/details/134291473
整合helm参考:
https://blog.csdn.net/centrl/article/details/134293363
集群架构
hostname | ip | nfs |
---|---|---|
kmaster | 172.16.16.100 | server |
kworker1 | 172.16.16.101 | |
kworker2 | 172.16.16.102 |
kmaster安装nfs服务
安装nfs-kernel-server
sudo apt update
sudo apt install nfs-kernel-server -y
创建文件夹并设置权限
sudo mkdir /opt/dynamic-storage
sudo chown -R nobody:nogroup /opt/dynamic-storage
sudo chmod 777 /opt/dynamic-storage
设置共享规则
sudo -- sh -c "echo /opt/dynamic-storage 172.16.16.0/24\(rw,sync,no_subtree_check\) >> /etc/exports"
sudo exportfs -a
重启服务
sudo systemctl restart nfs-kernel-server
sudo systemctl status nfs-kernel-server
kworker安装nfs-common
sudo apt update
sudo apt install nfs-common -y
k8s安装nfs客户端配置程序
添加helm仓库
helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner
helm 命令部署配置程序
helm install -n nfs-provisioning --create-namespace nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner --set nfs.server=172.16.16.100 --set nfs.path=/opt/dynamic-storage
检查安装
kubectl get all -n nfs-provisioning
kubectl get sc -n nfs-provisioning
功能验证
创建持久卷声明(PVC)
cat > demo-pvc.yml << EOF
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: demo-claim
namespace: nfs-provisioning
spec:
storageClassName: nfs-client
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Mi
EOF
创建并查看
kubectl create -f demo-pvc.yml
kubectl get pv,pvc -n nfs-provisioning
验证配置
使用以下 YML 文件启动测试容器荚
cat > test-pod.yml << EOF
kind: Pod
apiVersion: v1
metadata:
name: test-pod
namespace: nfs-provisioning
spec:
containers:
- name: test-pod
image: busybox:latest
command:
- "/bin/sh"
args:
- "-c"
- "touch /mnt/SUCCESS && sleep 600"
volumeMounts:
- name: nfs-pvc
mountPath: "/mnt"
restartPolicy: "Never"
volumes:
- name: nfs-pvc
persistentVolumeClaim:
claimName: demo-claim
EOF
安装并验证
kubectl create -f test-pod.yml
kubectl get pods -n nfs-provisioning
kubectl exec -it test-pod -n nfs-provisioning /bin/sh
删除安装
kubectl delete -f test-pod.yml
kubectl delete -f demo-pvc.yml
kubectl get pv,pvc -n nfs-provisioning