Google Cloud Anthos Series: Migrate for Anthos and GKE
Google Cloud Anthos Series: Part 8
Welcome to Part-8 of the ‘Google Cloud Anthos series’. You can find the complete series Here
Migrate for Anthos and GKE
This tool makes it fast and easy to modernize traditional applications away from virtual machines and into native containers. Find this tool in Anthos dashboard with the name ‘Migrate to containers’.
Use Migrate for Anthos and GKE to convert VM-based workloads into containers that run on Google Kubernetes Engine (GKE) or Anthos clusters. Workloads from VMs that run on VMware, AWS, Azure, or Compute Engine can be migrated to GCP in container format with ease.
This unique automated approach extracts the critical application elements from the VM so that those elements can be easily inserted into containers in GKE or Anthos clusters without the VM layers (like Guest OS) that become unnecessary with containers.
This significantly reduces the cost and labor that would be required for a manual application modernisation project. Post migration customer’s DevOps team gets modern controls offered by the GKE/Anthos to manage these applications.
Migrate for Anthos and GKE : Quickstart Guide
In this Quickstart hands-on guide, Create a simple Compute Engine virtual machine (VM) on GCP first then use ‘Migrate for Anthos and GKE’ to migrate the VM to a Google Kubernetes Engine (GKE) processing cluster in the Cloud.
PART-1: GCE VM Setup
Create a GCE VM on Google cloud platform and install simple Apache web server application on it.
1.1. Setup Env Variables
PROJECT_ID="<your-project-id>"
REGION="<gcp-region>"
ZONE="<zone>"
1.2. Create a VM with a web server
gcloud compute instances create quickstart-instance \
--project=${PROJECT_ID} --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=quickstart-instance
1.3. Create a Firewall Rule
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
1.4. SSH to the VM & Install the apache2 Package
sudo apt-get update && sudo apt-get install apache2 -yecho '<!doctype html><html><body><h1>Hello World!</h1></body></html>' | sudo tee /var/www/html/index.html
1.5. Verify the Installation
Open the browser and type http://<quickstart-instance-Public-IP>
1.6. Stop the VM
PART-2: GKE Processing Cluster Setup
2.1. Creating a processing cluster
Create a GKE cluster in the Cloud that you use as a processing cluster. This is where you install Migrate for Anthos and GKE and execute the migration.
gcloud container clusters create migration-processing \
--project=${PROJECT_ID} --zone=${ZONE} --machine-type e2-standard-4 \
--image-type ubuntu --num-nodes 1 \
--subnetwork "projects/${PROJECT_ID}/regions/${REGION}/subnetworks/default"
PART-3: Install ‘Migrate for Anthos and GKE’
3.1. Create the
m4a-install
service account
gcloud iam service-accounts create m4a-install \
--project=${PROJECT_ID}
3.2. 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"
3.3. 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}
3.4. Connect to the cluster
gcloud container clusters get-credentials migration-processing \
--zone ${ZONE} --project ${PROJECT_ID}
3.5. Set up Migrate for Anthos and GKE components on the processing cluster
migctl setup install --json-key=m4a-install.json
3.6 Validate the Migrate for Anthos and GKE installation
migctl doctor
PART-4: Migrating the VM: Create Service Account
4.1. Create the
m4a-ce-src
service account
gcloud iam service-accounts create m4a-ce-src \
--project=${PROJECT_ID}
4.2. 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"
4.3. 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"
4.4. 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}
4.5. Create the migration source
migctl source create ce quickstart-source --project ${PROJECT_ID} --json-key=m4a-ce-src.json
PART-5: Migrating the VM: Create a migration
5.1. Create a migration Plan
migctl migration create my-migration --source quickstart-source \
--vm-id quickstart-instance --intent Image
5.2. Check the migration status
migctl migration status my-migration
5.3. Download the migration plan
migctl migration get my-migration
5.4. Migrate the VM using the migration plan
migctl migration generate-artifacts my-migration
5.5. After the migration begins, check its status until it finishes
migctl migration status my-migration
PART-6: Deploying the migrated workload
6.1. Once the migration is complete, download the generated YAML artefacts
migctl migration get-artifacts my-migration
6.2. Add following service to the ‘deployment_spec.yaml’ file
apiVersion: v1
kind: Service
metadata:
name: hello-service
spec:
selector:
app: quickstart-instance
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
6.3.Apply the deployment spec YAML to deploy the workload
kubectl apply -f deployment_spec.yaml
6.4. Check for an external IP address
kubectl get service hello-service
6.5. Test the migration by opening a browser and visiting the web page at the external IP address
http://<EXTERNAL-IP>
Check ‘Migrate to containers’ Dashboard under ‘Kubernetes Engine’ section on GCP console.
Reference
Coming up..
In this blog we discussed ‘Migrate for Anthos & GKE’ tool to migrate VMs to containers. In upcoming blogs we will continue the Samajik’s journey of Anthos adoption.
Contributors: Anchit Nishant, Shijimol A K, Dhandus