gcloud-client
gcloud-client copied to clipboard
google cloud client which give ssh access and login to multiple instances with tmuxinator
gcloud client
scripts to do things which you wish google console client does.
Installation
Required libs
- gcloud authenticated with projects and config set
- tmux
- tmuxinator gem
Go
go get -u github.com/devdinu/gcloud-client
Homebrew
brew install devdinu/devlife/gcloud-client
If you've installed with brew, command will be gcl, might need to remove alias from git plugin of oh-my-zsh ~/.oh-my-zsh/plugins/git/git.plugin.zsh
Usage
Refresh
all instances, which's stored in boltd
gcloud-client instances refresh
optionally you can pass flag --projects proj1,proj2 to refresh specific projects
You could add the refresh as cron

Search
gcloud-client --helpto show the help with flag information
Add SSH key to compute instances
You could add your ssh key to compute instance[s], so you could ssh directly. default gcloud compute add ssh overrides the existing keys. you can add your key along with existing ones in instances with this command.
# adds your ~/.ssh/id_rsa.pub key to 10 instances
gcloud-client ssh_access --limit=10
The existing keys with new key is written to temp file and cleared after added to the instance.
You could customize the flags
--limittotal instances to add--filterregexp to filter the instances while listing. uses gcloudfilter=name~'regex'--userusername to which your ssh key is added for, defaults to$USER--ssh_keyssh_key file to be uploaded, defaults to$HOME/.ssh/id_rsa.pub--dbfilefile to store the instances and search, defaults to$HOME/hosts.db--projectslist of project-ids to search for while login, or to refresh--host_mappingprints results ofsearchcommand in the format of/etc/hostsfile
# customize ssh file, username
gcloud-client ssh_access --ssh_key=$HOME/.ssh/gcp_id_rsa.pub --filter='.*pg.*' --limit=10 --user username
Add to single instance
You could give --instance and --zone to add ssh key to single instance, as its faster than listing instances with regexp
gcloud-client --instance=some_instance --zone=asia-zone

Login to instances
ssh into the instances which you searched, open each in tmux pane.
gcloud-client instances login --regex=some-prefix
gcloud-client instances login --prefix='some-.*db.*' --user username --session session_name
gcl instances search --regex=".*kafka.*" --projects=proj-integration,proj-production
- prefix search is much faster than regex search
Customize flags
--userusername for ssh--sessiontmux session name, so multiple ssh sessions can be done at same time--projectsif you've many gcloud projects, mention the projects to search

Additional information
Homebrew
if you've installed via homebrew, use gcl instead of gcloud-client
/usr/local/Cellar/gcloud-client/ have the template file and bin directory with the executable
Tmux
enable syncronized panes, so most cases require you to run command on all machines
:set synchronized-panes on
TODO:
- customize which
cmdto run once ssh to all instances - customize login via external ip / internal ip via flags (currently only internal ip is supported)
- Infer id from ssh key
- revoking ssh key for user from machine
- ssh customize project to use via flag
- TAG: search list could be tagged, so can login via tags