I cannot connect to Gcloud instance using ssh, since cpu is 99.9% of use

I have a gcloud vm instance of type custom (4 vCPUs, 8 GB memory), with ubuntu 16.04, 10Gb disk space. Today at specific time (7:30 am), start using the 99% of cpu. I restart the machine but continue to use the 99% of cpu. Now I cannot connect through ssh. There is any workaround to connect to my instance and see what the problem is?? Thank you!!!

1 answer

  • answered 2018-11-07 15:23 Jordi Miralles

    You could probably try to connect through the serial port :

    gcloud compute instances add-metadata INSTANCE --metadata serial-port-enable=1
    gcloud compute connect-to-serial-port INSTANCE

    Probably the tty on the serial port will be a lot less sensitive to the high CPU usage and you'll be able to log in.

    Now, this will ask you for a user and password...what to do if you are (correctly) using only RSA Keypair authentication for ssh? Here there is a quick and dirty hack that does the job:

    1 - Set up this as the startup script echo "root:1234" | chpasswd like this, for example:

    gcloud compute instances add-metadata INSTANCE --metadata startup-script='echo "root:1234" | chpasswd'

    2 - Reboot the instance so the startup script is applied

    3 - Log in through the serial port

    gcloud compute connect-to-serial-port INSTANCE 

    4 - Use root as username and 1234 as password (or whatever you put in the script)

    5 - Don't forget to disable serial port access when you don't need it anymore.