Project | LXD |
Status | Draft |
Author(s) | @gabrielmougard |
Approver(s) | @stgraber @tomp |
Release | 5.15 |
Internal ID | LXXXX |
Abstract
This adds support for instance rebuild.
Rationale
There are multiple reasons that can justify to rebuild an instance.
- In rebuilding a LXD instance (keeping the same instance configurations), you can be sure to have the same exact instance as the one you initially created. It could be useful to start with a fresh instance filesystem in case you want to reset it.
- Rebuilding the instance also gives you the opportunity to update its base image while keeping the instance configuration. It can be useful in case of operating system updates.
- Lastly, if you want to update the applications running in the instance or you want to fix a bug after it has been deployed, rebuilding the LXD instance can be an effective way to fix the issue. You can make the necessary changes to the code or configuration files, rebuild the instance, and then deploy the updated version.
Specification
Design
The instance could be rebuilt in three different ways:
- We could rebuild it as empty
- We could rebuild it with the original instance’s image.
- Or, we could rebuild it with a different base image.
In order to do that, we would need to replace its root disk with a fresh copy of the same or alternate image.
A simple approach would be to just erase the content of the underlying storage volume of the container and unpack the new rootfs from the same or alternate image. For that we could we could delete and re-create the underlying instance volume using the appropriate image unpacker. Also, we chose to prevent a rebuild if an instance has snapshots.
In the case where we would choose a different image from the orignal one, we would also want to check that the existing volume can hold the new rootfs. If this is not the case, we might need to grow the volume before overwriting it.
API changes
A new field in InstancesPost
will be added:
type InstancesPost struct {
...
Rebuild bool `json:"rebuild" yaml:"rebuild"`
}
CLI changes
The rebuild
will be added and will be as follow:
lxc rebuild [[<remote>:]<image>...] [<remote>:]<instance> [--empty]
Here are some use cases supposing we have an existing instance called c1
which is in a stopped state:
-
lxc rebuild c1
- Rebuild
c1
using its original image
- Rebuild
-
lxc rebuild c1 --empty
- Rebuild
c1
as empty (in the same fashion aslxc init c1 --empty
)
- Rebuild
-
lxc rebuild images:ubuntu/jammy c1
- Rebuild
c1
using a different image
- Rebuild
Database changes
No datababse changes.