首页 > 其他分享 >Kubernetes 部署 NFS server

Kubernetes 部署 NFS server

时间:2023-11-30 15:46:04浏览次数:48  
标签:csi name Kubernetes server nfs io NFS k8s

环境要求

kubernetes:1.21+

部署 NFS server

下载 nfs server 部署清单

# wget https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/nfs-provisioner/nfs-server.yaml

添加 ns nfs

apiVersion: v1
kind: Namespace
metadata:
  name: nfs
---
kind: Service
apiVersion: v1
metadata:
  name: nfs-server
  namespace: nfs
  labels:
    app: nfs-server
spec:
  type: ClusterIP  # use "LoadBalancer" to get a public ip
  selector:
    app: nfs-server
  ports:
    - name: tcp-2049
      port: 2049
      protocol: TCP
    - name: udp-111
      port: 111
      protocol: UDP
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: nfs-server
  namespace: nfs
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nfs-server
  template:
    metadata:
      name: nfs-server
      labels:
        app: nfs-server
    spec:
      nodeSelector:
        "kubernetes.io/os": linux
      containers:
        - name: nfs-server
          image: itsthenetwork/nfs-server-alpine:latest
          env:
            - name: SHARED_DIRECTORY
              value: "/exports"
          volumeMounts:
            - mountPath: /exports
              name: nfs-vol
          securityContext:
            privileged: true
          ports:
            - name: tcp-2049
              containerPort: 2049
              protocol: TCP
            - name: udp-111
              containerPort: 111
              protocol: UDP
      volumes:
        - name: nfs-vol
          hostPath:
            path: /nfs-vol  # modify this to specify another path to store nfs share data
            type: DirectoryOrCreate

部署 nfs server

# kubectl apply -f nfs-server.yaml
namespace/nfs created
service/nfs-server created
deployment.apps/nfs-server created

查看 pod

# kubectl get pods -n nfs
NAME                          READY   STATUS    RESTARTS   AGE
nfs-server-7cc5bcdcd5-m7m7m   1/1     Running   0          35s

查看 svc

# kubectl get svc -n nfs
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)            AGE
nfs-server   ClusterIP   10.100.157.133   <none>        2049/TCP,111/UDP   90s

部署 NFS CSI driver

下载部署脚本

# git clone https://github.com/kubernetes-csi/csi-driver-nfs.git
# cd csi-driver-nfs

更改 registry.k8s.io

# sed -i 's@registry.k8s.io/sig-storage@registry.aliyuncs.com/google_containers@g' deploy/v4.5.0/*.yaml

部署 nfs csi

# ./deploy/install-driver.sh v4.5.0 local
use local deploy
Installing NFS CSI driver, version: v4.5.0 ...
serviceaccount/csi-nfs-controller-sa created
serviceaccount/csi-nfs-node-sa created
clusterrole.rbac.authorization.k8s.io/nfs-external-provisioner-role created
clusterrolebinding.rbac.authorization.k8s.io/nfs-csi-provisioner-binding created
csidriver.storage.k8s.io/nfs.csi.k8s.io created
deployment.apps/csi-nfs-controller created
daemonset.apps/csi-nfs-node created
NFS CSI driver installed successfully.

查看 pod 状态

csi-nfs-controller pod

# kubectl -n kube-system get pod -o wide -l app=csi-nfs-controller
NAME                                READY   STATUS    RESTARTS   AGE   IP                NODE          NOMINATED NODE   READINESS GATES
csi-nfs-controller-f4bd4f45-v89wl   4/4     Running   0          7s    192.168.174.106   k8s-node-01   <none>           <none>

csi-nfs-node pod

# kubectl -n kube-system get pod -o wide -l app=csi-nfs-node
NAME                 READY   STATUS    RESTARTS   AGE   IP                NODE            NOMINATED NODE   READINESS GATES
csi-nfs-node-b2dxs   3/3     Running   0          7s    192.168.174.100   k8s-master-01   <none>           <none>
csi-nfs-node-f2dct   3/3     Running   0          7s    192.168.174.107   k8s-node-02     <none>           <none>
csi-nfs-node-f8dbq   3/3     Running   0          7s    192.168.174.106   k8s-node-01     <none>           <none>
csi-nfs-node-pj5lb   3/3     Running   0          7s    192.168.174.108   k8s-node-03     <none>           <none>

