Migrating an instance to a new cloud
Occasionally, due to upgrades, data center moves or other unforeseen events, it becomes necessary to migrate your instances from one OpenStack cloud to another.
In this example, we’re going to take a snapshot of an instance (a simple one just running nginx), download it to our local machine and then upload it back up to the new cloud. First, let’s take a look at our instance.
We can see that nginx
is running from inside the instance; let’s check out the instance itself.
(Note: I have named the instance snap_test
, so I can grep
for it specifically):
From here we can see the external IP of the instance; let’s visit it to make sure nginx
is up and running:
So now that we know it’s up and running, let’s get it moved over to our new cloud.
First, a note about sourcing. You’ll need to have sourced the credentials of your existing cloud to run the cloud commands necessary to run the snapshotting and moving. In this case, I have installed python-openstackclient
on my Mac and grabbed the stackrc
from my cloud, by clicking on Download OpenStack RC File on the right, as this image shows:
Make sure you source your stackrc
:
That done, let’s snapshot our instance. We know its instance ID from the previous Nova command, so let’s just do it:
You can follow along in Horizon if you like; you should see the Task of your instance change to snapshotting and then uploading. After that, you should be able to see your snapshot in the image-list
:
Once it’s done (and it may take a bit, depending on the image size) and the image shows as ACTIVE, go ahead and download it to your local machine:
Once that download completes, you now have the image saved locally. Let’s turn around and immediately upload it into our new cloud. First, make sure to source the stackrc
from that cloud to make sure you’re interacting with the right one, then go ahead and upload the snapshot you created:
A note about the image-create
command when you use Glance. In the previous command, here’s what we did:
--container-format:
Container format of image. Acceptable formats: ami
,
ari
, aki
, bare
, and ovf
.
--disk-format:
Disk format of image. Acceptable formats: ami
, ari
,
aki
, vhd
, vmdk
, raw
, qcow2
, vdi
, and iso
. (Note that OpenStack uses qcow2
for all images internally.)
--name
Name of your image.
--file
Local file that contains a disk image to be uploaded
during creation. Alternatively, images can be passed
to the client via stdin
.
When that completes, let’s boot an instance from the snapshot:
In the previous command (nova boot --image snap_migration --nic net-id=ba0fdd03-72b5-41eb-bb67-fef437fd6cb4 --security-groups jksec --flavor m1.tiny snap_migration_test
) I used the --nic net-id
that I gained by running nova net-list
and grabbing the ID of the internal network. Likewise, the --security-groups
variable jksec
came from running nova secgroup-list
, both commands being run using the API. You can find both commands in the Horizon panel as well.
Once our instance comes up, we need to give it an external IP in order for nginx
to be able to be reached from the outside. Speaking of which, make sure to allow port 80
ingress on your new cloud security group so your instance is reachable that way.
Finally, let’s test our moved instance to make sure nginx
is up and running without issue (remember, we haven’t even logged into the instance, this is a drag and drop procedure thus far):
That’s it! Thanks!