k8s 1.28.x 配置nfs

1.安装nfs,在每个节点上安装

yum install -y nfs-utils

2.创建共享目录(主节点上操作)

mkdir -p /opt/nfs/k8s

3.编写NFS的共享配置

/opt/nfs/k8s *(rw,no_root_squash)

#*代表对所有IP都开放此目录,rw是读写

4.启动nfs

systemctl enable nfs-server #开机启动

systemctl restart nfs-server #启动

5.测试nfs

showmount -e 主节点ip

查看NFS共享目录,ip为机器的内部IP

6.创建先关yaml文件

注:在 k8s 1.20 之后,出于对性能和统一 apiserver 调用方式的初衷,k8s 移除对 SelfLink 的支持,而默认上面指定的 provisioner 版本需要 SelfLink 功能,因此 PVC 无法进行自动制备。所以需要找不需要SelfLink的镜像。

class.yaml

bash 复制代码
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-nfs-storage
provisioner: fuseim.pri/ifs # or choose another name, must match deployment's env PROVISIONER_NAME'
parameters:
  archiveOnDelete: "true"

deploy.yaml

bash 复制代码
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: nfs-client-provisioner
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client-provisioner
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: registry.cn-beijing.aliyuncs.com/pylixm/nfs-subdir-external-provisioner:v4.0.0
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: fuseim.pri/ifs
            - name: NFS_SERVER
              value: 192.168.2.74 #主节点ip
            - name: NFS_PATH
              value: /opt/k8s/
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.2.74  #主节点ip
            path: /opt/k8s/

rbac.yaml

bash 复制代码
kind: ServiceAccount
apiVersion: v1
metadata:
  name: nfs-client-provisioner
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    namespace: default
roleRef:
  kind: ClusterRole
  name: nfs-client-provisioner-runner
  apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
rules:
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: default
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io

7.查看对应的pod

kubectl get pod

8.创建pvc.yaml 测试

bash 复制代码
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: demo-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: managed-nfs-storage

9.kubectl get pvc

相关推荐
Mylvzi6 分钟前
Linux 性能利器:详解 `top` 命令的使用与输出信息解析
linux·服务器·网络
斗转星移326 分钟前
解决ubuntu20.04无法唤醒的问题的一种方法
linux·ubuntu·电脑
饺子大魔王的男人1 小时前
Docker环境下FileRise私有云盘在飞牛NAS的部署与穿透实践
运维·docker·容器
lyh13441 小时前
【Ubuntu崩溃修复】
linux·运维·服务器
什么半岛铁盒2 小时前
【Linux系统】Linux环境变量:系统配置的隐形指挥官
linux
Lw老王要学习3 小时前
Linux容器篇、第一章_02Rocky9.5 系统下 Docker 的持久化操作与 Dockerfile 指令详解
linux·运维·docker·容器·云计算
橙子小哥的代码世界3 小时前
【大模型RAG】Docker 一键部署 Milvus 完整攻略
linux·docker·大模型·milvus·向量数据库·rag
倔强的石头1064 小时前
【Linux指南】用户与系统基础操作
linux·运维·服务器
云上艺旅4 小时前
centos升级内核
linux·运维·centos
kaikaile19954 小时前
centos开启samba服务
linux·运维·centos