Skip to content

Instantly share code, notes, and snippets.

View mrballcb's full-sized avatar

Todd Lyons mrballcb

View GitHub Profile
@mrballcb
mrballcb / description.txt
Last active September 1, 2022 15:00
Helper script for lungo on MacOS
Usage:
# Both of these will activate lungo for 10 hours
lungo 10 hours
lungo hours=10
# Both of these will toggle lungo off if it's on, or on indefinitely if it was off
lungo toggle
lungo
@mrballcb
mrballcb / list_filter_awless.sh
Created August 8, 2022 18:37
Multiple account awless search/filter
#!/usr/bin/env bash
set -eu -o pipefail
FILTER=${1-.*}
REGIONS="us-east-1 us-east-2 us-west-1 us-west-2"
tempwork=$(mktemp -d)
# When the script finishes or is cancelled, clean up the temp dir
@mrballcb
mrballcb / get_ELK_status.sh
Created May 10, 2022 16:30
Summary view of ELK cluster
#!/bin/bash
function ssh_and_get_status {
SSH=$1
SSHARGS=$2
TARG=$3
ssh $SSHARGS $SSH "
echo
curl -s 'http://$TARG/_cat/nodes?v'
echo
@mrballcb
mrballcb / rancher_desktop_restart.txt
Last active March 14, 2022 16:55
Restart Rancher Desktop from the CLI on Mac
Rancher Desktop is what I've switched to in place of Docker Desktop. It has some differences that
need to be worked around (see previous gist for setting the network subnet a container uses).
One other issue is that after about 24 hours, the docker socket just stops listening. It is currently
on Rancher's radar, but in the meantime, the only real solution is to stop and start the entire
Rancher Desktop app. The below script does exactly that.
A second issue is that a running k3s cluster consumes enough CPU/power that it raises the temperature
of the Mac when it's idle and significantly cuts down on battery life. The second script will stop
the k3s subsystem and kill all running containers, bringing the CPU usage down to a very low level.
@mrballcb
mrballcb / rancher_desktop_BIP.txt
Last active April 6, 2023 08:46
Configure Rancher Desktop 1.0.0 to use a custom bridge IP on Mac
# This will survive restarts of Rancher Desktop. I don't expect it to survive "Reset Kubernetes" actions.
# This will get a shell inside the running VM.
# Many thanks to Jan Dubois, this one liner replaced a complicated set of commands I had here earlier.
LIMA_HOME="$HOME/Library/Application Support/rancher-desktop/lima" limactl shell 0
sudo su -
vi /etc/conf.d/docker
# Add to the DOCKER_OPTS cli the bip and subnet you want. I picked a very small /24 at the end of the 172.16/20 space:
@mrballcb
mrballcb / show_kube_status.sh
Created November 4, 2021 18:18
Show pods in "transition" mode
#!/usr/bin/env bash
# Expected input can be one of the following types:
# CTX # Just the context - shows "transition mode" for this cluster and all kube masters/nodes
# CTX NS # The context, a space, and the namespace - shows all pods in that NS and only kube nodes
TYPE=${1-none}
CTX=${TYPE}
NS=${2-$TYPE}
# Extract instance types, AZ, and kops instance group name
SED_FILTER_LABELS="-e 's/beta.kubernetes.*instance-type=/type=/' -e 's#beta.kubernetes.io/##g' -e 's#kubernetes.io/##g' -e 's#,arch=\w*##' -e 's#,os=\w*##'"
@mrballcb
mrballcb / user_access_key_list.sh
Created July 30, 2021 21:41
Save a copy of all users with access keys in an S3 bucket
#!/usr/bin/env bash
set -eu -o pipefail
MYROLE=elevated # Set to whatever you named your role
MYBUCKET=history # Set to whatever S3 bucket you will put this
DATE=$(date +%F)
AWS_ACCOUNT=$(aws sts get-caller-identity | jq -r .Account)
@mrballcb
mrballcb / filter_instances.sh
Last active February 26, 2021 18:15
jq displaying filtered EC2 instances, only selected fields
# Loops through regions
# Gets all data for instances in the inner array
# Outputs instance id, AZ, Launch Time, and the Name tag
for REGION in us-east-1 us-west-1; do
aws --region $REGION ec2 describe-instances | \
jq '.Reservations[].Instances[] | select(.InstanceId as $id | ["id-1234", "id-56789"] | index($id)) | [.InstanceId, .Placement.AvailabilityZone, .LaunchTime, [.Tags[] | select(.Key == "Name") | .Value][] ]'
done
@mrballcb
mrballcb / gist:507db8d740832500b57c312aa326057b
Last active April 25, 2020 18:01
vim macros to convert TF 0.11 -> 0.12
When your TF is already partially TF12 and the TF11->12 converter barfs on it.
Regex anchors on beginning of line, so any commented config won't be adjusted.
## remove quotes from variable and provider and output lines
:%s/^\(variable\|provider\|output\) "\(\S*\)"/\1 \2/
## remove quotes from resource and data lines
:%s/^\(resource\|data\) "\(\S*\)" "\(\S*\)"/\1 \2 \3/
## remove quotes from type=$TYPE lines, preserving leading spacing
@mrballcb
mrballcb / description.txt
Last active August 20, 2019 18:19
RabbitMQ Federation Instability
Cluster description:
Three 2 node RMQ-3.7.14 clusters, running in Kube, all inbound ports are exposed
via an internal ELB.
All users, permissions, policies, parameters (upstreams, sets) are defined in a
definitions.json file read when each cluster node starts.
The data volumes are EBS volumes, so is persistent across restarts.
Cluster locations:
us-east-1 (10.9.73.0/24)
eu-central-1 (10.10.17.0/24)
us-west-1 (10.11.12.0/24)