Code Monkey home page Code Monkey logo

compute_engine_default's Introduction

1. overview

Google cloud's Compute Engine is virtual machines.
each virtual machine is called instance.
each instance is started or stopped manually. When instance is started and in running state, the billing is counted until the instance is stopped.

-> if you want all controls of a computer, use this. -> can support linux, ubuntu or windows os. -> remember to stop it when you donot use it. -> if you want a solution that automatically start/stop instance, use Google Cloud Run.

( https://cloud.google.com/compute/docs/create-linux-vm-instance https://cloud.google.com/compute/all-pricing https://cloud.google.com/compute/docs/instances )

2. create

  • go to 'console/Compute Engine/VM instances' and click 'Create instance'

  • select region. eg: us-central1 (lowa) note: the asia-southeast1 (singapore) is not supported region to gain the benefits of Free Tier. Use it will cost you more. (https://cloud.google.com/free/docs/free-cloud-features#free-tier-usage-limits)

  • select machine: E2, e2-medium

  • select Boot Disk: Ubuntu, Ubuntu 20.04 LTS

  • select Firewall: allow http and allow https

  • check the price on the right panel: about $25/month => $0.03/hour

  • click 'Create'

(https://cloud.google.com/compute/docs/create-linux-vm-instance)

3. start, stop

go to 'console/Compute Engine/VM instances'. click the 'three dots button' on the right of each instance and select 'start/resume' or 'stop'. -> remember to stop instance when not using it.

4. connect ssh in browser

go to 'console/Compute Engine/VM instances'. click the 'SSH button' on the right of each instance. browser will open another windows that acts as an terminal to execute commands.

internally, googles does the followings: https://cloud.google.com/compute/docs/instances/ssh#metadata-managed_ssh_connections

5. connect ssh using 3rd tools

create key pair

you can create and store keys anywhere you like.
https://cloud.google.com/compute/docs/connect/create-ssh-keys#windows-10-or-later

(the key generated by ssh-keygen may not in the supported format of putty or winscp. if then those programs want to convert key to their supported format, just accept it. they will convert and put new keys besides the old keys. also remember the passphrase to use private key later or just dont use passphrase.)

add to instance's metadata

this method doesn't require client to provide password. (recommended because of simplicity) It registers the username with client's public key. https://cloud.google.com/compute/docs/connect/add-ssh-keys#add_ssh_keys_to_instance_metadata

(view os login method here: https://cloud.google.com/compute/docs/instances/ssh#os_login-managed_ssh_connections )

connect using putty

https://cloud.google.com/compute/docs/connect/ssh-using-third-party-tools#putty

connect using winscp

  • select new session
  • enter hostname (server ip), port: 22
  • enter username, no need of password.
  • click 'Advanced', click tab 'SSH/Authentication'.
  • select the private key. (if asked for converting to, just accept it)
  • select 'OK' to save authentication method.
  • select 'Login'.

6. set environment variables

the simplest solution is upload the '.env' file to instance (using WinScp). then: export ABC=$(cat .env)

then use in docker container: sudo -E docker run -dp 3000:3000 --env ABC app1

your program should receive entire file content then parse it.

( another solution is using custom metadata and run custom script: https://cloud.google.com/compute/docs/metadata/overview#custom )

compute_engine_default's People

Contributors

qttq23 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.