当前位置: 首页 > news >正文

k8s--storageClass自动创建PV

文章目录

  • 一、storageClass自动创建PV
    • 1.1 安装NFS
    • 1.2 创建nfs storageClass
    • 1.3 测试自动创建pv

一、storageClass自动创建PV

这里使用NFS实现

1.1 安装NFS

安装nfs-server: sh nfs_install.sh /mnt/data03 10.60.41.0/24

nfs_install.sh

#!/bin/bash### How to install it? ###
### 安装nfs-server,需要两个参数:1、挂载点  2、允许访问nfs-server的网段 ###### How to use it? ###
### Client节点`yum -y install nfs-utils rpcbind`,然后挂载nfs-server目录到本地 ###
### 如:echo "192.168.0.20:/mnt/data01  /mnt/data01  nfs  defaults  0 0" >> /etc/fstab && mount -a ###mount_point=$1
subnet=$2function nfs_server() {systemctl stop firewalldsystemctl disable firewalldsetenforce 0sed -i 's/^SELINUX.*/SELINUX\=disabled/' /etc/selinux/configyum -y install nfs-utils rpcbindmkdir -p $mount_pointecho "$mount_point ${subnet}(rw,sync,no_root_squash)" >> /etc/exportssystemctl start rpcbind && systemctl enable rpcbindsystemctl restart nfs-server && systemctl enable nfs-serverchown -R nfsnobody:nfsnobody $mount_point
}function usage() {
echo "Require 2 argument: [mount_point] [subnet]
eg: sh $0 /mnt/data01 192.168.10.0/24"
}declare -i arg_nums
arg_nums=$#
if [ $arg_nums -eq 2 ];thennfs_server
elseusageexit 1
fi

1.2 创建nfs storageClass

创建: kubectl apply -f storageclass_deploy.yaml

storageclass_deploy.yaml

apiVersion: v1
kind: ServiceAccount
metadata:name: nfs-provisionernamespace: devops
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:name: nfs-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"]
- apiGroups: [""]resources: ["services", "endpoints"]verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:name: run-nfs-provisioner
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: nfs-provisioner-runner
subjects:
- kind: ServiceAccountname: nfs-provisionernamespace: devops
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:name: leader-locking-nfs-provisionernamespace: devops
rules:
- apiGroups: [""]resources: ["endpoints"]verbs: ["get", "list", "watch", "create", "update", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:name: leader-locking-nfs-provisionernamespace: devops
roleRef:apiGroup: rbac.authorization.k8s.iokind: Rolename: leader-locking-nfs-provisioner
subjects:
- kind: ServiceAccountname: nfs-provisionernamespace: devops
---
apiVersion: apps/v1
kind: Deployment
metadata:name: nfs-provisioner
spec:selector:matchLabels:app: nfs-provisionerreplicas: 1strategy:type: Recreatetemplate:metadata:labels:app: nfs-provisionerspec:serviceAccountName: nfs-provisionercontainers:- name: nfs-provisionerimage: docker.io/gmoney23/nfs-client-provisioner:latestvolumeMounts:- name: nfs-client-rootmountPath: /persistentvolumesenv:- name: PROVISIONER_NAMEvalue: example.com/nfs- name: NFS_SERVERvalue: 10.60.41.248- name: NFS_PATHvalue: /mnt/data03volumes:- name: nfs-client-rootnfs:server: 10.60.41.248path: /mnt/data03
---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:name: nfs
provisioner: example.com/nfs

1.3 测试自动创建pv

创建: kubectl apply -f test_auto_generate_pv.yaml
创建pvc之后发现pv自动创建了,在/mnt/data03/ 目录下

在这里插入图片描述

test_auto_generate_pv.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: test-claim1namespace: devops
spec:accessModes:- ReadWriteManyresources:requests:storage: 1GistorageClassName: nfs
---
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-deployment
spec:replicas: 1selector:matchLabels:name: nginx-podtemplate:metadata:labels:name: nginx-podnamespace: myappspec:containers:- name: nginximage: docker.io/library/nginx:latestimagePullPolicy: IfNotPresentvolumeMounts:- name: nfs-pvcmountPath: /usr/share/nginx/htmlvolumes:- name: nfs-pvcpersistentVolumeClaim:claimName: test-claim1
http://www.lryc.cn/news/180772.html

相关文章:

  • 7.3 调用函数
  • 如果使用pprof来进行性能的观测和优化
  • 在移动固态硬盘上安装Ubuntu系统和ROS2
  • 【iptables 实战】02 iptables常用命令
  • webview_flutter
  • 【GESP考级C++】1级样题 闰年统计
  • CentOS密码重置
  • Tomcat Servlet
  • 国庆day2---select实现服务器并发
  • Grafana 开源了一款 eBPF 采集器 Beyla
  • 亲测可用国产GPT人工智能
  • 适配器模式详解和实现(设计模式 四)
  • IDEA的使用
  • CSS详细基础(二)文本样式
  • win10系统任务栏图标变成白色的解决办法
  • hadoop生态现状、介绍、部署
  • 二、EFCore 数据库表的创建和迁移
  • 在nodejs中使用typescript
  • 数据结构与算法基础(青岛大学-王卓)(8)
  • 【生物信息学】使用谱聚类(Spectral Clustering)算法进行聚类分析
  • CSS基础语法第二天
  • ThreeJS - 封装一个GLB模型展示组件(TypeScript)
  • HashMap面试题
  • Java编程技巧:swagger2、knif4j集成SpringBoot或者SpringCloud项目
  • 第三章:最新版零基础学习 PYTHON 教程(第九节 - Python 运算符—Python 中的除法运算符)
  • 【python】导出mysql数据,输出excel!
  • 【Java 进阶篇】JDBC ResultSet 遍历结果集详解
  • 华为数通方向HCIP-DataCom H12-831题库(单选题:161-180)
  • 【VsCode】SSH远程连接Linux服务器开发,搭配cpolar内网穿透实现公网访问
  • java并发编程 守护线程 用户线程 main