news 2026/10/14 23:24:56

k8s部署 nfs-client-provisioner

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
k8s部署 nfs-client-provisioner

k8s部署nfs-client-provisioner是 Kubernetes 中实现 NFS 动态存储供应的核心方式

1.NFS 服务端已部署需提前准备一台 NFS 服务器(如 CentOS/Ubuntu),并创建共享目录.如果有单独的NFS存储,此步骤可忽略。

# 1. 安装 NFS 服务(以 CentOS 为例) yum install -y nfs-utils rpcbind # 2. 创建共享目录 mkdir -p /kubernetes-nfs # 3. 配置 NFS 共享(修改 /etc/exports) echo "/kubernetes-nfs *(rw,sync,no_root_squash,no_all_squash)" >> /etc/exports # 4. 生效配置并启动服务 exportfs -r systemctl start rpcbind && systemctl enable rpcbind systemctl start nfs-server && systemctl enable nfs-server # 5. 验证 NFS 共享 showmount -e 本机IP # 输出应包含 /kubernetes-nfs

2.K8s 集群节点能访问 NFS 服务端所有 K8s 节点安装 NFS 客户端(避免挂载失败)

# CentOS yum install -y nfs-utils # Ubuntu apt install -y nfs-common

3.部署步骤

3.1创建命名空间,本次使用的是kube-system命名空间,可忽略

kubectl create ns nfs-deploy

3.2创建 ServiceAccount 和 RBAC 权限

apiVersion: v1 kind: ServiceAccount metadata: name: nfs-client-provisioner-sa # replace with namespace where provisioner is deployed namespace: kube-system --- 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-sa # replace with namespace where provisioner is deployed namespace: kube-system 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 # replace with namespace where provisioner is deployed namespace: kube-system 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 # replace with namespace where provisioner is deployed namespace: kube-system subjects: - kind: ServiceAccount name: nfs-client-provisioner-sa # replace with namespace where provisioner is deployed namespace: kube-system roleRef: kind: Role name: leader-locking-nfs-client-provisioner apiGroup: rbac.authorization.k8s.io ---

应用配置

kubectl apply -f nfs-client-provisioner-rbac.yaml

3.3部署 nfs-client-provisioner 应用

--- apiVersion: apps/v1 kind: Deployment metadata: name: nfs-client-provisioner labels: app: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: kube-system spec: replicas: 1 strategy: type: Recreate selector: matchLabels: app: nfs-client-provisioner template: metadata: labels: app: nfs-client-provisioner spec: serviceAccountName: nfs-client-provisioner-sa containers: - name: nfs-client-provisioner image: quay.io/external_storage/nfs-client-provisioner:latest volumeMounts: - name: nfs-client-root mountPath: /persistentvolumes env: - name: PROVISIONER_NAME value: choerodon.io/nfs-client-provisioner - name: NFS_SERVER value: 10.10.10.211 - name: NFS_PATH value: /kubernetes_data volumes: - name: nfs-client-root nfs: server: 10.10.10.211 path: /kubernetes_data ---

应用配置

kubectl apply -f nfs-client-provisioner-deploy.yaml

3.4创建 StorageClass(存储类)

--- apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: nfs-cloud provisioner: choerodon.io/nfs-client-provisioner # or choose another name, must match deployment's env PROVISIONER_NAME' parameters: archiveOnDelete: "false" reclaimPolicy: Delete # PV 回收策略(Delete/Retain) volumeBindingMode: Immediate # 立即绑定 PVC 和 PV

应用配置

kubectl apply -f nfs-client-storageclass.yaml # 可选:设置为默认存储类(PVC 不指定 storageClassName 时自动使用) kubectl patch storageclass nfs-cloud -p '{"metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

4.自动执行脚本

