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
相关推荐
@YDWLCloud2 分钟前
华为云国际版 vs 阿里云国际版:东南亚市场选型指南
大数据·服务器·阿里云·华为云·云计算
新兴AI民工3 分钟前
【Linux内核七】进程管理模块:进程调度管理器sched_class
linux·服务器·linux内核
孤岛悬城3 分钟前
59 k8s集群调度
云原生·kubernetes
快乐的划水a3 分钟前
上下文简析
linux·运维·服务器
HABuo4 分钟前
【linux进程控制(一)】进程创建&退出-->fork&退出码详谈
linux·运维·服务器·c语言·c++·ubuntu·centos
EndingCoder4 分钟前
高级类型:联合类型和类型别名
linux·服务器·前端·ubuntu·typescript
2301_765715148 分钟前
Linux中组合使用多个命令的技巧与实现
linux·运维·chrome
想唱rap17 分钟前
MySQL内置函数
linux·运维·服务器·数据库·c++·mysql
Jet_5818 分钟前
Ubuntu 桌面版 Wireshark 抓包权限不足问题解决指南
linux·ubuntu·wireshark
wit_yuan18 分钟前
openbmc 支持mctp over pcie(三)(支持作为endpoint)
linux·服务器·嵌入式硬件