Skip to content

Instantly share code, notes, and snippets.

View rms1000watt's full-sized avatar

Ryan M Smith rms1000watt

View GitHub Profile
@rms1000watt
rms1000watt / local-list-docker-containers-and-ip.sh
Created August 11, 2020 22:53
locally list docker containers and their ip addresses
#!/usr/bin/env bash
# Courtesy: https://stackoverflow.com/a/20686101
docker ps -a | grep -v CONTAINER | cut -d' ' -f1 | xargs docker inspect -f '{{.Config.Image}}{{"\t"}}{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
@rms1000watt
rms1000watt / cleanup_old_configmaps_helm.sh
Created July 24, 2020 22:21
Cleanup old Configmaps created by helm.. faster edition
#!/usr/bin/env bash
# Courtesy: https://github.com/helm/helm/issues/2332#issuecomment-336565784
# Enhanced for performance
TARGET_NUM_REVISIONS=10
TARGET_NUM_REVISIONS=$(($TARGET_NUM_REVISIONS+0))
RELEASES=$(kubectl --namespace=kube-system get cm -l OWNER=TILLER -o go-template --template='{{range .items}}{{ .metadata.labels.NAME }}{{"\n"}}{{ end }}' | sort -u)
@rms1000watt
rms1000watt / disable-deletion-protection-albs.sh
Created July 14, 2020 00:47
Disable Deletion Protection on ALBs
#!/usr/bin/env bash
for arn in $(aws elbv2 describe-load-balancers | jq -r '.LoadBalancers[] | select(.DNSName | contains("TODO_CHANGE_THIS")) | .LoadBalancerArn'); do
echo "Updating: ${arn}"
aws elbv2 modify-load-balancer-attributes --load-balancer-arn "${arn}" --attributes Key=deletion_protection.enabled,Value=false
done
@rms1000watt
rms1000watt / curl-file-from-release-in-github.sh
Created July 7, 2020 17:37
cURL File from Release in Github
#!/usr/bin/env bash
download_url=$(curl -s -H "Authorization: token ${GITHUB_ACCESS_TOKEN}" "https://api.github.com/repos/${GH_OWNER}/${GH_REPO}/releases/tags/v1.0.0" | jq '.assets[] | select( .name == "bin-name-v1.0.0-darwin-amd64")' | jq -r ".url")
curl -Lo ssm-env -H "Authorization: token ${GITHUB_ACCESS_TOKEN}" -H "Accept: application/octet-stream" "${download_url}"
@rms1000watt
rms1000watt / accept-all-users-linkedin-may-2020.js
Created May 27, 2020 21:08
accept all users linkedin may 2020
// Courtesy: https://dev.to/aletisunil/accepting-linkedin-invitations-through-javascript-2p0b
var x = document.getElementsByClassName("invitation-card__action-btn artdeco-button artdeco-button--2 artdeco-button--secondary ember-view");
for(var i=0;i < x.length;i++){x[i].click();}
@rms1000watt
rms1000watt / hello-world-helm.sh
Created May 20, 2020 17:11
hello world to helm
#!/usr/bin/env bash
# install helm on OS X
brew install helm
# Add the bitnami charts location
helm repo add bitnami https://charts.bitnami.com/bitnami
# Show all the charts that bitnami manages
helm search repo bitnami
@rms1000watt
rms1000watt / k8s-cluster-memory-16GB
Last active November 9, 2020 19:24
k8s cluster memory % for 16GB RAM VMs
VM_MEM=16
VM_NODES=$(kubectl top node --sort-by memory | grep -iv memory | wc -l)
K8S_MEM=$(kubectl top node --sort-by memory | awk '{print $5}' | tr -d '%' | grep -iv memory | paste -s -d+ - | bc)
echo "Cluster Memory: $(($VM_NODES*$VM_MEM*100/$K8S_MEM))%"
@rms1000watt
rms1000watt / aws-cli-elastic-ips-filter-tag.sh
Created April 8, 2020 20:55
Get Elastic IPs and filter based on tag via aws cli
aws ec2 describe-addresses --filters "Name=tag:Environment,Values=qa" | jq -r '.Addresses[].PublicIp'
@rms1000watt
rms1000watt / get-set-k8s-secret-val.sh
Last active July 13, 2020 20:57
Get & Set Kubernetes Secret Value
kubectl get secret app1 -o jsonpath="{.data.MYSQL_CONN}" | base64 --decode
cs=$(echo -n "mysql://user:pass@host:port/db" | base64)
kubectl patch secret app1 -p='{"data":{"MSQL_CONN": "'"${cs}"'"}}' -v=1
@rms1000watt
rms1000watt / run-exec-k8s.sh
Last active February 18, 2022 00:35
Run a Pod in Kubernetes without configuration and exec into it
#!/usr/bin/env bash
# Create a container to shell into and run commands from
kubectl run ryan-smith-test --rm -it --restart=Never --image=nginx -- bash
# Create a container that is long lived and will restart
kubectl run test-pod --image nginx
kubectl -it exec test-pod bash
## run your commands
# exit