Migration of IBM Liberty to GKE using m2c-cli
In this article we will discuss migration of IBM Liberty to Google Kubernetes Engine (GKE). It would be an overview of migration steps using m2c cli (not yet GA). The m2c-cli tool is not yet GA however it has been used to migrate simple IBM Liberty and the steps can be used as it is (with minimal changes)
Following will be discussed
- Environment setup on GCP
- IBM Liberty server setup
- Setup VM with m2c-cli tool installed in it
- Create a auto-pilot GKE
- Migrate and application deployed in IBM Liberty to GKE (m2c-cli Migration)
What is m2c-cli?
M2c stands for migrate to containers and is a command-line tool that lets you set up and execute migrations on your local machine. More details about m2c-cli can be found here. The m2c architecture is as follows
Migration steps involve the fitment assessment as well however in this article we would assume IBM Liberty and application deployed in it is applicable for migration.
Modernisation using Migrate to Containers CLI spans across three steps: Transformation, Workload deployment, and Maintenance.
- Transformation — Migrate to Containers CLI is used to transform a VM-based application component into a container-based application component ready to be deployed. This spans across five phases:
- Copy — Copy the file system of the target machine to the local machine.
- Analyze — Analyze the file system to create a migration plan.
- Edit — Edit the plan to modify the migration outputs to fit your needs.
- Generate — Generate artifacts such as Docker files, Docker contexts, Kubernetes deployment files and Skaffold configuration.
- Migrate data — Copy the data files into persistent volumes. This is optional.
2. Workload deployment — You can deploy Migrated container workloads on any GKE or GKE Enterprise cluster meeting the minimum requirements. The migration artifacts can include one or more Dockerfiles, one or more Kubernetes deployment specs, and a Skaffold configuration file.
3. Maintenance — After you migrate container workloads, you typically perform optimisation and maintenance operations. The extracted workload content and the generated Dockerfile can be integrated in a CI/CD pipeline for efficient image-based maintenance.
In next steps we will majorly focus on transformation and workload deployment.
Environment Setup On GCP
Start a compute engine instance on GCP
Local Machine (m2c-cli workstation)
Install Ubuntu 20.04 TLS with e2-standard-8, and 500G disks, selected “Allow full access to all Cloud APIs”
Download m2c-cli in the workstation
curl https://storage.googleapis.com/m2c-cli-release/0.2.0-offline.tar -o 0.2.0-offline.tar
tar -xvf 0.2.0-offline.tar
Install docker from apt
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
apt-cache policy docker-ce
sudo apt install docker-ce
Install gcloud
**GCP compute engine by default provides gcloud. Skip the step if you are using the same
Doc: https://cloud.google.com/sdk/docs/install#deb
Auth plugin: https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke
Install kubectl
kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.24.0/bin/linux/amd64/kubectl
Install skaffold
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && \
sudo install skaffold /usr/local/bin/
IBM Liberty server setup
Install Ubuntu 20.04 TLS with e2-standard-8, and 100G disks,
Ensure you have JAVA installed and running before installing Liberty
Download Liberty binary file from IBM developer website: https://www.ibm.com/support/pages/websphere-liberty-developers
curl https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/downloads/wlp/23.0.0.5/wlp-webProfile8-java8-linux-x86_64-23.0.0.5.zip -o wlp-webProfile8-java8-linux-x86_64-23.0.0.5.zip
Make sure the liberty server setup should follow the below path pattern
"/opt/*/ol/wlp"
"/usr/*/ol/wlp"
"/etc/*/ol/wlp"
"/opt/*/ibm/wlp"
"/opt/*/IBM/wlp"
"/usr/*/ibm/wlp"
"/usr/*/IBM/wlp"
"/etc/*/ibm/wlp"
"/etc/*/IBM/wlp"
"/opt/*/ibm/WebSphere/Liberty"
"/opt/*/IBM/WebSphere/Liberty"
"/usr/*/ibm/WebSphere/Liberty"
"/usr/*/IBM/WebSphere/Liberty"
"/etc/*/ibm/WebSphere/Liberty"
"/etc/*/IBM/WebSphere/Liberty"
Unzip the Liberty binary file that will create a wlp folder. Create a ${WLP_HOME} environment variable with the wlp folder path
unzip wlp-webProfile8-java8-linux-x86_64-23.0.0.5.zip
cd wlp
export WLP_HOME="$PWD"
To deploy an application, create a server in Liberty installation following below commands
cd ${WLP_HOME}/bin;
./server create <Server Name>;
Once the server is created it will create a directory Server Name under ${WLP_HOME}/usr/servers
For deploying the application, package the application as a war file and copy the war file in ${WLP_HOME}/usr/servers/apps directory. You can deploy a test war from the command below
curl https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war
Deploy the war
Copy downloaded war to ${WLP_HOME}/usr/servers/apps directory
cp <sample war source path> ${WLP_HOME}/usr/servers/server/apps/
Edit the server.xml
vi ${WLP_HOME}/usr/servers/server/server.xml
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>webProfile-8.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint"
httpPort="9080"
httpsPort="9443" />
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<!-- add the below line -->
<application location="sample.war"/>
</server>
Start the server using the below command
cd ${WLP_HOME}/bin;
./server start <Server Name>;
Run the below command to verify if application is up and running in liberty server
curl http://localhost:<PORT>/sample/hello
**Make sure to use the correct port the default is 9080
Create a auto-pilot GKE
Create a AutoPilot GKE cluster with default values in the project
m2c-cli Migration
Login to m2c-cli installed machine
ssh to VM in created in m2c-cli installed machine
Copy the source systems file
./m2c copy ssh root@<IP of the Source VM> -o <Source machine file>.tar
Analyse the copied file system
./m2c analyze -s <Source machine file>.tar -p liberty-container -o<Analysis output>.tar -r wlp-java-home=<Path to java under liberty server> -r wlp-home=<Path to liberty server>
Verify the analysis output is created properly
A config.yaml should be available with all the details
ls <Analysis output>.tar/
output
config.yaml
Generate the containerised deployable artifacts
./m2c generate -i <Analysis output>.tar -o <Deployable artifacts>
Verify the generated artifacts
**The directory should have artifacts.yaml, <application archieve for e.g. .war file> and skaffold.yaml file
cd <Deployable artifacts>
ls
output
artifacts.yaml sample.war skaffold.yaml
Create GCP repository
Create repository
gcloud artifacts repositories create <REPO_NAME> --location="<REPO_LOCATION>" --repository-format="<FORMAT>" --project="<PROJECT_ID>"
Verify GCP repository
List the repository
gcloud artifacts repositories list --project=<PROJECT_ID> --location=<REPO_LOCATION> --repository-format="<FORMAT>"
Set google cloud repository variable
Pickup the repository path and set the variable
export GCR_REPO=<GCP_REGION>-docker.pkg.dev/<PROJECT_ID>/ibm-lib-server-m2c-repo
Execute the skaffold command to deploy the artifacts
skaffold run -d ${GCR_REPO}
Troubleshooting : If the above command throws an error, kindly execute the following command from the path where skaffold.yaml is present. The command will clear the cache.
skaffold delete
Check the pods
kubectl get pods
Hit the service endpoints on the cluster
kubectl exec -it <podName> -- bin/bash
curl -v http://localhost:9080/sample/hello
curl -v https://localhost:9443/sample/hello -s -L --insecure
Finally, we observed that the IBM Liberty server migrated to GKE.
Remarks
In this article both, source and destination both are on GCP. The suggested solution can be used irrespective of whether the source is on any other cloud or on-prem. The appropriate source configuration needs to be configured with respect to m2c-cli requirement and everything will work as it is.
References
https://cloud.google.com/migrate/containers/docs/m2c-cli-reference-linux
https://cloud.google.com/migrate/containers/docs/m2c-cli/architecture