CN111880738A - A method for automatically creating and mounting LVM volumes in a K8s environment - Google Patents

A method for automatically creating and mounting LVM volumes in a K8s environment Download PDF

Info

Publication number
CN111880738A
CN111880738A CN202010742438.2A CN202010742438A CN111880738A CN 111880738 A CN111880738 A CN 111880738A CN 202010742438 A CN202010742438 A CN 202010742438A CN 111880738 A CN111880738 A CN 111880738A
Authority
CN
China
Prior art keywords
lvm
size
volumes
environment
mount
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010742438.2A
Other languages
Chinese (zh)
Inventor
李珂
申嘉童
于沈课
蔡卫卫
高传集
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Cloud Information Technology Co Ltd
Original Assignee
Inspur Cloud Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Cloud Information Technology Co Ltd filed Critical Inspur Cloud Information Technology Co Ltd
Priority to CN202010742438.2A priority Critical patent/CN111880738A/en
Publication of CN111880738A publication Critical patent/CN111880738A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0604Improving or facilitating administration, e.g. storage management
    • G06F3/0607Improving or facilitating administration, e.g. storage management by facilitating the process of upgrading existing storage systems, e.g. for improving compatibility between host and storage device
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1458Management of the backup or restore process
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0629Configuration or reconfiguration of storage systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/0644Management of space entities, e.g. partitions, extents, pools

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Quality & Reliability (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明特别涉及一种K8s环境自动化创建和挂载LVM卷的方法。该K8s环境自动化创建和挂载LVM卷的方法,基于Kubernetes环境,首先制作执行自动化创建和挂载LVM卷的镜像,然后,定义Configmap管和Job管理单副本Pod运行制作的镜像,配置容器权限、环境变量、所需挂载和节点选择;最后使用Kubernetes客户端运行前面创建的yaml文件,包括Configmap和Deployment,实现目标节点运行自动化创建和挂载LVM卷,可以重复运行并支持后续对LVM卷的扩展,提供节点服务使用本地存储。该K8s环境自动化创建和挂载LVM卷的方法,借助Kubernetes Job读取相关配置完成目标磁盘到LVM卷的转换,并挂载到目标目录上提供服务使用,与人工完成磁盘初始化和挂载过程相比大大提升了易用性和可管理性,能够满足生产环境Kubernetes服务使用本地存储的需求。

Figure 202010742438

The invention particularly relates to a method for automatically creating and mounting LVM volumes in a K8s environment. The method of automatically creating and mounting LVM volumes in the K8s environment is based on the Kubernetes environment. First, create an image to automatically create and mount LVM volumes. Then, define the Configmap pipe and Job to manage the image created by the single-copy Pod operation, configure container permissions, Environment variables, required mounts, and node selection; finally, use the Kubernetes client to run the previously created yaml files, including Configmap and Deployment, to automatically create and mount LVM volumes for target node operation, which can be run repeatedly and support subsequent LVM volumes. An extension that provides node services to use local storage. The method of automatically creating and mounting LVM volumes in the K8s environment uses the Kubernetes Job to read the relevant configuration to complete the conversion of the target disk to the LVM volume, and mount it to the target directory for service use, which is similar to the manual completion of the disk initialization and mounting process. It greatly improves ease of use and manageability, and can meet the needs of local storage for Kubernetes services in production environments.

Figure 202010742438

Description

一种K8s环境自动化创建和挂载LVM卷的方法A method for automatically creating and mounting LVM volumes in a K8s environment

技术领域technical field

本发明涉及云计算技术领域,特别涉及一种K8s环境自动化创建和挂载LVM卷的方法。The invention relates to the technical field of cloud computing, in particular to a method for automatically creating and mounting LVM volumes in a K8s environment.

背景技术Background technique

Kubernetes,简称K8s,是用8代替8个字符"ubernete"而成的缩写。作为一个开源的,用于管理云平台中多个主机上的容器化的应用,Kubernetes的目标是让部署容器化的应用简单并且高效(powerful)。Kubernetes提供了资源应用部署、规划、更新及维护的一种机制。Kubernetes, or K8s for short, is an acronym for replacing the eight-character "ubernete" with eight. As an open source for managing containerized applications on multiple hosts in a cloud platform, Kubernetes aims to make deploying containerized applications simple and efficient. Kubernetes provides a mechanism for resource application deployment, planning, updating and maintenance.

Kubernetes集群的工作负载可以使用多种存储方式,大部分磁盘插件使用远程存储,这是为了让持久化的数据与计算节点彼此独立,但远程存储通常无法提供本地存储优秀的读写性能。LVM(逻辑卷管理)代表直接绑定在计算节点的一块本地磁盘,但是使用的前提是需要人工完成创建和挂载目录的过程。目前实现本地目录的主流方式是LVM,作为Linux环境下对磁盘分区进行管理的一种机制,用户可以在无需停机的情况下方便地调整各个分区大小。The workload of a Kubernetes cluster can use a variety of storage methods. Most disk plug-ins use remote storage to keep persistent data independent of computing nodes. However, remote storage usually cannot provide the excellent read and write performance of local storage. LVM (Logical Volume Management) represents a local disk directly bound to the computing node, but the premise of use is that the process of creating and mounting directories needs to be completed manually. Currently, the mainstream way to implement local directories is LVM. As a mechanism for managing disk partitions in a Linux environment, users can easily adjust the size of each partition without downtime.

为了提高创建和挂载目录的易用性,本发明提出了一种K8s环境自动化创建和挂载LVM卷的方法。In order to improve the usability of creating and mounting directories, the present invention proposes a method for automatically creating and mounting LVM volumes in a K8s environment.

发明内容SUMMARY OF THE INVENTION

本发明为了弥补现有技术的缺陷,提供了一种简单高效的K8s环境自动化创建和挂载LVM卷的方法。In order to make up for the defects of the prior art, the present invention provides a simple and efficient method for automatically creating and mounting LVM volumes in the K8s environment.

本发明是通过如下技术方案实现的:The present invention is achieved through the following technical solutions:

一种K8s环境自动化创建和挂载LVM卷的方法,其特征在于:基于Kubernetes环境,包括以下步骤:A method for automatically creating and mounting LVM volumes in a K8s environment, characterized in that: based on the Kubernetes environment, the method includes the following steps:

第一步,制作执行自动化创建和挂载LVM卷的镜像,在原生基础镜像基础上安装lvm2包,可以执行自动化创建和挂载LVM卷所需的相关Linux命令;The first step is to create an image that automates the creation and mounting of LVM volumes. Install the lvm2 package on the basis of the native base image, and execute the relevant Linux commands required to automatically create and mount LVM volumes;

第二步,定义Configmap管理Shell脚本实现的五个基本操作,包括读取磁盘创建PV(物理卷)、创建VG(卷组)并把PV加入其中、读取大小创建或者扩展LV(逻辑卷)、格式化LV或者扩展LV、读取目标路径挂载LV;The second step is to define five basic operations implemented by the Configmap management shell script, including reading the disk to create PV (physical volume), creating VG (volume group) and adding PV to it, reading size, creating or expanding LV (logical volume) , format LV or extend LV, read target path and mount LV;

第三步,定义Job管理单副本Pod运行制作的镜像,配置容器权限、环境变量、所需挂载和节点选择;The third step is to define the image created by the Job management single-copy Pod operation, configure container permissions, environment variables, required mounts, and node selection;

第四步,使用Kubernetes客户端运行前面创建的yaml文件,包括Configmap和Deployment,实现目标节点运行自动化创建和挂载LVM卷,可以重复运行并支持后续对LVM卷的扩展,提供节点服务使用本地存储。The fourth step is to use the Kubernetes client to run the previously created yaml file, including Configmap and Deployment, to automatically create and mount LVM volumes for target node operation, which can be run repeatedly and support subsequent expansion of LVM volumes, providing node services using local storage .

所述第一步中,相关Linux命令包括但不限于pvcreate、vgcreate、vgextend、lvcreate、lvextend、mkfs、resize2fs命令。In the first step, relevant Linux commands include but are not limited to pvcreate, vgcreate, vgextend, lvcreate, lvextend, mkfs, and resize2fs commands.

所述第二步中,利用Configmap定义自动化创建和挂载LVM的过程,包括配置PV、配置VG、配置LV、格式化LV和配置挂载。In the second step, the process of automatically creating and mounting LVM is defined using Configmap, including configuring PV, configuring VG, configuring LV, formatting LV, and configuring mounting.

其中,配置PV的过程如下:循环读取磁盘参数列表,对每个磁盘首先fdisk-l检查是否存在,如果不存在报错退出,否则继续执行;然后pvs检查该磁盘是否已经做过PV,如果没有执行pvcreate命令创建PV,否则正常退出,直到所有磁盘处理完毕。Among them, the process of configuring PV is as follows: cyclically read the disk parameter list, first check if fdisk-l exists for each disk, if there is no error and exit, otherwise continue to execute; then pvs checks whether the disk has done PV, if not Execute the pvcreate command to create the PV, otherwise exit normally until all disks are processed.

配置VG的过程如下:首先vgs检查VG是否已经存在,如果没有执行vgcreate命令根据创建的PV生成VG;否则循环读取磁盘参数列表,检查PV是否在VG中,如果没有执行vgextend命令把PV加入到VG中,否则正常退出,直到所有磁盘处理完毕。The process of configuring the VG is as follows: first, vgs checks whether the VG already exists. If the vgcreate command is not executed, the VG is generated according to the created PV; otherwise, the disk parameter list is read in a loop to check whether the PV is in the VG. If the vgextend command is not executed, the PV is added to the VG. VG, otherwise exit normally until all disks are processed.

配置LV的过程如下:首先lvs检查LV是否已经存在,如果没有读取规划LV大小执行lvcreate命令创建LV,如果执行失败代表规划大小超过VG实际大小,则使用VG可用大小创建LV,否则正常退出;否则读取规划LV大小执行lvextend命令扩展LV,如果执行失败根据命令输出判断,如果包含match代表当前LV大小等于规划大小,如果包含Insufficient代表当前规划大小超过VG实际大小,使用VG可用大小扩展LV,否则代表当前LV大小超过规划大小,正常退出。The process of configuring LV is as follows: First, lvs checks whether the LV already exists. If the planned LV size is not read, execute the lvcreate command to create an LV. If the execution fails, it means that the planned size exceeds the actual size of the VG, then use the available size of the VG to create the LV, otherwise exit normally; Otherwise, read the planned LV size and execute the lvextend command to expand the LV. If the execution fails, judge according to the command output. If match is included, it means that the current LV size is equal to the planned size. If Insufficient is included, it means that the current planned size exceeds the actual size of the VG, and the LV is extended using the available size of the VG. Otherwise, it means that the current LV size exceeds the planned size and exits normally.

格式化LV的过程如下:首先df检查LV是否已经挂载,如果未挂载执行mkfs.ext4命令格式化LV;否则判断LV大小与挂载目录大小,如果前者超过后者执行resize2fs扩展LV。The process of formatting LV is as follows: First, df checks whether the LV has been mounted. If it is not mounted, execute the mkfs.ext4 command to format the LV; otherwise, judge the size of the LV and the size of the mounted directory. If the former exceeds the latter, execute resize2fs to extend the LV.

配置挂载的过程如下:首先grep检查/etc/fstab是否存在LV,如果没有读取目标目录添加挂载配置到/etc/fstab中,否则正常退出;然后执行mount-a,此时目标目录已经成功挂载。The process of configuring the mount is as follows: first grep to check whether there is an LV in /etc/fstab, if the target directory is not read, add the mount configuration to /etc/fstab, otherwise exit normally; then execute mount-a, the target directory is already Mounted successfully.

所述第三步中,环境变量包括地存储的磁盘列表、规划LV大小和目标挂载路径;所需挂载包括/run、/etc/fstab、/dev、Configmap和目标路径;配置节点选择保证Pod运行在目标节点。In the third step, the environment variables include the stored disk list, the planned LV size and the target mount path; the required mounts include /run, /etc/fstab, /dev, Configmap and the target path; the configuration node selection guarantees Pod runs on the target node.

当节点的业务需求需要扩展本地存储卷大小时,调整所述第三步中的环境变量配置,比如磁盘列表和规划LV大小,然后通过Kubernetes客户端执行删除Job,再执行第四步,即可自动完成本地存储卷大小的扩展。When the business requirements of the node need to expand the size of the local storage volume, adjust the environment variable configuration in the third step, such as the disk list and the planned LV size, and then delete the job through the Kubernetes client, and then perform the fourth step. The expansion of the local storage volume size is done automatically.

本发明的有益效果是:该K8s环境自动化创建和挂载LVM卷的方法,借助KubernetesJob读取相关配置完成目标磁盘到LVM卷的转换,并挂载到目标目录上提供服务使用,与人工完成磁盘初始化和挂载过程相比大大提升了易用性和可管理性,能够满足生产环境Kubernetes服务使用本地存储的需求。The beneficial effects of the present invention are: the method for automatically creating and mounting LVM volumes in the K8s environment, with the help of KubernetesJob reading the relevant configuration to complete the conversion of the target disk to the LVM volume, and mounting it on the target directory to provide service use, and manually completing the disk Compared with the initialization and mounting process, the ease of use and manageability are greatly improved, and it can meet the needs of using local storage for Kubernetes services in the production environment.

附图说明Description of drawings

为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the embodiments of the present invention or the technical solutions in the prior art more clearly, the following briefly introduces the accompanying drawings that need to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are For some embodiments of the present invention, for those of ordinary skill in the art, other drawings can also be obtained according to these drawings without creative efforts.

附图1为本发明K8s环境自动化创建和挂载LVM卷的方法示意图。FIG. 1 is a schematic diagram of the method for automatically creating and mounting LVM volumes in the K8s environment of the present invention.

具体实施方式Detailed ways

为了使本技术领域的人员更好的理解本发明中的技术方案,下面将结合本发明实施例,对本发明实施例中的技术方案进行清楚,完整的描述。显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本发明保护的范围。In order to make those skilled in the art better understand the technical solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the embodiments of the present invention. Obviously, the described embodiments are only some, but not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

该K8s环境自动化创建和挂载LVM卷的方法,基于Kubernetes环境,包括以下步骤:The method for automatically creating and mounting LVM volumes in the K8s environment is based on the Kubernetes environment, including the following steps:

第一步,制作执行自动化创建和挂载LVM卷的镜像,在原生基础镜像基础上安装lvm2包,可以执行自动化创建和挂载LVM卷所需的相关Linux命令;The first step is to create an image that automates the creation and mounting of LVM volumes. Install the lvm2 package on the basis of the native base image, and execute the relevant Linux commands required to automatically create and mount LVM volumes;

第二步,定义Configmap管理Shell脚本实现的五个基本操作,包括读取磁盘创建PV、创建VG并把PV加入其中、读取大小创建或者扩展LV、格式化LV或者扩展LV、读取目标路径挂载LV;The second step is to define five basic operations implemented by the Configmap management shell script, including reading disk to create PV, creating VG and adding PV to it, reading size, creating or extending LV, formatting LV or extending LV, and reading target path mount LV;

第三步,定义Job管理单副本Pod运行制作的镜像,配置容器权限、环境变量、所需挂载和节点选择;The third step is to define the image created by the Job management single-copy Pod operation, configure container permissions, environment variables, required mounts, and node selection;

第四步,使用Kubernetes客户端运行前面创建的yaml文件,包括Configmap和Deployment,实现目标节点运行自动化创建和挂载LVM卷,可以重复运行并支持后续对LVM卷的扩展,提供节点服务使用本地存储。The fourth step is to use the Kubernetes client to run the previously created yaml file, including Configmap and Deployment, to automatically create and mount LVM volumes for target node operation, which can be run repeatedly and support subsequent expansion of LVM volumes, providing node services using local storage .

所述第一步中,相关Linux命令包括但不限于pvcreate、vgcreate、vgextend、lvcreate、lvextend、mkfs、resize2fs命令。In the first step, relevant Linux commands include but are not limited to pvcreate, vgcreate, vgextend, lvcreate, lvextend, mkfs, and resize2fs commands.

所述第二步中,利用Configmap定义自动化创建和挂载LVM的过程,包括配置PV、配置VG、配置LV、格式化LV和配置挂载。In the second step, the process of automatically creating and mounting LVM is defined using Configmap, including configuring PV, configuring VG, configuring LV, formatting LV, and configuring mounting.

其中,配置PV的过程如下:循环读取磁盘参数列表,对每个磁盘首先fdisk-l检查是否存在,如果不存在报错退出,否则继续执行;然后pvs检查该磁盘是否已经做过PV,如果没有执行pvcreate命令创建PV,否则正常退出,直到所有磁盘处理完毕。Among them, the process of configuring PV is as follows: cyclically read the disk parameter list, first check if fdisk-l exists for each disk, if there is no error and exit, otherwise continue to execute; then pvs checks whether the disk has done PV, if not Execute the pvcreate command to create the PV, otherwise exit normally until all disks are processed.

配置VG的过程如下:首先vgs检查VG是否已经存在,如果没有执行vgcreate命令根据创建的PV生成VG;否则循环读取磁盘参数列表,检查PV是否在VG中,如果没有执行vgextend命令把PV加入到VG中,否则正常退出,直到所有磁盘处理完毕。The process of configuring the VG is as follows: first, vgs checks whether the VG already exists. If the vgcreate command is not executed, the VG is generated according to the created PV; otherwise, the disk parameter list is read in a loop to check whether the PV is in the VG. If the vgextend command is not executed, the PV is added to the VG. VG, otherwise exit normally until all disks are processed.

配置LV的过程如下:首先lvs检查LV是否已经存在,如果没有读取规划LV大小执行lvcreate命令创建LV,如果执行失败代表规划大小超过VG实际大小,则使用VG可用大小创建LV,否则正常退出;否则读取规划LV大小执行lvextend命令扩展LV,如果执行失败根据命令输出判断,如果包含match代表当前LV大小等于规划大小,如果包含Insufficient代表当前规划大小超过VG实际大小,使用VG可用大小扩展LV,否则代表当前LV大小超过规划大小,正常退出。The process of configuring LV is as follows: First, lvs checks whether the LV already exists. If the planned LV size is not read, execute the lvcreate command to create an LV. If the execution fails, it means that the planned size exceeds the actual size of the VG, then use the available size of the VG to create the LV, otherwise exit normally; Otherwise, read the planned LV size and execute the lvextend command to expand the LV. If the execution fails, judge according to the command output. If match is included, it means that the current LV size is equal to the planned size. If Insufficient is included, it means that the current planned size exceeds the actual size of the VG, and the LV is extended using the available size of the VG. Otherwise, it means that the current LV size exceeds the planned size and exits normally.

格式化LV的过程如下:首先df检查LV是否已经挂载,如果未挂载执行mkfs.ext4命令格式化LV;否则判断LV大小与挂载目录大小,如果前者超过后者执行resize2fs扩展LV。The process of formatting LV is as follows: First, df checks whether the LV has been mounted. If it is not mounted, execute the mkfs.ext4 command to format the LV; otherwise, judge the size of the LV and the size of the mounted directory. If the former exceeds the latter, execute resize2fs to extend the LV.

配置挂载的过程如下:首先grep检查/etc/fstab是否存在LV,如果没有读取目标目录添加挂载配置到/etc/fstab中,否则正常退出;然后执行mount-a,此时目标目录已经成功挂载。The process of configuring the mount is as follows: first grep to check whether there is an LV in /etc/fstab, if the target directory is not read, add the mount configuration to /etc/fstab, otherwise exit normally; then execute mount-a, the target directory is already Mounted successfully.

所述第三步中,环境变量包括地存储的磁盘列表、规划LV大小和目标挂载路径;所需挂载包括/run、/etc/fstab、/dev、Configmap和目标路径;配置节点选择保证Pod运行在目标节点。In the third step, the environment variables include the stored disk list, the planned LV size and the target mount path; the required mounts include /run, /etc/fstab, /dev, Configmap and the target path; the configuration node selection guarantees Pod runs on the target node.

当节点的业务需求需要扩展本地存储卷大小时,调整所述第三步中的环境变量配置,比如磁盘列表和规划LV大小,然后通过Kubernetes客户端执行删除Job,再执行第四步,即可自动完成本地存储卷大小的扩展。当Pod状态为Completed时,配置挂载的目标目录可用大小已经完成调整。When the business requirements of the node need to expand the size of the local storage volume, adjust the environment variable configuration in the third step, such as the disk list and the planned LV size, and then delete the job through the Kubernetes client, and then perform the fourth step. The expansion of the local storage volume size is done automatically. When the Pod status is Completed, the available size of the target directory of the configuration mount has been adjusted.

所述第四步中,使用Kubernetes客户端运行Configmap和Job,当Pod状态为Completed时查看节点,此时本地磁盘已经自动化转化为LVM卷并挂载到目标目录,可提供节点运行的服务使用;In the fourth step, use the Kubernetes client to run Configmap and Job, and view the node when the Pod status is Completed. At this time, the local disk has been automatically converted into an LVM volume and mounted to the target directory, which can provide services for node operation;

与目前的现有技术相比,该K8s环境自动化创建和挂载LVM卷的方法,具有以下特点:Compared with the current existing technology, the method for automatically creating and mounting LVM volumes in the K8s environment has the following characteristics:

第一、借助Shell脚本可以灵活定制自动化创建和挂载LVM卷的处理过程;First, with the help of shell scripts, the process of automatically creating and mounting LVM volumes can be flexibly customized;

第二、使用Kubernetes集群中的Job对象可以一次性自动完成任务所需的步骤,不再依赖任何手动操作的过程,保证了配置的可控性,避免了手动操作的差错,大大提升了节点创建和挂载LVM卷的易用性和可管理性。Second, using the Job object in the Kubernetes cluster can automatically complete the steps required for the task at one time, no longer rely on any manual operation process, ensure the controllability of configuration, avoid manual operation errors, and greatly improve node creation And the ease and manageability of mounting LVM volumes.

以上所述的实施例,只是本发明具体实施方式的一种,本领域的技术人员在本发明技术方案范围内进行的通常变化和替换都应包含在本发明的保护范围内。The above-mentioned embodiment is only one of the specific embodiments of the present invention, and the usual changes and substitutions made by those skilled in the art within the scope of the technical solution of the present invention should be included in the protection scope of the present invention.

Claims (10)

1.一种K8s环境自动化创建和挂载LVM卷的方法,其特征在于:基于Kubernetes环境,包括以下步骤:1. a method for automatically creating and mounting LVM volumes in a K8s environment, characterized in that: based on the Kubernetes environment, comprising the following steps: 第一步,制作执行自动化创建和挂载LVM卷的镜像,在原生基础镜像基础上安装lvm2包,可以执行自动化创建和挂载LVM卷所需的相关Linux命令;The first step is to create an image that automates the creation and mounting of LVM volumes. Install the lvm2 package on the basis of the native base image, and execute the relevant Linux commands required to automatically create and mount LVM volumes; 第二步,定义Configmap管理Shell脚本实现的五个基本操作,包括读取磁盘创建PV、创建VG并把PV加入其中、读取大小创建或者扩展LV、格式化LV或者扩展LV、读取目标路径挂载LV;The second step is to define five basic operations implemented by the Configmap management shell script, including reading disk to create PV, creating VG and adding PV to it, reading size, creating or extending LV, formatting LV or extending LV, and reading target path mount LV; 第三步,定义Job管理单副本Pod运行制作的镜像,配置容器权限、环境变量、所需挂载和节点选择;The third step is to define the image created by the Job management single-copy Pod operation, configure container permissions, environment variables, required mounts, and node selection; 第四步,使用Kubernetes客户端运行前面创建的yaml文件,包括Configmap和Deployment,实现目标节点运行自动化创建和挂载LVM卷,可以重复运行并支持后续对LVM卷的扩展,提供节点服务使用本地存储。The fourth step is to use the Kubernetes client to run the previously created yaml file, including Configmap and Deployment, to automatically create and mount LVM volumes for target node operation, which can be run repeatedly and support subsequent expansion of LVM volumes, providing node services using local storage . 2.根据权利要求1所述的K8s环境自动化创建和挂载LVM卷的方法,其特征在于:所述第一步中,相关Linux命令包括但不限于pvcreate、vgcreate、vgextend、lvcreate、lvextend、mkfs、resize2fs命令。2. K8s environment according to claim 1 automatically creates and mounts the method for LVM volume, it is characterized in that: in the described first step, relevant Linux commands include but are not limited to pvcreate, vgcreate, vgextend, lvcreate, lvextend, mkfs , resize2fs command. 3.根据权利要求2所述的K8s环境自动化创建和挂载LVM卷的方法,其特征在于:所述第二步中,利用Configmap定义自动化创建和挂载LVM的过程,包括配置PV、配置VG、配置LV、格式化LV和配置挂载。3. the method for automatic creation and mount LVM volume of K8s environment according to claim 2, is characterized in that: in the described second step, utilize Configmap to define the process of automatic creation and mount LVM, comprise configuration PV, configuration VG , configure LV, format LV and configure mount. 4.根据权利要求3所述的K8s环境自动化创建和挂载LVM卷的方法,其特征在于:配置PV的过程如下:循环读取磁盘参数列表,对每个磁盘首先fdisk-l检查是否存在,如果不存在报错退出,否则继续执行;然后pvs检查该磁盘是否已经做过PV,如果没有执行pvcreate命令创建PV,否则正常退出,直到所有磁盘处理完毕。4. K8s environment according to claim 3 automatically creates and mounts the method for LVM volume, it is characterized in that: the process of configuring PV is as follows: read disk parameter list circularly, to each disk first fdisk-1 checks whether there is, If there is no error and exit, otherwise continue to execute; then pvs checks whether the disk has already done PV, if the pvcreate command is not executed to create a PV, otherwise exit normally until all disks are processed. 5.根据权利要求3所述的K8s环境自动化创建和挂载LVM卷的方法,其特征在于:配置VG的过程如下:首先vgs检查VG是否已经存在,如果没有执行vgcreate命令根据创建的PV生成VG;否则循环读取磁盘参数列表,检查PV是否在VG中,如果没有执行vgextend命令把PV加入到VG中,否则正常退出,直到所有磁盘处理完毕。5. K8s environment according to claim 3 automatically creates and mounts the method for LVM volume, it is characterized in that: the process of configuring VG is as follows: at first vgs checks whether VG already exists, if not executing vgcreate command, generate VG according to the PV created ; Otherwise, read the disk parameter list in a loop, check whether the PV is in the VG, if the vgextend command is not executed, add the PV to the VG, otherwise exit normally until all the disks are processed. 6.根据权利要求3所述的K8s环境自动化创建和挂载LVM卷的方法,其特征在于:配置LV的过程如下:首先lvs检查LV是否已经存在,如果没有读取规划LV大小执行lvcreate命令创建LV,如果执行失败代表规划大小超过VG实际大小,则使用VG可用大小创建LV,否则正常退出;否则读取规划LV大小执行lvextend命令扩展LV,如果执行失败根据命令输出判断,如果包含match代表当前LV大小等于规划大小,如果包含Insufficient代表当前规划大小超过VG实际大小,使用VG可用大小扩展LV,否则代表当前LV大小超过规划大小,正常退出。6. the method for automatically creating and mounting LVM volume in K8s environment according to claim 3, it is characterized in that: the process of configuring LV is as follows: at first lvs checks whether LV already exists, if there is no read planning LV size, execute lvcreate command to create LV, if the execution fails, it means that the planned size exceeds the actual size of the VG, use the available size of the VG to create the LV, otherwise exit normally; otherwise, read the planned LV size and execute the lvextend command to expand the LV. If the execution fails, judge according to the command output. If it contains match, it means the current The LV size is equal to the planned size. If Insufficient is included, it means that the current planned size exceeds the actual size of the VG, and the LV is extended with the available size of the VG. Otherwise, the current LV size exceeds the planned size and exits normally. 7.根据权利要求3所述的K8s环境自动化创建和挂载LVM卷的方法,其特征在于:格式化LV的过程如下:首先df检查LV是否已经挂载,如果未挂载执行mkfs.ext4命令格式化LV;否则判断LV大小与挂载目录大小,如果前者超过后者执行resize2fs扩展LV。7. K8s environment according to claim 3 automatically creates and mounts the method for LVM volume, it is characterized in that: the process of formatting LV is as follows: at first df checks whether LV has been mounted, if not mounted, execute mkfs.ext4 command Format the LV; otherwise, judge the size of the LV and the size of the mounted directory. If the former exceeds the size of the latter, execute resize2fs to extend the LV. 8.根据权利要求3所述的K8s环境自动化创建和挂载LVM卷的方法,其特征在于:配置挂载的过程如下:首先grep检查/etc/fstab是否存在LV,如果没有读取目标目录添加挂载配置到/etc/fstab中,否则正常退出;然后执行mount-a,此时目标目录已经成功挂载。8. K8s environment according to claim 3 automatically creates and mounts the method for LVM volume, it is characterized in that: the process of configuration mount is as follows: at first grep checks /etc/fstab whether there is LV, if not read target directory add Mount the configuration to /etc/fstab, otherwise exit normally; then execute mount-a, and the target directory has been successfully mounted. 9.根据权利要求1所述的K8s环境自动化创建和挂载LVM卷的方法,其特征在于:所述第三步中,环境变量包括地存储的磁盘列表、规划LV大小和目标挂载路径;所需挂载包括/run、/etc/fstab、/dev、Configmap和目标路径;配置节点选择保证Pod运行在目标节点。9. K8s environment according to claim 1 automatically creates and mounts the method for LVM volume, it is characterized in that: in the described 3rd step, environment variable comprises the disk list of ground storage, planning LV size and target mount path; The required mounts include /run, /etc/fstab, /dev, Configmap, and the target path; the configuration node selection ensures that the Pod runs on the target node. 10.根据权利要求1或9所述的K8s环境自动化创建和挂载LVM卷的方法,其特征在于:当节点的业务需求需要扩展本地存储卷大小时,调整所述第三步中的环境变量配置,然后通过Kubernetes客户端执行删除Job,再执行第四步,即可自动完成本地存储卷大小的扩展。10. The method for automatically creating and mounting an LVM volume in a K8s environment according to claim 1 or 9, wherein: when the business requirement of the node needs to expand the size of the local storage volume, the environment variable in the third step is adjusted Configuration, then delete the job through the Kubernetes client, and then perform the fourth step to automatically complete the expansion of the size of the local storage volume.
CN202010742438.2A 2020-07-29 2020-07-29 A method for automatically creating and mounting LVM volumes in a K8s environment Pending CN111880738A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010742438.2A CN111880738A (en) 2020-07-29 2020-07-29 A method for automatically creating and mounting LVM volumes in a K8s environment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010742438.2A CN111880738A (en) 2020-07-29 2020-07-29 A method for automatically creating and mounting LVM volumes in a K8s environment

Publications (1)

Publication Number Publication Date
CN111880738A true CN111880738A (en) 2020-11-03

Family

ID=73201076

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010742438.2A Pending CN111880738A (en) 2020-07-29 2020-07-29 A method for automatically creating and mounting LVM volumes in a K8s environment

Country Status (1)

Country Link
CN (1) CN111880738A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112463616A (en) * 2020-12-02 2021-03-09 中国建设银行股份有限公司 Chaos testing method and device for Kubernetes container platform
CN113391952A (en) * 2021-06-07 2021-09-14 北京同创永益科技发展有限公司 Automatic backup method based on LVM snapshot in cloud native environment
CN113741961A (en) * 2021-11-08 2021-12-03 梯度云科技(北京)有限公司 Method and device for submitting big data calculation operation based on Kubernetes container arrangement software
CN114327515A (en) * 2021-12-28 2022-04-12 深圳依时货拉拉科技有限公司 Automatic mounting method and device, readable storage medium and computer equipment
CN114816272A (en) * 2022-06-23 2022-07-29 江苏博云科技股份有限公司 Magnetic disk management system under Kubernetes environment

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104283959A (en) * 2014-10-14 2015-01-14 国云科技股份有限公司 Performance-grading-based storage mechanism suitable for cloud platform
CN107193504A (en) * 2017-06-02 2017-09-22 郑州云海信息技术有限公司 A kind of method and system of automation distribution and establishment application memory based on Kubernetes
CN107707688A (en) * 2017-10-19 2018-02-16 杭州数梦工场科技有限公司 A kind of method and device of kubernetes clusters parsing host host name
CN110012088A (en) * 2019-03-29 2019-07-12 山东浪潮云信息技术有限公司 A kind of Redis principal and subordinate's cluster automatically dispose scheme based on Kubernets
CN110297641A (en) * 2019-06-25 2019-10-01 四川长虹电器股份有限公司 Layout dispositions method is applied based on kubernetes
CN110941393A (en) * 2019-10-31 2020-03-31 北京浪潮数据技术有限公司 Logical volume management-based LV supply method, device, equipment and medium
CN111162941A (en) * 2019-12-26 2020-05-15 浪潮云信息技术有限公司 Method for automatically managing virtual IP (Internet protocol) in Kubernetes environment

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104283959A (en) * 2014-10-14 2015-01-14 国云科技股份有限公司 Performance-grading-based storage mechanism suitable for cloud platform
CN107193504A (en) * 2017-06-02 2017-09-22 郑州云海信息技术有限公司 A kind of method and system of automation distribution and establishment application memory based on Kubernetes
CN107707688A (en) * 2017-10-19 2018-02-16 杭州数梦工场科技有限公司 A kind of method and device of kubernetes clusters parsing host host name
CN110012088A (en) * 2019-03-29 2019-07-12 山东浪潮云信息技术有限公司 A kind of Redis principal and subordinate's cluster automatically dispose scheme based on Kubernets
CN110297641A (en) * 2019-06-25 2019-10-01 四川长虹电器股份有限公司 Layout dispositions method is applied based on kubernetes
CN110941393A (en) * 2019-10-31 2020-03-31 北京浪潮数据技术有限公司 Logical volume management-based LV supply method, device, equipment and medium
CN111162941A (en) * 2019-12-26 2020-05-15 浪潮云信息技术有限公司 Method for automatically managing virtual IP (Internet protocol) in Kubernetes environment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
李红岩,乔洁,王莉: "《Linux下逻辑卷管理的原理与实现》", 《科技风》, no. 203, pages 37 *

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112463616A (en) * 2020-12-02 2021-03-09 中国建设银行股份有限公司 Chaos testing method and device for Kubernetes container platform
CN113391952A (en) * 2021-06-07 2021-09-14 北京同创永益科技发展有限公司 Automatic backup method based on LVM snapshot in cloud native environment
CN113391952B (en) * 2021-06-07 2022-03-11 北京同创永益科技发展有限公司 Automatic backup method based on LVM snapshot in cloud native environment
CN113741961A (en) * 2021-11-08 2021-12-03 梯度云科技(北京)有限公司 Method and device for submitting big data calculation operation based on Kubernetes container arrangement software
CN114327515A (en) * 2021-12-28 2022-04-12 深圳依时货拉拉科技有限公司 Automatic mounting method and device, readable storage medium and computer equipment
CN114327515B (en) * 2021-12-28 2025-06-24 深圳依时货拉拉科技有限公司 Automatic mounting method and device, readable storage medium and computer equipment
CN114816272A (en) * 2022-06-23 2022-07-29 江苏博云科技股份有限公司 Magnetic disk management system under Kubernetes environment
CN114816272B (en) * 2022-06-23 2022-09-06 江苏博云科技股份有限公司 Magnetic disk management system under Kubernetes environment

Similar Documents

Publication Publication Date Title
CN111880738A (en) A method for automatically creating and mounting LVM volumes in a K8s environment
US11621998B2 (en) Dynamic creation and execution of containerized applications in cloud computing
CN111522628B (en) Kubernetes cluster building deployment method, framework and storage medium based on OpenStack
CN112099938B (en) Determining resource allocation in distributed computing environments using multidimensional metadata tag sets
JP5393515B2 (en) Server image migration
CN102402446B (en) Method and device for installing application software
US8924954B2 (en) Application software installation method and application software installation apparatus
US10152387B1 (en) Instant start of virtual machine from archive copy on backup media
US20140007092A1 (en) Automatic transfer of workload configuration
BRPI0715058A2 (en) dynamic configuration, allocation and development of computer systems
CN106055388A (en) A cloud platform application automatic deployment framework
CN104281484B (en) A kind of virtual machine migration method and device
CN107632937B (en) Method and device for testing virtual machine cluster and readable storage medium
CN104182257A (en) Application software installation method and device
CN112882726B (en) Hadoop and Docker-based deployment method of environment system
US11429373B2 (en) Upgrade implementation of a virtualization management system
CN115357198B (en) Storage volume mounting method and device, storage medium and electronic equipment
US11977559B2 (en) Providing instant and distributed access to a source blob via copy-on-read blobs and link blobs
US10592112B2 (en) Storage system software upgrade and data migration
CN111371620A (en) Bare computer service deployment method and system based on distributed cache
CN107193563A (en) A kind of method of server stateless firmware version management
CN116560578A (en) Data storage method, device, equipment and storage medium
CN114860378A (en) A file system migration method, device, system and medium thereof
CN115202674A (en) Helm-based automatic deployment method for local volumes in kubernets cluster
US10936544B2 (en) Enabling consistency in push order for network caching

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20201103

RJ01 Rejection of invention patent application after publication