Fully Automating KVM Virtual Machine Deployment with SaltStack
This article explains the evolution of KVM deployment methods, presents a design for a one‑click fully automated KVM provisioning system, and showcases the actual code and SaltStack states that enable rapid, repeatable virtual machine creation and configuration.
1. Deployment Scenarios for KVM Virtual Machines
Scenario 1: Manual. Install KVM management tools and UI, then manually create and install the VM system before deploying applications. Expected time: one day per environment.
Scenario 2: Manual‑plus‑cloning. Use KVM tools and VM images, copy‑clone to deploy systems, then integrate some applications. Expected time: one day for several environments.
Scenario 3: Scripted automation. Combine KVM commands, VM image templates, and custom batch scripts to follow standardized steps, creating VMs quickly. Expected time: half a day for dozens of systems.
KickStart can also automate installation, but its rigid configuration and DHCP networking make large‑scale, flexible deployment difficult.
Scenario 4: Commercial cloud platforms. Use solutions like VMware, clicking buttons to deploy dozens of environments.
Scenario 5: Self‑developed automation. Build a custom solution, possibly based on OpenStack or CloudStack, to meet specific cost, quality, efficiency, scale, and environment requirements. This article focuses on this fifth approach—self‑developed, fully automated KVM deployment.
2. Design Idea for Fully Automated KVM Deployment
The KVM deployment platform is a module of our self‑developed operations automation system. Users only need to set custom parameters and click a button to trigger full system deployment.
When the "Start Deployment" request is submitted, the front‑end passes the parameters to the application logic, which forwards commands and parameters to a SaltStack server. The SaltStack server then executes a series of configuration and deployment tasks on the target KVM host and returns the results to the front‑end.
The main steps performed by the web‑application logic are illustrated below:
After the SaltStack server receives the task, it dispatches the job to the Salt minion (the physical KVM host) and runs the defined Salt states.
The Salt state execution flow is shown in the following diagram:
Sample execution results are displayed below:
When the process finishes, the system, applications, IP address, and hostname are all fully provisioned, as shown here:
3. Code Implementation for Full Automation
Key parts of the web‑application logic include:
Testing IP connectivity and detecting IP conflicts. (Code shown in the image below)
Calling SaltStack commands to test for hostname conflicts on the physical host. (Code shown in the image below)
The main Salt state execution steps are also illustrated:
These Salt states handle tasks such as retrieving KVM images, starting the system, and customizing IP addresses and hostnames, enabling fully automated, repeatable KVM provisioning.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.