A Kubernetes cluster operation and maintenance automation operation method and device based on Shell encapsulation
By adding namespace specification and automatic completion functions to the installation script of Kubernetes cluster, the problems faced by operation and maintenance personnel are solved, such as cumbersome commands, low degree of automation, inconvenient namespace management and lack of personalized customization, and more efficient, flexible and secure operation and maintenance management are achieved.
Patent Information
- Application Number
- CN202510007395.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-03
- Publication Date
- 2025-04-08
AI Technical Summary
Operations and maintenance personnel of Kubernetes clusters face problems such as cumbersome commands, low degree of automation, inconvenient namespace management and lack of personalized customization, resulting in inefficiency and increased operation and maintenance complexity.
A Kubernetes cluster operation and maintenance automation operation method based on Shell encapsulation is proposed. By adding namespace specification function to the installation script, users can customize the namespace, and the script automatically replaces the namespace parameters in the command, implements operations on specific namespaces, and provides automatic completion function.
Improves the flexibility and portability of Kubernetes cluster management, reduces the risk of operational errors, simplifies configuration management, and enhances team collaboration efficiency.
Smart Images

Figure CN119781907A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of automated operation and maintenance technology, and in particular relates to a Kubernetes cluster operation and maintenance automated operation method, device, computer-readable storage medium, and electronic device based on Shell encapsulation. Background Art
[0002] With the popularity of container technology, Kubernetes, as the de facto standard for container orchestration, has been widely used in production environments of all sizes. Operations and maintenance personnel and developers often interact with Kubernetes clusters through the kubectl command line tool. However, in actual operation, kubectl has the following shortcomings: (1) Complicated commands: Many common operations require entering lengthy commands, which increases the risk of input errors.
[0003] (2) Low level of automation: There is a lack of scripting tools to simplify common tasks, and a large amount of repetitive work is time-consuming and laborious.
[0004] (3) Inconvenient namespace management: In a multi-namespace environment, the operations of switching and specifying namespaces are complex and prone to errors.
[0005] (4) Lack of personalized customization: It is impossible to quickly customize general operation scripts according to user needs.
[0006] The above problems reduce work efficiency, increase the complexity of operation and maintenance work, and are not conducive to quickly responding to business needs. Summary of the invention
[0007] In order to address the above problems, this application proposes a new Kubernetes cluster operation and maintenance automation method and device based on Shell encapsulation. In the device of this application, a set of Kubectl-based automated processing scripts that support namespace customization are included, aiming to simplify the daily management tasks of the Kubernetes cluster and improve operation and maintenance efficiency. By adding the namespace specification function to the installation script install.sh, users can customize the namespace as needed, and the script will automatically replace the namespace parameters in all commands to implement operations on specific namespaces.
[0008] In order to achieve the above objectives, this application provides the following technical solutions: The first aspect of the present application provides a Kubernetes cluster operation and maintenance automation operation method based on Shell encapsulation, the method comprising: Pass user-specified namespace parameters into the installation script; When starting the installation, the installation script automatically replaces the default namespace in the tool script with the user-specified namespace, and the tool script implements operations on the user-specified namespace; When the tool script operates on the user-specified namespace, the automatic completion script obtains the Pod and service list based on the user-specified namespace to achieve automatic namespace completion.
[0009] Optionally, in the method of the present application, the installation script is used to install all tool scripts with one click, set execution permissions, configure the auto-completion function, and specify the namespace when performing the installation based on the namespace parameter; The tool script includes: Log query scripts (f and l): used to retrieve log information in a specified namespace based on service name, Pod name, and keywords; Container entry script (into): used to quickly enter the interactive shell of the Pod in the specified namespace; Pod list script (p): used to display detailed information of all Pods in the specified namespace; The autocomplete script (autocomplete) is used to provide an autocomplete function based on a specified namespace for a tool script.
[0010] Optionally, in the method of the present application, when starting the installation, the installation script passes in the user-specified namespace parameter when executing install.sh, and then uses the sed command to automatically replace the default namespace in all tool scripts with the user-specified namespace; The tool script implements operations on the user-specified namespace by using the user-specified namespace variable in the kubectl command.
[0011] Optionally, in the method of the present application, the tool script defines the namespace in a variable manner, including the following steps: (1) Select a namespace variable definition method, which includes global variable definition and environment variable persistence; (2) Control variable scope; (3) Namespace configuration file management, including determining the configuration file location, saving the configuration, and reading the configuration.
[0012] Optionally, the present application method also includes an installation process, including the following steps: Execute the installation script and specify the namespace: The user executes . / install.sh <namespace> in the command line; Namespace replacement: The installation script uses the sed command to replace the default namespace in all tool scripts with the user-specified namespace; Configure auto-completion: Add the auto-completion script content to ~ / .bashrc and it will take effect immediately; Deploy tool scripts: Copy the tool scripts to the / usr / bin directory and set executable permissions; Installation complete: Users can use tool scripts to specify namespaces.
[0013] Optionally, in the method of the present application, the user-specified namespace includes the following types: (1) Development environment namespace: such as dev, development, staging, etc. (2) Production environment namespace: such as prod, production, etc. (3) Test environment namespace: such as test, testing, etc. (4) User-defined namespace: user-defined-{identifier}; The naming conventions of the user-specified namespace are as follows: (a) Comply with DNS subdomain rules; (b) not more than 63 characters in length; (c) may only contain lowercase letters, numbers and “-”; (d) Must begin and end with a letter or number.
[0014] Optionally, in the method of the present application, the installation script automatically replaces the default namespace in the tool script with the user-specified namespace, and the replacement process includes the following steps: (1) Back up the original files; (2) Use the sed command to perform replacement operations, including basic replacement, conditional replacement, and multi-mode replacement; (3) Verify the namespace configuration.
[0015] The second aspect of the present application provides a Kubernetes cluster operation and maintenance automation operation device based on Shell encapsulation, the device comprising: Parameter configuration module: used to pass user-specified namespace parameters into the installation script; Namespace replacement module: used when starting the installation, the installation script automatically replaces the default namespace in the tool script with the user-specified namespace to implement operations on the user-specified namespace; Automatic completion module: used in the process of tool scripts operating on user-specified namespaces. The automatic completion script obtains the Pod and service list according to the user-specified namespace to achieve automatic completion of the namespace.
[0016] The device implements the steps of the aforementioned Shell-encapsulated Kubernetes cluster operation and maintenance automation operation method when running.
[0017] A third aspect of the present application provides an electronic device, comprising: a memory and a processor; Memory: used to store computer programs; Processor: used to execute the computer program to implement the steps of the aforementioned Shell-encapsulated Kubernetes cluster operation and maintenance automation operation method.
[0018] A fourth aspect of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the aforementioned Shell-encapsulated based Kubernetes cluster operation and maintenance automation operation method are implemented.
[0019] In summary, this application proposes a new Kubernetes cluster operation and maintenance automation method based on Shell encapsulation, which has the following advantages: (1) High flexibility in use: The system adopts a namespace customization mechanism and a parameterized script design. By passing the namespace parameter into the installation script, the namespace in the tool script is automatically replaced with the specified namespace during installation, thus supporting different namespaces. At the same time, the tool script uses variables to define the namespace, and cooperates with the installation script to achieve flexible namespace configuration, so that the tool script can be applied to different environments and meet diverse needs. Through parameterization and automated configuration, the flexibility and portability of the Kubernetes cluster management tool are improved.
[0020] (2) High operation accuracy: All commands are targeted at the specified namespace, avoiding accidental operation of resources in other namespaces and improving system security. At the same time, the dynamic application namespace customized auto-completion function achieves accurate resource matching.
[0021] (3) Simplified configuration management: Automated script configuration and deployment are achieved by using the sed command and installation scripts. There is no need to manually modify the scripts, which simplifies the tool usage process and reduces the complexity of configuration and the risk of errors.
[0022] (4) Enhanced team collaboration: Team members can each specify a namespace to avoid interfering with each other and improve collaboration efficiency.
[0023] Other features and advantages of the present application will be described in the following description, or understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the techniques indicated in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present application, a brief introduction will be given below to the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0025] Figure 1 This is a flowchart of the overall implementation of the Shell-encapsulated Kubernetes cluster operation and maintenance automation method provided in the embodiment of the present application.
[0026] Figure 2 This is a schematic diagram of the installation process of the embodiment method of the present application.
[0027] Figure 3 This is a diagram of the working relationship between the tool script and the namespace in the embodiment method of this application.
[0028] Figure 4 A composition diagram of a Kubernetes cluster operation and maintenance automation device based on Shell encapsulation provided in an embodiment of the present application.
[0029] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0031] As used herein, the term “including” and its variations are open inclusions, ie, “including but not limited to”; the term “based on” means “based at least in part on”; and the term “one embodiment” means “at least one embodiment”.
[0032] It should be noted that the modifications of "one" and "plurality" mentioned in the present application are illustrative rather than restrictive, and those skilled in the art should understand that unless the context clearly indicates otherwise, it should be understood as "one or more".
[0033] Figure 1 The overall implementation process of the Kubernetes cluster operation and maintenance automation method based on Shell encapsulation provided by this application is shown, including the following steps: Pass user-specified namespace parameters into the installation script; When starting the installation, the installation script automatically replaces the default namespace in the tool script with the user-specified namespace, and the tool script implements operations on the user-specified namespace; When the tool script operates on the user-specified namespace, the automatic completion script obtains the Pod and service list based on the user-specified namespace to achieve automatic namespace completion.
[0034] The present application method is implemented based on the following system.
[0035] System composition: 1. Installation script (install.sh): It is used to install all tool scripts with one click, set execution permissions, configure the auto-completion function, and simplify the deployment process. The namespace parameter has been added, and users can specify the namespace when performing the installation, and the script will automatically replace the default namespace in all tool scripts.
[0036] (II) Tool script: 1. Log query script (f and l): retrieves log information in the specified namespace based on service name, Pod name, and keywords.
[0037] 2. Container entry script (into): Quickly enter the interactive shell of the Pod in the specified namespace.
[0038] 3. Pod list script (p): displays detailed information of all Pods under the specified namespace.
[0039] (3) Autocomplete script: Provides autocomplete functionality based on the specified namespace for tool scripts.
[0040] In order to better understand the technical solution of the present application, it is further described with reference to the following embodiments.
[0041] (1) Installation script (install.sh) #! / bin / bash namespace=$1 sed -i "s / dev / ${namespace} / g" * cat autocomplete>>~ / .bashrc source ~ / .bashrc cp l / usr / bin chmod 755 / usr / bin / l cp f / usr / bin chmod 755 / usr / bin / f cp into / usr / bin chmod 755 / usr / bin / into cp p / usr / bin chmod 755 / usr / bin / p characteristic: Namespace parameterization: By passing in the namespace parameter when executing install.sh, the script uses the sed command to replace the default namespace dev in all tool scripts with the user-specified namespace ${namespace}.
[0042] Execution method: . / install.sh <namespace name> advantage: Enhanced flexibility: Users can specify different namespaces as needed to meet the needs of multi-environment deployment.
[0043] Reduce errors: Avoid manually modifying the namespace in the script to reduce the probability of errors.
[0044] (2) Namespace adaptation of tool scripts like Figure 3 As shown in the figure, all tool scripts (such as f, l, into, and p) support operations on specified namespaces by using the ${namespace} variable in the kubectl command. The installation script automatically replaces the namespace variable in the script.
[0045] Example: In the f script kubectl -n ${namespace} get pod (3) Namespace support for auto-completion scripts function func() { local pd=$(kubectl -n ${namespace} get pod | awk '{print $1}') COMPREPLY=($(compgen -W "${pd}" -- ${COMP_WORDS [COMP_CWORD]})) } complete -F func into complete -F func l function funcf() { local pd=$(kubectl -n ${namespace} get svc | awk '{print $1}') COMPREPLY=($(compgen -W "${pd}" -- ${COMP_WORDS [COMP_CWORD]})) } complete -F funcf f Note: The auto-completion function obtains the Pod and service list according to the specified namespace to achieve accurate auto-completion.
[0046] The workflow of this application method is as follows: (1) Installation process, such as Figure 2 As shown, the installation process includes the following steps: 1. Execute the installation script and specify the namespace: The user executes . / install.sh <namespace> in the command line.
[0047] 2. Namespace replacement: The installation script uses the sed command to replace dev in all tool scripts with the specified namespace.
[0048] 3. Configure auto-completion: Add the autocomplete script content to ~ / .bashrc and it will take effect immediately.
[0049] 4. Deploy tool scripts: Copy the tool scripts to the / usr / bin directory and set executable permissions.
[0050] 5. Installation complete: Users can use tool scripts to operate the specified namespace.
[0051] (2) Usage process The usage process is the same as described above, but all operations are targeted at the namespace specified by the user, which improves the pertinence and security of the operations.
[0052] The technical implementation mechanism of this application method is as follows: (1) Namespace parameterization implementation mechanism a. Parameter input and verification namespace=$1 if [ -z "$namespace" ]; then echo "Error: Namespace parameter is required" echo "Usage: . / install.sh <namespace>" exit 1 fi The namespace types supported by this method include: (a) Development environment namespace: dev, development, staging; (b) Production environment namespace: prod, production; (c) Test environment namespace: test, testing; (d) User-defined namespace: user-defined-{identifier}.
[0053] The namespace naming conventions in this method are as follows: (a) Must comply with DNS subdomain rules; (b) not more than 63 characters in length; (c) can only contain lowercase letters, numbers and "-"; (d) Must start and end with an alphanumeric character.
[0054] b. Namespace replacement process # 1. Back up the original file for file in fl into p autocomplete; do cp $file ${file}.bak done # 2. Perform the replacement operation sed -i "s / \\\\-n dev / \\\\-n ${namespace} / g" * # Replace the namespace parameter in the kubectl command sed -i "s / namespace=\\\\"dev\\\\" / namespace=\\\\"${namespace}\\\\" / g"* # Replace variable definition c. Namespace configuration verification # Verify that the namespace exists kubectl get namespace ${namespace}&> / dev / null if [ $? -ne 0 ]; then echo "Warning: Namespace ${namespace} does not exist" read -p "Do you want to create it? (y / n): " answer if [ "$answer" = "y" ]; then kubectl create namespace ${namespace} fi fi (2) Variable definition mechanism of tool scripts a. Namespace variable definition method # Global variable definition NAMESPACE=${namespace:-dev} # Provide a default value KUBECTL_CMD="kubectl -n ${NAMESPACE}" # Encapsulate kubectl command # Persistent environment variables echo "export K8S_NAMESPACE=${NAMESPACE}">>~ / .bashrc echo "export KUBECTL_CMD='${KUBECTL_CMD}'">>~ / .bashrc b. Variable scope control function set_namespace() { local new_namespace=$1 if [ -n "$new_namespace" ]; then NAMESPACE=$new_namespace KUBECTL_CMD="kubectl -n ${NAMESPACE}" fi } c. Namespace configuration file management # Configuration file location CONFIG_FILE="${HOME} / .kube / namespace_config" # Save configuration echo "${NAMESPACE}">"${CONFIG_FILE}" # Read configuration if [ -f "${CONFIG_FILE}" ]; then NAMESPACE=$(cat "${CONFIG_FILE}") fi (3) Automated configuration and deployment process a. Detailed explanation of sed command usage # Basic replacement sed -i "s / dev / ${namespace} / g" * # Replace dev in all files # Conditional Replacement sed -i " / kubectl.*\\\\-n / s / dev / ${namespace} / g" * # Replace only the namespace in the kubectl command # Multi-mode replacement sed -i -e "s / dev / ${namespace} / g" \\\\ -e "s / DEV / ${namespace^^} / g" \\\\ -e "s / Dev / ${namespace^} / g" * b. Installation script execution process # 1. Permission check if [ "$EUID" -ne 0 ]; then echo "Please run as root" exit 1 fi # 2. Dependency Check for cmd in kubectl sed awk grep; do if ! command -v $cmd&> / dev / null; then echo "Error: $cmd is required but not installed" exit 1 fi done # 3. Back up the existing configuration timestamp=$(date +%Y%m%d_%H%M%S) backup_dir=" / tmp / k8s_tools_backup_${timestamp}" mkdir -p "${backup_dir}" cp / usr / bin / {l,f,into,p} "${backup_dir} / " 2> / dev / null || true # 4. Install new tools for script in lf into p; do install -m 755 $script / usr / bin / $script done (4) Tool script implementation method a. Log query script (f) implementation # 1. Parameter Validation if [ $# -lt 1 ]; then echo "Usage: f <service-name>[search-keyword]" exit 1 fi # 2. Get the Pod list pods=$(${KUBECTL_CMD} get pod | grep "$1" | awk '{print $1}') if [ -z "$pods" ]; then echo "No pods found for service: $1" exit 1 fi # 3. Log retrieval for pod in $pods; do echo "=== Searching logs in pod: $pod ===" if [ -n "$2" ]; then ${KUBECTL_CMD} exec $pod -- sh -c \\\\ "cd / logs&&grep -C3 '$2' \\\\$(ls -t | head -1)" else ${KUBECTL_CMD} logs $pod | tail -n 50 fi done b. Real-time log viewing (l) implementation # 1. Dynamic log tracking function follow_logs() { local pod=$1 local keyword=$2 if [ -n "$keyword" ]; then ${KUBECTL_CMD} logs -f $pod | grep --line-buffered "$keyword" else ${KUBECTL_CMD} logs -f $pod fi } # 2. Error handling function handle_error() { echo "Error: $1" exit 1 } # 3. Main function main() { local pod=$1 local keyword=$2 # Verify Pod existence ${KUBECTL_CMD} get pod $pod> / dev / null 2>&1 || \\\\ handle_error "Pod $pod not found" follow_logs $pod $keyword } Figure 4 The figure shows a Kubernetes cluster operation and maintenance automation operation device based on Shell encapsulation proposed in this application, and the device includes: Parameter configuration module: used to pass user-specified namespace parameters into the installation script; Namespace replacement module: used when starting the installation, the installation script automatically replaces the default namespace in the tool script with the user-specified namespace to implement operations on the user-specified namespace; Automatic completion module: used in the process of tool scripts operating on user-specified namespaces. The automatic completion script obtains the Pod and service list according to the user-specified namespace to achieve automatic completion of the namespace.
[0055] When the above device is running, the steps of the Kubernetes cluster operation and maintenance automation method based on Shell encapsulation disclosed in this application are implemented.
[0056] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the device, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a special hardware-based system that performs the specified function or operation, or can be realized by a combination of special hardware and computer instructions.
[0057] like Figure 5 As shown, the embodiment of the present application also discloses an electronic device, including: a processor 310, a communication interface 320, a memory 330 for storing a processor executable computer program, and a communication bus 340. The processor 310, the communication interface 320, and the memory 330 communicate with each other through the communication bus 340. The processor 310 runs the executable computer program to implement the steps of the above-mentioned Kubernetes cluster operation and maintenance automation method based on Shell encapsulation.
[0058] It is understandable that, in addition to the memory and the processor, the electronic device may also include an input device such as a keyboard, an output device such as a display, and other communication modules. The input device, the output device, and other communication modules communicate with the processor via an I / O interface (i.e., an input / output interface).
[0059] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0060] Furthermore, the present application also discloses a computer-readable storage medium. When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute each step of the Shell-encapsulated Kubernetes cluster operation and maintenance automation method disclosed in the present application.
[0061] In the context of the present application, a computer-readable storage medium may be a tangible medium, more specific examples of which would include a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0062] In particular, according to an embodiment of the present application, the process described in the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the Kubernetes cluster operation and maintenance automation operation method based on Shell encapsulation disclosed in the present application. When the computer program is executed by the processing device, the above functions defined in the method of the embodiment of the present application are executed.
[0063] Although several specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present application. The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present application is not limited to the technical solutions formed by a specific combination of the above technical features, but also should cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above public concept.
[0064] Those skilled in the art should also understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application. < / namespace>
Claims
1. A Kubernetes cluster operation and maintenance automation method based on Shell encapsulation, characterized in that: The method comprises: Pass user-specified namespace parameters into the installation script; When starting the installation, the installation script automatically replaces the default namespace in the tool script with the user-specified namespace, and the tool script implements operations on the user-specified namespace; When the tool script operates on the user-specified namespace, the automatic completion script obtains the Pod and service list based on the user-specified namespace to achieve automatic namespace completion.
2. The method according to claim 1, characterized in that In the method: The installation script is used to install all tool scripts in one click, set execution permissions, configure the auto-completion function, and specify the namespace when performing the installation based on the namespace parameter; The tool script includes: Log query script: used to retrieve log information in a specified namespace based on service name, Pod name, and keywords; Container entry script: used to quickly enter the interactive shell of the Pod in the specified namespace; Pod list script: used to display detailed information of all Pods in a specified namespace; The automatic completion script is used to provide an automatic completion function based on a specified namespace for the tool script.
3. The method according to claim 2, characterized in that When starting the installation, the installation script passes in the user-specified namespace parameter when executing install.sh, and then uses the sed command to automatically replace the default namespace in all tool scripts with the user-specified namespace; The tool script implements operations on the user-specified namespace by using the user-specified namespace variable in the kubectl command.
4. The method according to claim 2, characterized in that: The tool script defines the namespace in a variable manner, including the following steps: (1) Select a namespace variable definition method, which includes global variable definition and environment variable persistence; (2) Control variable scope; (3) Namespace configuration file management, including determining the configuration file location, saving the configuration, and reading the configuration.
5. The method according to claim 1, characterized in that The method also includes an installation process, including the following steps: Execute the installation script and specify the namespace: The user executes . / install.sh <namespace> in the command line; Namespace replacement: The installation script uses the sed command to replace the default namespace in all tool scripts with the user-specified namespace; Configure auto-completion: Add the auto-completion script content to ~ / .bashrc and it will take effect immediately; Deploy tool scripts: Copy the tool scripts to the / usr / bin directory and set executable permissions; Installation complete: Users can use tool scripts to specify namespaces.
6. The method according to claim 1, characterized in that The user-specified namespace includes the following types: (1) Development environment namespace; (2) Production environment namespace; (3) Test environment namespace; (4) User-defined namespace; The naming conventions of the user-specified namespace are as follows: (a) Comply with DNS subdomain rules; (b) not more than 63 characters in length; (c) can only contain lowercase letters, numbers and "-"; (d) Must begin and end with a letter or number.
7. The method according to claim 1, characterized in that The installation script automatically replaces the default namespace in the tool script with the user-specified namespace, and the replacement process includes the following steps: (1) Back up the original files; (2) Use the sed command to perform replacement operations, including basic replacement, conditional replacement, and multi-mode replacement; (3) Verify the namespace configuration.
8. A Kubernetes cluster operation and maintenance automation device based on Shell encapsulation, characterized in that: The device comprises: Parameter configuration module: used to pass user-specified namespace parameters into the installation script; Namespace replacement module: used when starting the installation, the installation script automatically replaces the default namespace in the tool script with the user-specified namespace to implement operations on the user-specified namespace; Automatic completion module: used in the process of tool scripts operating on user-specified namespaces. The automatic completion script obtains the Pod and service list according to the user-specified namespace to achieve automatic completion of the namespace.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by the processor, the steps of the Shell-encapsulated Kubernetes cluster operation and maintenance automation operation method are implemented as described in any one of claims 1 to 7.
10. An electronic device, characterized in that: include: Memory and processor; Memory: used to store computer programs; Processor: used to execute the computer program to implement the steps of the Shell-encapsulated Kubernetes cluster operation and maintenance automation operation method as described in any one of claims 1 to 7.