• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Search

move

GCP Move VM to another VPC

June 19, 2022

Here’s how to move a VM to another VPC.

Stop VM.

gcloud compute instances stop $INSTANCE_NAME \
--zone $ZONE_NAME \
--project $PROJECT_ID

gcloud compute instances stop $INSTANCE_NAME \ --zone $ZONE_NAME \ --project $PROJECT_ID

Move VM to another VPC.

gcloud compute instances network-interfaces update $INSTANCE_NAME \
--zone $ZONE_NAME \
--network-interface=nic0 \
--network $YOUR_NETWORK \
--subnetwork $YOUR_SUBNETWORK \
--project $PROJECT_ID

gcloud compute instances network-interfaces update $INSTANCE_NAME \ --zone $ZONE_NAME \ --network-interface=nic0 \ --network $YOUR_NETWORK \ --subnetwork $YOUR_SUBNETWORK \ --project $PROJECT_ID

Start VM.

gcloud compute instances start $INSTANCE_NAME \
--zone $ZONE_NAME \
--project $PROJECT_ID

gcloud compute instances start $INSTANCE_NAME \ --zone $ZONE_NAME \ --project $PROJECT_ID

Filed Under: Cloud Tagged With: gcp, move, vm, vpc

AWS Move Instance to Another Zone

December 23, 2021

Here’s how to move an AWS instance to another zone.

Stop the instance first.

aws ec2 stop-instances --instance-ids i-1234567890abcdef0

aws ec2 stop-instances --instance-ids i-1234567890abcdef0

Create an AMI image.

aws ec2 create-image \
--instance-id i-1234567890abcdef0 \
--name "my-ami" \
--description "my-ami"

aws ec2 create-image \ --instance-id i-1234567890abcdef0 \ --name "my-ami" \ --description "my-ami"

Create EC2 instance using Terraform. The contents of main.tf.

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
    }
  }
}
provider "aws" {
  profile = "default"
  region  = "us-east-1"
}
resource "aws_instance" "ulysses" {
  ami                           = "ami-1234567890abcdef0"
  key_name                      = "servers"
  iam_instance_profile          = "machine-role"
  instance_type                 = "t3.micro"
  subnet_id                     = "subnet-1234567890abcdef0"
  security_groups               = ["sg-1234567890abcdef0", "sg-1234567890abcdef1"]
  tags = {
    Name = "moving-instance"
    tag1 = "test1"
    tag2 = "test2"
  }
}

terraform { required_providers { aws = { source = "hashicorp/aws" } } } provider "aws" { profile = "default" region = "us-east-1" } resource "aws_instance" "ulysses" { ami = "ami-1234567890abcdef0" key_name = "servers" iam_instance_profile = "machine-role" instance_type = "t3.micro" subnet_id = "subnet-1234567890abcdef0" security_groups = ["sg-1234567890abcdef0", "sg-1234567890abcdef1"] tags = { Name = "moving-instance" tag1 = "test1" tag2 = "test2" } }

Launch it.

terraform init
terraform plan
terraform apply

terraform init terraform plan terraform apply

Filed Under: Cloud Tagged With: aws, ec2, instance, move, zone

Migrate VM to Other Network

July 20, 2021

Here’s how to move a VM to another network.

Stop the VM.

gcloud compute instances stop server-name \
--zone=us-central1-c \
--project project-id

gcloud compute instances stop server-name \ --zone=us-central1-c \ --project project-id

Migrate the VM. Use self link for network and subnetwork.

gcloud compute instances network-interfaces update server-name \
--zone=us-central1-c \
--network-interface=nic0 \
--network=your-network \
--subnetwork=your-sub-network \
--project project-id

gcloud compute instances network-interfaces update server-name \ --zone=us-central1-c \ --network-interface=nic0 \ --network=your-network \ --subnetwork=your-sub-network \ --project project-id

Start the VM.

gcloud compute instances start server-name \
--zone=us-central1-c \
--project project-id

gcloud compute instances start server-name \ --zone=us-central1-c \ --project project-id

Filed Under: Cloud Tagged With: compute, gcloud, gcp, instance, move, network, network-interface, start, stop

GCP Move Instance to Another Zone

December 13, 2019

Moving a GCP instance to another zone is actually much simpler than initially thought. It’s just a single gcloud command.

gcloud compute instances move instance-name \
--zone us-central1-a \
--destination-zone us-central1-b

gcloud compute instances move instance-name \ --zone us-central1-a \ --destination-zone us-central1-b

A few details about moving to another zone.

  • VM has to be running.
  • You may get a new internal or external IP address
  • Local SSDs are ephemeral, so you can’t move them.
  • When moving between regions, you may have to select a subnetwork.
  • You may have to change GPUs available in the destination if you use them.

Filed Under: Cloud Tagged With: gcloud, gcp, instance, move, sdk, zone

GCP Move Instance to Another Project

December 11, 2019

Here’s how to copy a disk from one project to another.

gcloud compute disks create lamp-server \
--source-snapshot https://www.googleapis.com/compute/v1/projects/project-id/global/snapshots/lamp-server \
--project next-project-id \
--zone us-central1-a

gcloud compute disks create lamp-server \ --source-snapshot https://www.googleapis.com/compute/v1/projects/project-id/global/snapshots/lamp-server \ --project next-project-id \ --zone us-central1-a

Once all the disks are copied. You can create a snapshot of the boot.

gcloud compute disks snapshot lamp-server

gcloud compute disks snapshot lamp-server

Create an instance from snapshot.

gcloud compute disks create "hostname-boot" \
--project "project-id" \
--zone "us-central1-a" \
--source-snapshot "snapshot-name" \
--type "pd-standard" \
--size "100"

gcloud compute disks create "hostname-boot" \ --project "project-id" \ --zone "us-central1-a" \ --source-snapshot "snapshot-name" \ --type "pd-standard" \ --size "100"

Filed Under: Cloud Tagged With: create, disks, gcp, instance, move, project, snapshots

  • Go to page 1
  • Go to page 2
  • Go to Next Page »
  • Home
  • About
  • Search

Copyright © 2023