Meh, mildly helpful info about Cloud Shell
and also just some Linux stuff i wish people taught me earlier
- Tools already in Cloud Shell
- Customizing Cloud Shell
- Using
customize_environment
- Using a custom container image
- Using
- Using
tmux
- Simulating traffic
- Using ide.cloud.google.com
- Space saving
- Other
gcloud
tips - Other
linux
tips - Other Cloud Shell tips
My favorites:
- gcloud - you already know
- kubectl - interact with kubernetes
- kubectx - switch between kubernetes cluster contexts automatically
- kubens - switch between kubernetes namespaces in your current kubernetes cluster
- terraform - create (or destroy - or dry run, whatever floats your boat) cloud resources
- helm - deploy templatized k8s apps
- hey - fancy traffic generator
- curl - kirkland brand way to issue http requests - gets the job done
- docker - build containers
- skaffold - automate building and deploying k8s for dev
Other cool ones I guess:
- bq - query big
- gs - storage stuff
- git - manage your git repos
- gh - manage your GitHub repos
- vi (lol jk) - lol
- tmux - i use it to display multiple terminals
- jq - query json documents
# This runs as root lol so be careful i guess
vi ~/.customize_environment
Now insert whatever trouble you want to wreak, like...
# bat - cat but fancy syntax highlighting
yes | apt install bat
# tree - fancy display of your directory hierarchy
yes | apt install tree
# screen - run stuff in the background (i find easier than tmux)
yes | apt install screen
# yq - i hope you never have to query yaml but here ya go
VERSION=v4.2.0
BINARY=yq_linux_amd64
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - |\
tar xz && mv ${BINARY} /usr/bin/yq
Or installing your own version of gcloud
!
You can also change your PS1 by editing your ~/.bashrc
, for example I add kube-ps1.sh1
to change my prompt to give me my current k8s context.
source ~/kube-ps1.sh
PS1='[\u@\h \W $(kube_ps1)]\$ '
If you're not familiar with building container images, the cloudshell
CLI wraps the process of building the container image nicely:
cloudshell env create-custom-image your-cloudshell-repo
cd $HOME/your-cloudshell-repo && rm Dockerfile
cat << EOF >> Dockerfile
FROM gcr.io/cloudshell-images/cloudshell:latest
# Install all the stuff in the example above
yes | apt install bat
yes | apt install tree
yes | apt install screen
VERSION=v4.2.0
BINARY=yq_linux_amd64
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - |\
tar xz && mv ${BINARY} /usr/bin/yq
EOF
cloudshell env build-local
git commit -a -m "Initial custom environment check-in."
git push origin master
cloudshell env push
tmux
is a fancy terminal multiplexer thingy; i use tmux to show multiple things going on in different windows at once.
To use tmux
for this you can access its key bindings by pressing ctrl + b before these keys:
- drop a panel below: "
- drop a panel to the side: %
- navigate your panels: arrow key for direction you want
also type exit
to kill a panel (or any session really)
# change sleep to a hundreth of a second to really wreak havoc
while true; do curl $ENDPOINT; sleep 1; done
then ctrl + c
to kill (anything really)
need to generate traffic for a dashboard (IE i don't care about seeing the response, just need me some metrics)?
you can use tmux for this too. or a dash of screen
will do it - which for some reason i find more intuitive. here. though - for this you're better off just using a GCE VM.
Cloud Shell
comes with the open source editor Theia installed! Go ahead, click!
Fanciest things include:
- Nice version control support (bye
git
) - Cloning sample repositories by example
- Cloud Code - it does so much lol
- Cloud Code for GKE - see all clusters in your
kubeconfig
, and all resources in those clusters (that you have permission to see ofc) - Cloud Code for Cloud Run - see your services
- Cloud Code for minikube - create a baby k8s cluster! awww
Cloud Shell
only comes with 5 GB for your $HOME
. Lol. So clean up every once in awhile!
You could clean up docker
images using:
docker system prune
docker image prune
Hopefully you don't ever have to demo bazel
but I had to once and borked my Cloud Shell
once using it, clear your bazel
cache:
bazel clean
Grab a project number (and see how you can use flattened
as an output format and pipe to awk
)
gcloud projects describe $PROJECT_ID --format=flattened | awk 'FNR == 7 {print $2}'
Grab latest cluster version in GKE (and see how you can use value
as an output format)
gcloud beta container get-server-config --region us-central1 --format='value(validMasterVersions[0])'
Create a cluster (or anything really) async
gcloud container clusters create $CLUSTER_NAME \
--cluster-version=$GKE_VERSION \
--zone $ZONE \
--machine-type=e2-standard-2 \
--num-nodes=1 \
--no-enable-shielded-nodes \
--async
# Get your working directory
pwd
# Go home (roger)
cd ~
# Go up one in your working directory
cd ..
# Go up two in your working directory
cd ../..
# Go up three in...you get the point
cd ../../..
# When typing directory or filename, autocomplete using tab
# Need to see your files in your working directory?
ls -al
# Need to see disk usage?
df
# History?
history
# Err that's too much, let me just type what I think I was looking for in history
ctrl+r and type away my friend - hit enter if you hit the jackpot
# see a file
cat
# create an empty file
touch $FILENAME
# create a file with stuff
cat << EOF >> /path/to/filename
here is fancy file stuff
EOF
# delete a file
rm FILENAME
# delete a directory (BE CAREFUL)
rm -rf DIR
# see all your env vars - wow CLOUD SHELL has some defaults!
env
- Boost mode to get an
e2-medium
machine. - You can run
Cloud Shell
inephemeral mode
to get a factory fresh instance every time. - You can restart your instance to get a clean state.