k8s-对接NFS存储

一、前提条件

1、NFS_Server 部署好了。

2、网络可达。

二、 使用方式

1、CSI

**项目地址

https://github.com/kubernetes-csi/csi-driver-nfs#readme

Install NFS CSI driver v4.10.0 version on a kubernetes cluster

If you have already installed Helm, you can also use it to install this driver. Please check Installation with Helm.

Install with kubectl

*下面两种方式选一个。

  • Option#1. remote install
复制代码
curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/v4.10.0/deploy/install-driver.sh | bash -s v4.10.0 --
  • Option#2. local install
复制代码
git clone https://github.com/kubernetes-csi/csi-driver-nfs.git
cd csi-driver-nfs
./deploy/install-driver.sh v4.10.0 local
  • check pods status:
复制代码
kubectl -n kube-system get pod -o wide -l app=csi-nfs-controller
kubectl -n kube-system get pod -o wide -l app=csi-nfs-node

example output:

复制代码
NAME                                       READY   STATUS    RESTARTS   AGE     IP             NODE
csi-nfs-controller-56bfddd689-dh5tk       4/4     Running   0          35s     10.240.0.19    k8s-agentpool-22533604-0
csi-nfs-node-cvgbs                        3/3     Running   0          35s     10.240.0.35    k8s-agentpool-22533604-1
csi-nfs-node-dr4s4                        3/3     Running   0          35s     10.240.0.4     k8s-agentpool-22533604-0

clean up NFS CSI driver

  • Option#1. remote uninstall
复制代码
curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/v4.10.0/deploy/uninstall-driver.sh | bash -s v4.10.0 --
  • Option#2. local uninstall
复制代码
git clone https://github.com/kubernetes-csi/csi-driver-nfs.git
cd csi-driver-nfs
git checkout v4.10.0
./deploy/uninstall-driver.sh v4.10.0 local

2、手动------PV_PVC

复制代码
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs
spec:
  capacity:
    storage: 1Mi
  accessModes:
    - ReadWriteMany
  nfs:
    server: nfs-server.default.svc.cluster.local
    path: "/"
  mountOptions:
    - nfsvers=4.2

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 1Mi
  volumeName: nfs

3、POD直接读取

复制代码
apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: registry.k8s.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /my-nfs-data
      name: test-volume
  volumes:
  - name: test-volume
    nfs:
      server: my-nfs-server.example.com
      path: /my-nfs-volume
      readOnly: true
相关推荐
Vone_662 小时前
node.js 邮箱验证服务器搭建
运维·服务器·node.js
丢丢丢丢丢丢~3 小时前
apache2的默认html修改
linux·运维·服务器
wusam3 小时前
Linux系统管理与编程20:Apache
linux·运维·服务器·apache·shell编程
我不想当小卡拉米3 小时前
【Linux】操作系统入门:冯诺依曼体系结构
linux·开发语言·网络·c++
ChironW3 小时前
Ubuntu 24.04 LTS系统上配置国内时间同步
linux·运维·服务器·ubuntu
TPBoreas3 小时前
排查服务器内存空间预警思路
运维·服务器
yayaer24 小时前
GOOSE 协议中MAC配置
服务器·网络·goose
苏生要努力4 小时前
第九届御网杯网络安全大赛初赛WP
linux·python·网络安全
若风的雨4 小时前
【DeepSeek】判断两个 PCIe 设备是否属于**同一个 PCIe 子树
linux
ARM2NCWU4 小时前
云手机服务器搭建
服务器