卸载 NFS CSI driver

# ./deploy/uninstall-driver.sh v4.5.0 local
use local deploy
Uninstalling NFS driver, version: v4.5.0 ...
deployment.apps "csi-nfs-controller" deleted
daemonset.apps "csi-nfs-node" deleted
csidriver.storage.k8s.io "nfs.csi.k8s.io" deleted
serviceaccount "csi-nfs-controller-sa" deleted
serviceaccount "csi-nfs-node-sa" deleted
clusterrole.rbac.authorization.k8s.io "nfs-external-provisioner-role" deleted
clusterrolebinding.rbac.authorization.k8s.io "nfs-csi-provisioner-binding" deleted
Uninstalled NFS driver successfully.

测试 NFS server

nginx-pod.yaml

---
apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/provisioned-by: nfs.csi.k8s.io
  name: pv-nginx
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  mountOptions:
    - nfsvers=4.1
  csi:
    driver: nfs.csi.k8s.io
    # volumeHandle format: {nfs-server-address}#{sub-dir-name}#{share-name}
    # make sure this value is unique for every share in the cluster
    volumeHandle: nfs-server.nfs.svc.wgs.local/share##
    volumeAttributes:
      server: nfs-server.nfs.svc.wgs.local
      share: /
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-nginx
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  volumeName: pv-nginx
  storageClassName: ""
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx-nfs-example
spec:
  containers:
    - image: nginx
      name: nginx
      ports:
        - containerPort: 80
          protocol: TCP
      volumeMounts:
        - mountPath: /var/www
          name: pvc-nginx
          readOnly: false
  volumes:
    - name: pvc-nginx
      persistentVolumeClaim:
        claimName: pvc-nginx

创建测试pod

# kubectl apply -f nginx-pod.yaml
persistentvolume/pv-nginx created
persistentvolumeclaim/pvc-nginx created
pod/nginx-nfs-example created

验证 NFS  server

# kubectl exec nginx-nfs-example -- bash -c "findmnt /var/www -o TARGET,SOURCE,FSTYPE"
TARGET   SOURCE                         FSTYPE
/var/www nfs-server.nfs.svc.wgs.local:/ nfs4

创建 storage class

storageclass-nfs.yaml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-csi
provisioner: nfs.csi.k8s.io
parameters:
  server: nfs-server.nfs.svc.wgs.local
  share: /
  # csi.storage.k8s.io/provisioner-secret is only needed for providing mountOptions in DeleteVolume
  # csi.storage.k8s.io/provisioner-secret-name: "mount-options"
  # csi.storage.k8s.io/provisioner-secret-namespace: "default"
reclaimPolicy: Delete     # Retain
volumeBindingMode: Immediate
mountOptions:
  - nfsvers=4.1

创建 storageclass 

# kubectl apply -f storageclass-nfs.yaml
storageclass.storage.k8s.io/nfs-csi created

查看 storageclass 

# kubectl get StorageClass
NAME      PROVISIONER      RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
nfs-csi   nfs.csi.k8s.io   Retain          Immediate           false                  71s

创建 pvc

pvc-nfs-csi-dynamic.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-nfs-dynamic
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: nfs-csi

创建 pvc

# kubectl apply -f pvc-nfs-csi-dynamic.yaml
persistentvolumeclaim/pvc-nfs-dynamic created

查看 pvc

# kubectl get pvc
NAME              STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc-nfs-dynamic   Bound    pvc-a42b5bd5-3dba-4cf2-b09c-de5d9952b699   1Gi        RWX            nfs-csi        59s

查看 pv

# kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                     STORAGECLASS   REASON   AGE
pvc-a42b5bd5-3dba-4cf2-b09c-de5d9952b699   1Gi        RWX            Retain           Bound    default/pvc-nfs-dynamic   nfs-csi                 117s

参考文档

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

标签:csi,name,Kubernetes,server,nfs,io,NFS,k8s
From: https://www.cnblogs.com/wangguishe/p/17865625.html

