Lift & Shift + Application Modernization: Converting a legacy application to run in containers on Google Kubernetes Engine (GKE) using Anthos.

Akram Rayri
5 min readOct 25, 2023

--

In another project based on a real-world scenario, I acted as a Cloud Specialist for a company that decided to migrate its entire Datacenter to Google Cloud in 3 months.

The company decided to split the project into 2 stages. The first Lift & Shift, and the second modernization of Talent Management Portal.

After the Lift & Shift process was finished, I had to modernize the Talent Management Portal application for a Google Kubernetes Engine (GKE) cluster using Migrate for Anthos.

As described by the architecture above, the first step consists of compressing the web application files (.html, .css .js ...) into a zip file, then uploading it to a google cloud bucket, this is what we are calling “lifting the application”.

In order to “shift” the application, we have first to create a VM that will host those files, but before the VM will be created, we need first to perform the following from cloud shell (CLI):

  1. Create a new google cloud project, by making sure the its billing status.
  2. Enable the APIs that we will need to provide the necessary resources, i.e Compute Engine, Kubernetes Engine and Cloud Resource manager API.
  3. Set up the firewall rules (port 22 for ssh and port 80 for http for instance), decide which region/zone the resources will be located.
  4. Create the VM that will host the application files, by specifying the name, type, zone, subnet, image, project, disk size…
  5. From cloud shell, generate the ssh key that will be imported later to google cloud so that we will successfully ssh to the created machine.
  6. From the compute engine platform, we can open an ssh web console of the VM, and installing the necessary packages (update the OS, curl, unzip apache2 or httpd).
  7. Now it’s time to download the zip file that contains the application files to our VM (curl -O https://bucket-link.com) into the /var/www/html, since we are talking about a web application, by replacing the default index.html file by the new one plus the .css, .js, jpg, ttf …
  8. We can now check the external IP address of our VM to check if the application was successfully “shifted to the cloud”. Here you can find an example of the application that I have implemented on google cloud VM :

The second part of the project consists of modernization of the application by migrating the web server from the VM to Kubernetes cluster that in this case will be composed by only one node that contains a containerd container, by deploying Google Anthos migration project.

Always form cloud shell (CLI), we will follow the following steps :

  1. Let’s start by creating our k8s cluster by providing the name, region, compute type, version (note the it should be 1.24 above otherwise it’s deprecated), node image (Docker containers are not supported anymore by GKE, that’s why I have mentioned earlier that we are going to use containerd containers), number of nodes, project (you can use $DEVSHELL_PROJECT_ID variable to refer to your project ID without typing it manually)…
  2. Create a new service account with storage.admin permissions, generate its key and connect it to the k8s cluster.
  3. Set up the Anthos migrate component to the cluster : migctl setup install — — json-key=x.json (x.json is the service account key file that we have created before). By this we have completed the part between Anthos and k8s cluster shown in the project architecture above.
  4. Now, we are going to setup communication between our VM that contains the web application files and Anthos, but before that we have to shutdown the machine, otherwise the migration will not be successful.
  5. Let’s carry on by creating another service account role permissions (compute.viewer and compute.storageAdmin) that will take in place between the VM and Anthos.
  6. Creating and downloading the service account key.
  7. Define the CE (Compute Engine) as migration source : migctl source create ce webapp-source — project $DEVSHELL_PROJECT_ID — json-key=x1.json (x1 is the service account key that we have generated before)
  8. Creating the migration plan : migctl migration create my-migration — source webapp-source — vm-id <name of your VM>
  9. Generating the artifacts : migctl migration generate-artifacts my-migration. Note, you can always check the status of migration by using the following command : migctl migration status my-migration
  10. Download the artifacts. Note : a file called deployment_spec.yaml will be automatically generated after a successful artifacts generation.
  11. Deploy the “deployment_spec.yaml” to the cluster : kubectl apply -f deployment_spec.yaml
  12. Check the external IP of the created workload : kubectl get service X2 (X2 is the name of the deployed service). By this, you will be successfully deployed the k8s cluster that hosts your web application and no longer in need of the VM (you can even delete it after the checking the external IP of the deployed service) as it shown below :

--

--

Akram Rayri
Akram Rayri

Written by Akram Rayri

ICT Consultant and Engineer with focus on Cloud & DevOps | AWS | Microsoft Azure | Google Cloud | Oracle Cloud

No responses yet