Quickstart

In this quickstart, you create a simple Compute Engine virtual machine (VM), then use Migrate for Anthos to migrate the VM to GKE.

Before you begin

Enable support for Compute Engine

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Cloud Console, on the project selector page, select or create a Cloud project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Google Cloud project. Learn how to confirm billing is enabled for your project.

  4. Enable the Compute Engine API.

    Enable the API

Enable and configure GKE

Before you start, make sure you have performed the following tasks:

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.

  1. 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
  2. Follow the instructions to authorize gcloud to use your Google Cloud account.
  3. Create a new configuration or select an existing one.
  4. Choose a Google Cloud project.
  5. Choose a default Compute Engine zone.

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 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'll create a simple Compute Engine VM that serves a "Hello World!" web page. Having the page gives you something to test after migration.

  1. Run the following command to create the VM instance you'll migrate.

    Specify a zone that will be the same zone in which you create a GKE later in this topic.

    gcloud beta compute  --project=project-id instances create \
      quickstart-instance  --zone=zone --machine-type=n1-standard-1 \
      --subnet=default --scopes="cloud-platform" \
      --tags=http-server,https-server --image=ubuntu-minimal-1604-xenial-v20200317 \
      --image-project=ubuntu-os-cloud --boot-disk-size=10GB --boot-disk-type=pd-standard \
      --boot-disk-device-name=quickstart-instance
    
  2. 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
    
  3. In the Google Cloud Console, go to the VM instances page.

    Go to the VM instances page

  4. In the list of virtual machine instances, click SSH in the row of the instance you just created.

    For more on connecting via SSH, see Connecting to instances.

  5. 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.

  6. 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
    
  7. In the VM instances page, locate the row for the instance you created and copy the External IP address.

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

    You should now see the "Hello World!" page.

  9. In the VM instances page, select the check box at the left end of the row for the instance you created.

  10. 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'll create a GKE cluster that you'll use as a processing cluster. This is where you'll install Migrate for Anthos and execute the migration.

  1. 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 --scopes="cloud-platform" \
      --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"
    
  2. Connect to the cluster.

    gcloud container clusters get-credentials migration-processing \
      --zone zone --project project-id
    
  3. Set up Migrate for Anthos components on your processing cluster.

    migctl setup install
    
  4. 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
    

Migrating the VM

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

  1. Specify the migration source as a Compute Engine VM. This will add the source specification to the migration plan.

    migctl source create ce quickstart-source --project project-id --zone zone
    
  2. Create a migration.

    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
    
  3. Migrate the VM, using the migration plan to guide the migration.

    This will migrate the VM and generate artifacts you can use to deploy the workload.

    migctl migration generate-artifacts my-migration
    
  4. After the migration begins, check its status until it finishes.

    The migration can take several minutes. During this time, checking status will report the migration's current state.

    migctl migration status my-migration
    

    When the migration completes, you should see a message such as the following:

    migctl migration status my-migration
    NAME           PROCESS              STATE       STATUS      PROGRESS   AGE
    my-migration   generate-artifacts   completed   COMPLETED   [15/15]    7m25s
    

Deploying the migrated workload

In the following steps, you'll get the deployment artifacts you generated during migration, then use them to deploy your migrated workload to the cluster. As a last step, you'll confirm that the "Hello World!" web page is available from your migrated app.

  1. Once the migration is complete, get the generated YAML artifacts.

    migctl migration get-artifacts my-migration
    

    The command downloads files that were generated during the migration:

    • 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.
  2. Open the deployment_spec.yaml file and locate the Service object whose name is app-quickstart-instance.

  3. Beneath the Service definition, paste another Service that will expose 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: app-quickstart-instance
    spec:
      clusterIP: None
      selector:
        app: app-quickstart-instance
      type: ClusterIP
    status:
      loadBalancer: {}
    
    ---
    
    
    apiVersion: v1
    kind: Service
    metadata:
      name: hello-service
    spec:
      selector:
        app: app-quickstart-instance
      ports:
        - protocol: TCP
          port: 80
          targetPort: 80
      type: LoadBalancer
    
    

  4. 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.

  5. Check for an external IP address.

    kubectl get service hello-service
    

    When the web server is ready, you'll 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
    
  6. 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.

What's next