Google Compute Engine recover from terminated status - google-compute-engine

My free trial period has been cancelled but I would like to continue using my existing engines.
The console says my instance is terminated and is no longer running.
Rebooting the instance gives "The resource .... is not ready' error.
How can I continue using my engines with exact same IP setting and other configurations?

Once an instance is in a 'TERMINATED' state it can no longer be booted. You will need to recreate an instance with the same configuration, IP address and boot disk as you indicate. See this FAQ for more information about the terminated state: https://cloud.google.com/compute/docs/troubleshooting#terminate
To retain your existing IP address you will need to promote it to a static IP address resource. You can then reassign this address resource to your new instance.
$ gcloud compute addresses create address-name --addresses IP_ADDRESS --region REGION
See this article for the exact steps:
https://cloud.google.com/compute/docs/instances-and-network#promote_ephemeral_ip
To migrate the existing data on your disk you could create a snapshot and then restore that snapshot when creating a new instance:
$ gcloud compute disks snapshot DISK
See this article for the detailed steps:
https://cloud.google.com/compute/docs/disks#creating_snapshots
Finally to migrate all the associated configuration and metadata you could use the describe subcommand in the Cloud SDK:
$ gcloud compute instances describe INSTANCE
This would print out the entire configuration for your existing instance which you can then use to recreate in your new instance.
The exact steps are quite similar to the process of migrating an instance from one zone to another. You could essentially follow the guide for that process but recreate your new instance in the same zone if you prefer not to move the location of your data. The steps for migrating an instance across zones can be found here:
https://cloud.google.com/compute/docs/instances#moving_an_instance_between_zones

Related

Google compute engine, instance dead? How to reach?

