k8s安装nfs

前言

k8s集群搭建参考:
https://blog.csdn.net/centrl/article/details/134291473
整合helm参考:
https://blog.csdn.net/centrl/article/details/134293363

集群架构

hostnameipnfs
kmaster172.16.16.100server
kworker1172.16.16.101
kworker2172.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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值