You can migrate your VMs from Compute Engine to containerized VMs on Google Kubernetes Engine (GKE). Through the steps in this topic, you'll create YAML to configure GKE objects to support migration to your own GKE cluster.
- Before migrating VMs to GKE, be sure you've set up or verified the prerequisites described in Prerequisites for migrating Compute Engine VMs to GKE.
Building configuration files
Open Cloud Shell or a terminal
Continue with installation
Install the required dependencies.
pip3 install --user pyyaml
Open the VM Instances page on the Cloud Console and Stop the Compute Engine instance you are migrating.
clone_vm_disksscript to clone the VM's disks and generate a deployment YAML file:
python3 /google/migrate/anthos/gce-to-gke/clone_vm_disks.py \ -p project-name \ -z zone-name \ -T target-zone-name \ -i vm-name \ -A app-name \ -o yaml-file-name
Use options as described in the following table:
Your Google Cloud project name.
Google Cloud zone that hosts the VM. For example, 'us-central1-a'.
Google Cloud zone that hosts the GKE cluster. For example, 'us-central-b'.
Be sure to specify a zone that is also the location of a GKE node to which you're migrating.
Name of the VM. For example, 'myapp-vm'.
Name of workload that will be launched in GKE. This will be used as the
StatefulSetname in the generated YAML, and as a prefix for the
Filename of resulting YAML configuration.
python3 /google/migrate/anthos/gce-to-gke/clone_vm_disks.py \ -p 'my-project' \ -z 'us-central-a' \ -T 'us-central-b' \ -i 'myapp-vm' \ -A 'my-workload' \ -o 'deployment.yaml'
Apply configuration to your cluster
Apply the generated configuration YAML to the cluster you created. This will migrate your VM to the cluster.
To apply the deployment to your cluster, run the following command:
kubectl apply -f yaml-file-name
where yaml-file-name is the file you generated earlier when building a configuration file.
To confirm that your workload is running on the cluster, open the GKE workloads page on the Google Cloud Console. Also, click Storage to view the Persistent volume claims created for you. Applying the generated YAML has created two storage classes, one with a storage class name and one without. The named storage class is bound to the cloned disk.
Your VM is now migrated to GKE.
bash commands on your container
You can access a container through a
bash shell using the
kubectl exec command.
kubectl describe podsto find the name of the Pod in your cluster that you want to connect to.
In the following example, the command lists the suitecrm-0 pod.
kubectl describe pods | grep Name Name: suitecrm-0.
- Execute shell commands using one of the following methods:
kubectl execto open a bash command shell where you can execute commands.
kubectl exec -it pod-name -- /bin/bash
The following example gets a shell to the suitecrm-0 pod:
kubectl exec -it suitecrm-0 -- /bin/bash
kubectl execto execute commands directly.
kubectl exec -it pod-name -- /bin/bash -c "command(s)"
The following example lists the root directory of the suitecrm-0 pod:
kubectl exec -it suitecrm-0 -- /bin/bash -c "ls /"
For more information, see the Kubernetes documentation.