You can perform the steps in the quickstart by using either the migctl
tool
or the Google Cloud Console. migctl
is a command-line tool for
setting up and managing a Migrate for Anthos migration environment on
Google Cloud. migctl
is available in Cloud Shell.
Before you begin
Enable support for Compute Engine
-
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
-
In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.
- Enable the Compute Engine API.
Enable and configure GKE
Before you start, make sure you have performed the following tasks:
- Ensure that you have enabled the Google Kubernetes Engine API. Enable Google Kubernetes Engine API
- Ensure that you have installed the Cloud SDK.
Set up default gcloud
settings using one of the following methods:
- Using
gcloud init
, if you want to be walked through setting defaults. - Using
gcloud config
, to individually set your project ID, zone, and region.
Using gcloud init
If you receive the error One of [--zone, --region] must be supplied: Please specify
location
, complete this section.
-
Run
gcloud init
and follow the directions:gcloud init
If you are using SSH on a remote server, use the
--console-only
flag to prevent the command from launching a browser:gcloud init --console-only
-
Follow the instructions to authorize
gcloud
to use your Google Cloud account. - Create a new configuration or select an existing one.
- Choose a Google Cloud project.
- Choose a default Compute Engine zone for zonal clusters or a region for regional or Autopilot clusters.
Using gcloud config
- Set your default project ID:
gcloud config set project PROJECT_ID
- If you are working with zonal clusters, set your default compute zone:
gcloud config set compute/zone COMPUTE_ZONE
- If you are working with Autopilot or regional clusters, set your default compute region:
gcloud config set compute/region COMPUTE_REGION
- Update
gcloud
to the latest version:gcloud components update
Creating a VM with a web server
In the following steps, you create a simple Compute Engine VM that serves a "Hello World!" web page. Having the page gives you something to test after migration.
Run the following command to create the VM instance that you migrate.
Specify a zone that is the same zone in which you create a GKE cluster later in this topic.
gcloud compute instances create quickstart-instance \ --project=project-id --zone=zone --machine-type=n1-standard-1 \ --subnet=default --scopes="cloud-platform" \ --tags=http-server,https-server --image=ubuntu-minimal-1604-xenial-v20210119a \ --image-project=ubuntu-os-cloud --boot-disk-size=10GB --boot-disk-type=pd-standard \ --boot-disk-device-name=quickstart-instance
Run the following command to create a firewall rule that allows requests to the instance over HTTP.
gcloud compute --project=project-id firewall-rules create default-allow-http \ --direction=INGRESS --priority=1000 --network=default --action=ALLOW \ --rules=tcp:80 --source-ranges=0.0.0.0/0 --target-tags=http-server
In the Google Cloud Console, go to the VM instances page.
In the list of virtual machine instances, click SSH in the row of the instance you just created.
For more on connecting by SSH, see Connecting to instances.
In the quickstart-instance command window, use the package manager to install the
apache2
package.sudo apt-get update && sudo apt-get install apache2 -y
After installing Apache, the operating system automatically starts the Apache server.
In the same command window, overwrite the Apache web server default web page with the following command:
echo '<!doctype html><html><body><h1>Hello World!</h1></body></html>' | sudo tee /var/www/html/index.html
In the VM instances page, locate the row for the instance you created and copy the External IP address.
Paste the instance's IP address to your browser address bar. Prefix it with
http://
.You should now see the "Hello World!" page.
In the VM instances page, select the checkbox at the left end of the row for the instance you created.
At the top of the page, click the Stop button to stop the VM.
Creating a processing cluster and installing Migrate for Anthos
In the following steps, you create a GKE cluster in the Cloud that you use as a processing cluster. This is where you install Migrate for Anthos and execute the migration.
In Cloud Shell, use the following command to create a new Kubernetes cluster to use as a processing cluster.
When specifying the
machine-type
value, be sure to specify a machine type that has at least 15 GB of memory.gcloud container clusters create migration-processing \ --project=project-id --zone=zone --machine-type n1-standard-4 \ --image-type ubuntu --num-nodes 1 --enable-stackdriver-kubernetes \ --subnetwork "projects/project-id/regions/region/subnetworks/default"
Install Migrate for Anthos.
migctl
To enable Migrate for Anthos to access Container Registry and Cloud Storage, you must create a service account with the storage.admin role:
In Cloud Shell, create the
m4a-install
service account:gcloud iam service-accounts create m4a-install \ --project=PROJECT_ID
Grant the
storage.admin
role to the service account:gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:m4a-install@PROJECT_ID.iam.gserviceaccount.com" \ --role="roles/storage.admin"
Download the key file for the service account:
gcloud iam service-accounts keys create m4a-install.json \ --iam-account=m4a-install@PROJECT_ID.iam.gserviceaccount.com \ --project=PROJECT_ID
Connect to the cluster.
gcloud container clusters get-credentials migration-processing \ --zone zone --project project-id
In Cloud Shell, set up Migrate for Anthos components on your processing cluster by using the
migctl
command-line tool included with Migrate for Anthos:migctl setup install --json-key=m4a-install.json
Validate the Migrate for Anthos installation.
Use the
migctl doctor
command to confirm a successful deployment.migctl doctor
It may take more than a minute before the command returns the following success result.
[✓] Deployment
Console
Google Cloud Console can help you with the installation process by generating the necessary installation commands and running them in Cloud Shell.
Open the Migrate for Anthos page in the Cloud Console.
Click Add Processing Cluster.
Select the cluster you created above,
migration-processing
, from the drop-down list.Execute each of the commands in Cloud Shell to:
- Create a service account that allows Migrate for Anthos to access Container Registry and Cloud Storage.
- Install Migrate for Anthos components.
Use the last Cloud Shell command to monitor the installation status.
Before the installation has completed, you might see a message such as the following. If so, wait a few minutes for the installation to finish before running
migctl doctor
again.migctl doctor [!] Deployment validation job is in-progress
In the following example output, the check mark indicates that Migrate for Anthos has been successfully deployed.
migctl doctor [✓] Deployment
Select Done after installation succeeds.
Migrating the VM
In the following steps, you create a migration plan with migration details, then use it to migrate the VM.
Specify the migration source as a Compute Engine VM. This step adds the source specification to the migration plan.
migctl
To use Compute Engine as a migration source, you must first create a service account with the compute.viewer and compute.storageAdmin roles:
In Cloud Shell, create the
m4a-ce-src
service account:gcloud iam service-accounts create m4a-ce-src \ --project=PROJECT_ID
Grant the
compute.viewer
role to the service account:gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:m4a-ce-src@PROJECT_ID.iam.gserviceaccount.com" \ --role="roles/compute.viewer"
Grant the
compute.storageAdmin
role to the service account:gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:m4a-ce-src@PROJECT_ID.iam.gserviceaccount.com" \ --role="roles/compute.storageAdmin"
Download the key file for the service account:
gcloud iam service-accounts keys create m4a-ce-src.json \ --iam-account=m4a-ce-src@PROJECT_ID.iam.gserviceaccount.com \ --project=PROJECT_ID
Create the migration source:
migctl source create ce quickstart-source --project project-id --json-key=m4a-ce-src.json
Where
m4a-ce-src.json
specifies the service account you created above.
Console
Open the Migrate for Anthos page in the Cloud Console.
Click Add Source.
Select a cluster where you have already installed the Migrate for Anthos components from the drop-down list .
Click Next.
Specify the name of the migration as
quickstart-source
.Set the Source type to Compute Engine.
Click Next.
Select the project that contains the VM that you want to migrate.
Create a service account that enables you to use Compute Engine as a migration source by selecting Create a new service account. You are prompted to enter the name of the new service account.
Click Next.
Select Add Source.
Create a migration.
migctl
This command creates a migration plan that defines what to migrate.
migctl migration create my-migration --source quickstart-source \ --vm-id quickstart-instance --intent Image
When the migration status shows that the migration has been created, you can move on to the next step:
migctl migration status my-migration NAME CURRENT-OPERATION PROGRESS STEP STATUS AGE my-migration GenerateMigrationPlan [1/3] CreateSourceSnapshots Running 13s
Console
Open the Migrate for Anthos page in the Cloud Console.
Click Create Migration.
Set the Migration name as
migration
.Select the migration source you created in the previous step:
quickstart-source
.Set the source VM name or ID to
quickstart-instance
.Set the Migration intent as
Image
.Click Create Migration.
When the migration completes, the Status column displays Migration plan generated.
Review the migration plan.
In this Quickstart, you only review the migration plan. However, you can also edit it. See Customizing a migration plan for more.
migctl
You must download the migration plan to review it:
Download the migration plan:
migctl migration get my-migration
Open the downloaded migration plan,
my-migration.yaml
, in a text editor to review it.If you made any changes, upload the edited migration plan (no changes are required to complete the quickstart):
migctl migration update my-migration --file my-migration.yaml
Console
Review the migration plan in the Google Cloud Console by using the YAML editor:
In the row for the desired migration, select Review and edit migration plan in the Next steps dropdown.
Review the migration plan.
Click the "X" icon in the upper-right corner to close the plan without editing it.
Migrate the VM using the migration plan.
This step migrates the VM and generate artifacts you can use to deploy the workload.
migctl
migctl migration generate-artifacts my-migration
Console
Open the Migrate for Anthos page in the Cloud Console.
In the row for the desired migration, select Generate artifacts in the Next steps dropdown.
After the migration begins, check its status until it finishes.
The migration can take several minutes. During this time, checking the status reports the migration's current state.
migctl
migctl migration status my-migration
When the migration completes, you should see a message such as the following:
migctl migration status my-migration NAME CURRENT-OPERATION PROGRESS STEP STATUS AGE my-migration GenerateArtifacts [1/1] ExtractImage Completed 14m23s
Console
Open the Migrate for Anthos page in the Cloud Console.
View the status of a migration by:
Clicking the migration name. The Migration details panel opens to display the migration status and other information.
Viewing the Status column for the row for your migration.
When migration creation completes, the Status displays Migration plan generated.
Deploying the migrated workload
In the following steps, you get the deployment artifacts you generated during migration, then use them to deploy your migrated workload to the cluster. As a last step, you confirm that the "Hello World!" web page is available from your migrated app.
Once the migration is complete, download the generated YAML artifacts.
migctl
migctl migration get-artifacts my-migration
Console
Open the Migrate for Anthos page in the Cloud Console.
In the row for the desired migration, select Review artifacts under Options.
In the panel that opens on the right, download each artifact separately.
The downloaded artifact files generated during the migration include:
deployment_spec.yaml
-- The YAML file that configures your workload.- Dockerfile -- The Dockerfile used to build the image for your migrated VM.
migration.yaml
-- A copy of the migration plan.
Open the
deployment_spec.yaml
file and locate theService
object whose name isquickstart-instance
.Beneath the
Service
definition, paste anotherService
that exposes port 80 for access to your web server over HTTP, then save the file.Paste the highlighted code so that you have the following in your deployment spec.
apiVersion: v1 kind: Service metadata: creationTimestamp: null name: quickstart-instance spec: clusterIP: None selector: app: quickstart-instance type: ClusterIP status: loadBalancer: {} --- apiVersion: v1 kind: Service metadata: name: hello-service spec: selector: app: quickstart-instance ports: - protocol: TCP port: 80 targetPort: 80 type: LoadBalancer
Apply the deployment spec YAML to deploy the workload.
kubectl apply -f deployment_spec.yaml
It may take a few minutes for the deployment to finish.
Check for an external IP address.
kubectl get service hello-service
When the web server is ready, you see an external IP address for the
hello-service
you added.kubectl get service hello-service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-service LoadBalancer 10.23.241.124 ##.##.###.## 80:32611/TCP 5m4s
Test the migration by opening a browser and visiting the web page at the external IP address (be sure to use HTTP, rather than HTTPS).
http://##.##.###.##
You can execute bash
commands on the container with your migrated workload. For
more, see the Troubleshooting topic.
Clean up
To avoid unnecessary Google Cloud charges, use the Google Cloud Console to delete your project if you do not need it.