相关文章

  • XP连接高版本SQLServer提示:ConnectionOpen(SECDoClientHandShake())SSL安全错误解决方
    XP连接高版本SQLServer提示:ConnectionOpen(SECDoClientHandShake())SSL安全错误解决方案https://blog.csdn.net/m0_46236949/article/details/130251762EnableTLS1.2onWindowsXPhttps://www.smartftp.com/pt-br/support/kb/2754......
  • SQL Server中left join、inner join和right join的区别?
    数据库是我们IT行家常的事情,相信大家都不陌生,计算机专业都开了数据库系统概论这门课程,我分享下在暑假找实习参加宣讲会过程做的笔试题中遇到关于leftjoin、innerjoin和rightjoin的区别的简述题,希望对需要的朋友有所帮助。看下面一个小例子,我懒的开软件,用Excel替代下,谅解谅解~st......
  • 在centos7下搭建ftp server
    1、安装软件yuminstallvsftpd2、修改配置文件目的:1)将使用系统本地用户登陆2)将用户锁定在其家目录下,不能随意切换3)禁用匿名用户anonymous_enable=NOlocal_enable=YESwrite_enable=YESlocal_umask=022dirmessage_enable=YESxferlog_enable=YESconnect......
  • ubuntu server 22 LTS 安装MySQL8(二进制源码方式)
    原作来源:https://github.com/aminglinux/daily_shell/blob/main/29.sh根据我自己情况稍作修改mysql下载地址:https://downloads.mysql.com/archives/community/ 按照顺序执行逐行执行注意执行过程的提示,报错需处理:tar-xvfmysql-8.0.34-linux-glibc2.17-x86_64.tarsudo......
  • TKE在Kubernetes集群原地无损大版本升级的一些探索
     如何在不重建容器不中断服务的情况下升级Kubernetes集群大版本,一些探索,方案实现于2021年9月 该功能已上线一段时间,因为一些原因文章迟迟没有发布,升级肯定会有还没有触及到的未知问题,该方案也不是十全十美,但目前上线后也基本平稳,能够处理大部分情况,把自己在这方面的思路和......
  • day06 基于NFS的存储解决方案 2.1
    一、基于NFS的存储解决方案NFS在K8S中的应用及配置1、前言NFS是基于网络共享文件的存储解决方案,及网络文件系统。NFS运行在一个系统网络上与他人共享目录和文件。通过使用NFS,用户和程序可像访问本地文件一样访问远端系统上的文件。nfs:是我们最终的存储nfs-client:用来动态......
  • IIS 10的重大更新通常会随着Windows Server和Windows 10的累积更新一起发布,这些更新可
    IIS10是WindowsServer 和Windows10操作系统中内置的Web服务器角色。针对IIS10的重大更新通常会随着WindowsServer和Windows10的累积更新一起发布,这些更新可能包括性能改进、安全性增强、新功能和修复程序。在过去的更新中,IIS10可能会获得以下方面的重大改进:安全性增......
  • Kubernetes网络
    在Kubernetes(k8s)中,网络主要由以下几部分组成:Pod网络:Pod是k8s中的基本工作单元,可以容纳一个或多个应用程序容器。为了使Pod之间能够通信,k8s提供了一个名为CNI(ContainerNetworkInterface)的网络抽象层。CNI允许第三方网络插件与k8s集成,为Pod创建和管理网络。最常见的网络插件包括Fla......
  • oracle、sql server Join连表修改。
    1、Oracle连表修改mergeintot_usert1using(select*fromt_class)t2on(t1.userId=t2.userId)whenmatchedthenupdatesett1.name=t2.name2、Sqlserver连表修改UPDATEbSETb.ProductSN=p.productsnFROMt_userbINNERJOINt_studentpONb.MainSN=p.Ma......
  • 查询sqlserver中的慢sql
    1SELECT2a.session_id,3a.client_net_address,4(total_elapsed_time/execution_count)/1000N'平均时间ms',5total_elapsed_time/1000N'总花费时间ms',6total_worker_time/1000N'所用的CPU总时间ms',7......