I have a small instance running in GCE, had some troubles with the MongoDb so after some tries decided to reset the instance. But... it didn't seem to come back online. So i stopped the instance and restarted it.
It is an Bitnami MEAN stack which starts apache and stuff at startup.
But... i can't reach the instance! No SCP, no SSH, no webservice running. When i try to connect via SSH (in GCE) it times out, cant make connection on port 22. In the information it says 'The instance is booting up and sshd is not running yet', which is possible of course.... But i cant reach the instance in no possible manner not even after an hour wait :) Not sure what's happening if i cant connect to it somehow :(
There is some activity in the console... some CPU usage, mostly 0%, some incomming traffic but no outgoing...
I hope someone can give me a hint here!
Update 1
After the helpfull tip form Serhii... if found this in the logs...
Booting from Hard Disk 0...
[ 0.872447] piix4_smbus 0000:00:01.3: SMBus base address uninitialized - upgrade BIOS or use force_addr=0xaddr
/dev/sda1 contains a file system with errors, check forced.
/dev/sda1: Inodes that were part of a corrupted orphan linked list found.
/dev/sda1: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
(i.e., without -a or -p options)
fsck exited with status code 4
The root filesystem on /dev/sda1 requires a manual fsck
Update 2...
So, i need to fsck the drive...
Created a snapshot, made a new disk from that snapshot, added the new disk as an extra disk to another instance. Now that instance wont boot with the same problem... removing the extra disk fixed it again. So adding the disk makes it crash even though it isn't the boot-disk?
First, have a look at the Compute Engine -> VM instances -> NAME_OF_YOUR_VM -> Logs -> Serial port 1 (console) and try to find errors and warnings that could be connected to lack of free space or SSH. It'll be helpful if you updated your post by providing this information. In case if your instance run out of free space follow this instructions.
You can try to connect to your VM via Serial console by following this guide, but keep in mind that:
The interactive serial console does not support IP-based access
restrictions such as IP whitelists. If you enable the interactive
serial console on an instance, clients can attempt to connect to that
instance from any IP address.
more details you can find in the documentation.
Have a look at the Troubleshooting SSH guide and Known issues for SSH in browser. In addition, Google provides a troubleshooting script for Compute Engine to identify issues with SSH login/accessibility of your Linux based instance.
If you still have a problem try to use your disk on a new instance.
EDIT It looks like your test VM is trying to boot from the disk that you created from the snapshot. Try to follow this guide.
If you still have a problem, you can try to recreate the boot disk from a snapshot to resize it.

Openshift Mymsql persistent storage won't mount on php

I have pod that utilizes php and I have a persistent MySQL storage created on openshift online. Whenever I click the option "add storage to php" and I set mysql as the storage with mount point /var/lib/mysql the server attempts to redeploy but the new container is stuck creating and then fails. I get multiple error messages like this one:
Failed to attach volume "pvc-d4962378-aae0-11e7-8a41-0a2a2b777307" on node "ip-172-31-50-169.us-west-2.compute.internal" with: Error attaching EBS volume "vol-0087ade77401256f5" to instance "i-0b8b81e68bc629f01": VolumeInUse: vol-0087ade77401256f5 is already attached to an instance status code: 400, request id: dfbdac9b-bad0-4211-8158-080a4e120b1a. The volume is currently attached to instance "i-02a6b44c53ab0d7f2"
Isn't this the proper way to connect mysql storage to a pod?
EBS volume type can only be mounted on one node at a time in an OpenShift cluster. When you have PHP and MySQL as separate applications that can land on different nodes and as a result, you can't mount the persistent volume against both. The error is warning you of this.
The only way you can use a single EBS volume against PHP and MySQL at the same time is for them to be running in separate containers of the same pod. You also need to ensure that the deployment strategy is set to Recreate and not Rolling, as rolling results in a new instance being created when the old still exists, with same issue arising as the new and old could be on different nodes.

How to restore instance using snapshot in Google Compute Engine?

I created a snapshot of a VM instance via cloud console. I would like to know how I can restore an instance using a snapshot. The documentation for compute engine is not very helpful. The instance runs on Ubuntu. Thanks.
To restore an instance from a snapshot without deleting/re-creating the instance:
Shut down the instance and detach the boot disk: gcloud beta compute instances detach-disk INSTANCE_NAME --disk BOOT_DISK_NAME
Create a new disk from the snapshot: gcloud compute disks create DISK_NAME --source-snapshot SNAPSHOT_NAME
Attach the disk created from step 2 as the boot disk: gcloud beta compute instances attach-disk INSTANCE_NAME --disk DISK_NAME --boot
Restoring the instance without deleting/re-creating the instance means that after restore, the instance will keep its IP address and other properties like tags, labels, etc.
In Console, you can go to VM Instances from Compute Engine tab.
There you click on '+Create Instance'
and there in section of boot-disk, you can navigate to 'snapshots' tab and select the snapshot you took.
Like this from console, you can Restore your instance.
Let me know, if this doesn't work for you!
Try using:
gcloud compute disks \
create <NEW_INSTANCE_NAME> \
--source-snapshot <SNAPSHOT_NAME> \
--type pd-ssd \
--zone <ZONE>
You could find useful instruction here.
If you want to do it in the web interface, it's pretty easy. Edit your VM instance. Scroll down to your boot disk and click "x" next to the boot volume, then click create button. In the next window give your new volume a meaningful name, set up your snapshot schedule, and then under "source type" select "Snapshot". Choose your snapshot from the dropdown. If you have a customer managed/supplied key (not recommended) select it, otherwise leave it as google-managed key. Click create. Depending on disk size it might take a while. Be patient and let it finish the setup and then start your instance once it is al complete.

Creat an image from Google Compute Engine instance

I am trying to replicate a new instance from my current instance in Google Compute Engine (following Google instruction: https://cloud.google.com/compute/docs/images#create_an_image_from_a_root_persistent_disk).
In step 3 (Terminate your instance), I am following the instruction ($ gcloud compute instances delete example-instance --keep-disks boot). However, it still asks me whether I want to completely delete the instance:
The following instances will be deleted. Attached disks configured to
be auto-deleted will be deleted unless they are attached to any other
instances. Deleting a disk is irreversible and any data on the disk
will be lost. Do you want to continue (Y/n)? n
Am I still able to recover the instance or continue to create the image of my current instance as Google's instruction? If any body has try to replicate Google Compute Engine, please let me know. Thank you!
I just tested this command on my account and deleted my instance using " --keep-disks boot ". This option keeps the boot disk despite the warning message which says "Attached disks configured to be auto-deleted will be deleted....."
You can also use Developers Console, uncheck "Delete boot disk when instance is deleted" under your instance properties and then delete the instance from there.

How to get a new EC2 instance to mount an existing volume on which there is a MySQL database?

Several months ago, I followed http://aws.amazon.com/articles/1663 and got it all running. Then, my PC crashed and I lost the keypair (http://stackoverflow.com/questions/7949835/accessing-ec2-instance-after-losing-keypair) and could no longer access the instance.
I want to now launch a new instance and mount this MySQL/DB volume which is left over from before and see if I can get to the data on it. How can I go about doing that?
You outlined the correct approach to this problem already, and the author of the article you referenced, Eric Hammond, has written another one detailing this very process, see Fixing Files on the Root EBS Volume of an EC2 Instance - it boils down to:
start another EC2 instance
stop the EC2 instance you can't access anymore
detach the EBS volume from the stopped instance
attach the EBS volume to the running instance
SSH into the running instance
mount the EBS volume in the running instance
perform whatever fixes necessary, i.e. adjust the /var permissions in your case
Please see Eric's instructions for details on how to do this from the command line; obviously you can achieve all steps up to the SSH access via the AWS Management Console as well, removing the need to install the Amazon EC2 API Tools, in case they aren't readily available already.