arrow_back

Migrate to Containers: Qwik Start

Anmelden Teilnehmen
Testen und teilen Sie Ihr Wissen mit unserer Community.
done
Sie erhalten Zugriff auf über 700 praxisorientierte Labs, Skill-Logos und Kurse

Migrate to Containers: Qwik Start

Lab 1 Stunde universal_currency_alt 1 Guthabenpunkt show_chart Einsteiger
info Dieses Lab kann KI-Tools enthalten, die den Lernprozess unterstützen.
Testen und teilen Sie Ihr Wissen mit unserer Community.
done
Sie erhalten Zugriff auf über 700 praxisorientierte Labs, Skill-Logos und Kurse

GSP682

Google Cloud self-paced labs logo

Overview

VM instances can exist on premises, managed by products such as VMWare vSphere, and in public clouds such as AWS or Azure, in addition to Google Cloud Compute Engine instances.

Anthos is an open source application platform that enables you to modernize your existing applications in your hybrid or multi-cloud environment. You can build new VMs and run them anywhere in a secure manner. Anthos is built on open source technologies pioneered by Google — including Kubernetes, Istio, and Knative — and enables consistency between on-premises and cloud environments.

When workloads are upgraded to containers, IT departments can eliminate OS-level maintenance and security patching for VMs and automate policy and security updates at scale. Monitoring across on-premises and cloud environments is done through a single interface in the Cloud Console.

Migrate to Containers provides an almost real-time solution to take an existing VM and make it available as a Kubernetes hosted pod with all the values associated with executing your applications in a Kubernetes cluster.

In this lab you create a simple Compute Engine virtual machine (VM), then use Migrate to Containers to migrate the VM to a GKE processing cluster in the Cloud. You can perform the steps using either the m2c tool or the Cloud Console. m2c is a command-line tool for setting up and managing a Migrate to Containers migration environment on Google Cloud. m2c is available in Cloud Shell.

How Migrate to Containers allows you to containerize faster than other possibilities:

Container migration architecture diagram.

Objectives

You will learn how to perform the following tasks:

  • Create a Compute Engine instance hosting a Web Server.
  • Create a GKE cluster to host the migrated Compute Engine instance.
  • Migrate the Compute Engine instance using Migrate to Containers.
  • Test the Web Server that exists in GKE.

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.

This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details pane.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details pane.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field. Navigation menu icon and Search field

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

  2. Click through the following windows:

    • Continue through the Cloud Shell information window.
    • Authorize Cloud Shell to use your credentials to make Google Cloud API calls.

When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

Output:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.
  1. Set an environment variable for your Project ID:
export PROJECT_ID=$DEVSHELL_PROJECT_ID

Task 1. Create the source Compute Engine

  1. Run the following command to create and configure a Compute Engine instance that will act as the source of the VM to be migrated:
gcloud compute instances create source-vm --zone={{{project_0.startup_script.lab_zone | zone}}} --machine-type=e2-standard-2 --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=source-vm --metadata startup-script={{{project_0.startup_script.metadata_script|METADATA_SCRIPT}}}

You have installed the Apache web server and created a basic web page via the startup script.

Sample output:

Created [https://www.googleapis.com/compute/beta/projects/qwiklabs-gcp-02-ace18e67a4ba/zones/{{{project_0.startup_script.lab_zone | zone}}}/instances/source-vm]. NAME: source-vm ZONE: {{{project_0.startup_script.lab_zone | zone}}} MACHINE_TYPE: e2-standard-2 PREEMPTIBLE: INTERNAL_IP: 10.128.0.2 EXTERNAL_IP: 34.70.249.10 STATUS: RUNNING
  1. Create a firewall rule to allow the HTTP:
gcloud compute 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

Sample output:

Creating firewall...working..Created [https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-04-1126b7a391de/global/firewalls/default-allow-http]. Creating firewall...done. NAME: default-allow-http NETWORK: default DIRECTION: INGRESS PRIORITY: 1000 ALLOW: tcp:80 DENY: DISABLED: False

Click Check my progress to verify the objective. Create the source Compute Engine

  1. In the Cloud Console navigate to Compute Engine > VM instances and locate the row for the instance you created and copy the External IP address.

  2. Paste the instance's IP address to your browser address bar. Prefix it with http://.

You should now see the "Hello World" page.

Task 2. Create a processing cluster

In the following steps you'll create a GKE cluster in the Cloud that you'll use as a processing cluster. This is where you'll install Migrate to Containers and execute the migration.

  • In Cloud Shell use the following command to create a new Kubernetes cluster to use as a processing center:
gcloud container clusters create migration-processing --project=$PROJECT_ID --zone={{{project_0.startup_script.lab_zone | zone}}} --machine-type e2-standard-4 --image-type ubuntu_containerd --num-nodes 3 --enable-stackdriver-kubernetes --subnetwork "projects/$PROJECT_ID/regions/{{{project_0.startup_script.lab_region | region}}}/subnetworks/default" Note: Be sure you specify the same zone here that you specified when creating the VM.

Sample output:

Creating cluster migration-processing in {{{project_0.startup_script.lab_zone | zone}}} ...done. Created [https://container.googleapis.com/v1/projects/qwiklabs-gcp-04-1126b7a391de/zones/{{{project_0.startup_script.lab_zone | zone}}}/clusters/migration-processing]. To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/{{{project_0.startup_script.lab_zone | zone}}}/migration-processing?project=qwiklabs-gcp-04-1126b7a391de kubeconfig entry generated for migration-processing. NAME: migration-processing LOCATION: {{{project_0.startup_script.lab_zone | zone}}} MASTER_VERSION: 1.30.5-gke.1443001 MASTER_IP: 34.77.241.217 MACHINE_TYPE: e2-medium NODE_VERSION: 1.30.5-gke.1443001 NUM_NODES: 1 STATUS: RUNNING

Click Check my progress to verify the objective. Create a processing cluster

Task 3. Install Migrate to Containers

Installing the Skaffold and __Migrate to Containers CLI (m2c). Skaffold is a tool for development workflows with Kubernetes and m2c is a command-line tool that streamlines the process of migrating existing workloads to containerized deployments.

  1. In Google Cloud Shell, install Skaffold by running the following command:
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && \ sudo install skaffold /usr/local/bin/
  1. Next, download the Migrate to Containers CLI.
curl -O "https://m2c-cli-release.storage.googleapis.com/$(curl -s https://m2c-cli-release.storage.googleapis.com/latest)/linux/amd64/m2c" chmod +x ./m2c

Task 4. Migrating the VM

Now you'll create a migration plan with migration details, then use it to migrate the VM.

When you copy a source VM file system, the Migrate to Containers CLI uses default filters to reduce the size of the copied file system. However, to make the Apache server available to start up, the server needs the /var/log directory, which is removed by the default filters.

  1. In Cloud Shell tab, get a list of the default Migrate to Containers filters in a file called filters.txt:
./m2c copy default-filters > filters.txt
  1. To edit the default filters, removed the - /var/log/* line from the filters.txt file using sed command.
sed -i '/\/var\/log\/*/d' filters.txt
  1. Next, copy the source machine's file system by running the following command:
./m2c copy gcloud \ --project $PROJECT_ID --zone {{{project_0.default_zone | Zone}}} \ --vm-name source-vm --output vm-filesystem \ --filters filters.txt

Sample output:

I Initializing connection {"VM Name": "source-vm"} E ssh init WARNING: The private SSH key file for gcloud does not exist. E ssh init WARNING: The public SSH key file for gcloud does not exist. E ssh init WARNING: You do not have an SSH key for gcloud. E ssh init WARNING: SSH keygen will be executed to generate a key. E ssh init Using OS Login user [student-04-900d18a09f34] instead of requested user [m2c] E ssh init Warning: Permanently added 'compute.7299044666357178971' (ED25519) to the list of known hosts. E convert gcloud to ssh Using OS Login user [student-04-900d18a09f34] instead of requested user [m2c] I Copying fs using rsync... E rsync Exit request sent. I Copy ended sucessfully, you can use "vm-filesystem" as a source for next operations Note: If you encounter the `Error: failed to initiate`, wait a few minutes and then try running the command again.

Create a migration plan

We will begin migrating VMs by creating a migration. This will result in the creation of a migration plan object.

A migration is the central object used to perform migration actions, monitor migration activities, and track status using the m2c tool or the Cloud Console. The migration object is implemented as a Kubernetes Custom Resource Definition (CRD).

Next, you will create a migration plan by running the m2c tool.

  1. On the Cloud Shell tab, create the migration plan:
./m2c analyze \ --source vm-filesystem --plugin linux-vm-container \ --output analysis-output

Sample output:

I Running analysis... E analysis container time="2024-06-20T10:22:50Z" level=info msg="saving artifact to path: '/output/config.yaml'" I You can edit the modernization plan at "analysis-output/config.yaml"

After the analysis is complete, a new directory called analysis-output is created which contains the migration plan, config.yaml.

  1. Next, generate the migration artifacts:
./m2c generate --input analysis-output --output migration-artifacts

Sample output:

I Generating artifacts... E generate container time="2024-06-20T10:23:25Z" level=info msg="CopyDirectory from: /tmp/1879368458 to: /output/" I Enriching artifacts... I Your generated artifacts are available at "migration-artifacts"

Task 5. Deploying the migrated workload

In this section, you will deploy the migrated workload to the GKE cluster running on Google Cloud.

  1. Connect to the cluster migration-processing by running the following command:
gcloud container clusters get-credentials migration-processing --zone {{{project_0.default_zone | Zone}}} --project $PROJECT_ID
  1. Open the migration-artifacts folder:
cd migration-artifacts
  1. To expose the workload to the internet, add a new Load Balancer service in the deployment_spec.yaml file. Edit and update the deployment_spec.yaml file to add another Service at the end that will expose port 80 for access to your web server over HTTP:
cat << EOF >> deployment_spec.yaml apiVersion: v1 kind: Service metadata: name: hello-service spec: selector: app: linux-system ports: - protocol: TCP port: 80 targetPort: 80 type: LoadBalancer EOF
  1. Next, deploy the migrated VM:
skaffold run -d eu.gcr.io/$PROJECT_ID

Sample output:

deployment.apps/linux-system created service/linux-system created service/hello-service created

It may take a few minutes for the deployment to complete.

  1. Now check for an external IP address.
kubectl get service hello-service

Sample output:

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-service LoadBalancer 34.118.226.35 35.227.16.198 80:30279/TCP 2m12s

When the web server is ready, you'll see an external IP address for the hello-service you added.

Task 6. Test the migration

  • Test the migration by opening a browser and visiting the web page at the external IP address of hello-service.

For example:

http://hello-service-external-IP Note: Be sure to use HTTP rather than HTTPS.

Click Check my progress to verify the objective. Verify creation of the service through migration

Congratulations!

You migrated a Compute Engine instance to a Kubernetes pod using Migrate to Containers. This same technique can be used for other sources of VMs including VMWare vSphere, AWS, and Azure.

Next steps / Learn more

End your lab

When you have completed your lab, click End Lab. Your account and the resources you've used are removed from the lab platform.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

Manual Last Updated: November 25, 2024

Lab Last Tested: November 25, 2024

Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Diese Inhalte sind derzeit nicht verfügbar

Bei Verfügbarkeit des Labs benachrichtigen wir Sie per E-Mail