#!/bin/bash # 安装nfs-storageclass NS=kube-system NFS_SERVER_HOST=10.10.20.8 # 填写NFS服务器IP地址 NFS_SERVER_PATH=/kubernetes-nfs # 填写NFS路径 NFS_PROVISIONER_NAME=nfs-server # 服务供应商标识,随便起 NFS_STORAGE_CLASS_NAME=managed-nfs-storage # K8S中StorageClass的显示名称,随便起 cat << EOF > /tmp/k8s-init-nfs-storageclass.yaml apiVersion: v1 kind: ServiceAccount metadata: name: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: ${NS} --- 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 # replace with namespace where provisioner is deployed namespace: ${NS} 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 # replace with namespace where provisioner is deployed namespace: ${NS} 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 # replace with namespace where provisioner is deployed namespace: ${NS} subjects: - kind: ServiceAccount name: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: ${NS} roleRef: kind: Role name: leader-locking-nfs-client-provisioner apiGroup: rbac.authorization.k8s.io --- apiVersion: apps/v1 kind: Deployment metadata: name: nfs-client-provisioner labels: app: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: ${NS} 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: quay.io/external_storage/nfs-client-provisioner:latest volumeMounts: - name: nfs-client-root mountPath: /persistentvolumes env: - name: PROVISIONER_NAME value: ${NFS_PROVISIONER_NAME} - name: NFS_SERVER value: ${NFS_SERVER_HOST} - name: NFS_PATH value: ${NFS_SERVER_PATH} volumes: - name: nfs-client-root nfs: server: ${NFS_SERVER_HOST} path: ${NFS_SERVER_PATH} --- apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: ${NFS_STORAGE_CLASS_NAME} provisioner: ${NFS_PROVISIONER_NAME} # or choose another name, must match deployment's env PROVISIONER_NAME' parameters: archiveOnDelete: "false" EOF kubectl apply -f /tmp/k8s-init-nfs-storageclass.yaml
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/10/15 4:25:31

SeedVR2视频修复模型深度解析:从技术原理到实战应用

SeedVR2视频修复模型深度解析&#xff1a;从技术原理到实战应用 【免费下载链接】SeedVR2-7B 项目地址: https://ai.gitcode.com/hf_mirrors/ByteDance-Seed/SeedVR2-7B 在当今视频内容爆炸式增长的时代&#xff0c;如何高效处理低质量视频素材成为创作者面临的核心挑战…

作者头像 李华
网站建设 2026/10/15 3:25:04

多模态模型CLIP详解

论文&#xff1a;Learning Transferable Visual Models From Natural Language SupervisionCLIP 的全称是 Contrastive Language-Image Pre-training&#xff08;对比语言-图像预训练&#xff09;。它是由 OpenAI 在 2021 年提出的一个多模态人工智能模型。其核心思想是通过学习…

作者头像 李华
网站建设 2026/10/15 0:45:24

EnergyPlus建筑能耗模拟完全指南:掌握核心技术

EnergyPlus作为业界领先的建筑能源模拟解决方案&#xff0c;为建筑节能设计提供了全面的技术支撑。本指南将深入解析其核心功能与应用技巧&#xff0c;帮助您快速掌握这一强大工具。 【免费下载链接】EnergyPlus EnergyPlus™ is a whole building energy simulation program t…

作者头像 李华
网站建设 2026/10/14 21:32:26

为什么90%的Q#开发者忽略了VSCode中的覆盖率指标?

第一章&#xff1a;Q# 程序的 VSCode 代码覆盖率在量子计算开发中&#xff0c;确保 Q# 程序的质量至关重要。Visual Studio Code&#xff08;VSCode&#xff09;作为主流开发环境&#xff0c;结合扩展工具可实现对 Q# 代码的覆盖率分析&#xff0c;帮助开发者识别未测试的量子逻…

作者头像 李华
网站建设 2026/10/15 0:24:15

如何实现电脑音频无线投送到手机?跨设备同步终极指南

如何实现电脑音频无线投送到手机&#xff1f;跨设备同步终极指南 【免费下载链接】AudioShare 将Windows的音频在其他Android设备上实时播放。Share windows audio 项目地址: https://gitcode.com/gh_mirrors/audi/AudioShare 还在为设备间的音频壁垒而烦恼吗&#xff1…

作者头像 李华