Giter Site home page Giter Site logo

mildly-helpful-cloudshell's Introduction

mildly-helpful-cloudshell

Meh, mildly helpful info about Cloud Shell and also just some Linux stuff i wish people taught me earlier

Table of contents

  • Tools already in Cloud Shell
  • Customizing Cloud Shell
    • Using customize_environment
    • Using a custom container image
  • Using tmux
  • Simulating traffic
  • Using ide.cloud.google.com
  • Space saving
  • Other gcloud tips
  • Other linux tips
  • Other Cloud Shell tips

Helpful tools I use that are already there - it's free real estate baby!

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

Customizing Cloud Shell on startup (the fastest way to customize IMO)

# 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)]\$ '

You could also just build your own container image to run in Cloud Shell

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

Demoing multiple things using tmux - it's not flying, it's falling with style

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)

Simulate traffic

need to show constant response (IE canary demo)?

# 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.

Need to demo mostly code or config?

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

Save some space!

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

Weird gcloud tips

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

General Linux tips (general linux)

# 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

More random Cloud Shell things:

  • Boost mode to get an e2-medium machine.
  • You can run Cloud Shell in ephemeral mode to get a factory fresh instance every time.
  • You can restart your instance to get a clean state.

mildly-helpful-cloudshell's People

Contributors

agmsb avatar

Stargazers

Roman 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.