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
相关推荐
wangjialelele8 分钟前
Linux下的IO操作以及ext系列文件系统
linux·运维·服务器·c语言·c++·个人开发
广州中轴线15 分钟前
OpenStack on Kubernetes 生产部署实战(十三)
容器·kubernetes·openstack
HypoxiaDream25 分钟前
LINUX-Ext系列⽂件系统
linux·运维·服务器
小毛驴85026 分钟前
Linux curl 命令用法
linux·运维·chrome
李斯啦果32 分钟前
【Linux】Linux目录配置
linux·运维·服务器
AI+程序员在路上34 分钟前
linux下线程中pthread_detach与pthread_join区别
linux·运维·服务器
代码游侠34 分钟前
C语言核心概念复习——C语言基础阶段
linux·开发语言·c++·学习
logocode_li36 分钟前
说透 Linux Shell:命令与语法的底层执行逻辑
linux·运维·ssh
CHENKONG_CK41 分钟前
晨控CK-LR08-E00与汇川H5U系列PLC配置MODBUSTCP通讯连接手册
linux·服务器·网络
LongQ30ZZ1 小时前
Linux-基础IO
linux