Skip to content

Instantly share code, notes, and snippets.

View mmastoras's full-sized avatar

Mark Mastoras mmastoras

  • Foghorn Consulting
  • San Bruno, California
View GitHub Profile
# get status of a job
$ nomad job status -no-color kafka-broker
ID = kafka-broker
Name = kafka-broker
Submit Date = 2019-07-24T14:03:41-07:00
Type = service
Priority = 50
Datacenters = alpha
Status = dead
Periodic = false
@mmastoras
mmastoras / dpkg lock
Last active June 20, 2022 23:07
dpkg lock
#!/bin/bash
apt-get update
apt-get install -y psmisc
i="0"
while [ $i -lt 10 ]
do
if [ $(fuser /var/lib/dpkg/lock) ]; then
Here’s a bash function to make it easier to shell into kubernetes pods. Running `kubash` by itself will give you a list of pod names;
$ kubash <pod name # will open a bash shell on a pod with that name. It works via prefix matching so any of the following would work:
$ kubash railsapp-68b45f5c7b-98qqz #attach to this specific pod
$ kubash railsapp #attach to any railsapp-* pod
$ kubash ra #attach to some pod that starts with "ra"
/bin/kubash
kubash() {
if [ "$1" = "" ]; then
@mmastoras
mmastoras / gist:7e20755e470144fc9f87d2fe4989da20
Created April 2, 2019 19:31
fix for debian expired repos
apt-get update -o Acquire::Check-Valid-Until=false
@mmastoras
mmastoras / gist:600e4dae073354b85b918d9346d5815c
Last active June 6, 2019 23:25
Encrypting Secrets w/ KMS for use in terraform
# Encrypt a key for use in aws secrets manager terraform state files
1. Encrypt a secret using the aws cli
$ echo "<secret>" | tr -d '\n' > secret.txt # strip the newline from the echo
$ aws kms encrypt --key-id alias/aws/secretsmanager --plaintext fileb://secret.txt --encryption-context "type=password,env=staging" --output text --query CiphertextBlob | pbcopy
2. Create the aws_kms_secrets data resource in terraform
data "aws_kms_secrets" "mercury" {
secret {
name = "staging_db_password"
@mmastoras
mmastoras / port checks
Last active May 23, 2023 18:46
Port checks + network troubleshooting
$ nc -vz -u 10.100.0.10 53
Connection to 10.100.0.10 53 port [udp/domain] succeeded!
# nc -vz 10.100.0.10 443
Connection to 10.100.0.10 443 port [tcp/*] succeeded!
#!/bin/bash
echo "waiting for elasticsearch"
for i in {1..60}; do
nc_output=$(nc -zv localhost 9200 2>&1 >/dev/null)
[[ $nc_output == *"open"* ]] && break
sleep 1
echo -n "."
done
@mmastoras
mmastoras / gist:11d438eafd9581206b547b2004348ba6
Last active January 24, 2024 22:31
kubectl cheat sheet
# get logs from a pod
$ kubectl logs -f <pod name> --namespace <namespace>
# get logs from a specific container in a pod
$ kubectl logs -f <pod name> -c <container> -n <namespace>
# get logs across several containers
$ kubectl logs -l istio=ingressgateway -n istio-system -c ingress-sds # by using label
# get list of pods and observe their logs
# run bash in a specific container image
docker run -it <image> /bin/bash
# run bash and mount a local volume into a specific contaimer image
docker run -it -v $(pwd):/pki-tools/pki dprails/pki-tools /bin/bash
# run a x86 docker image on M1 mac
docker run -it --platform linux/amd64 -v $(pwd):/pki-tools/pki dprails/pki-tools /bin/bash
# build on m1 mac
@mmastoras
mmastoras / gist:6e2fe61d108c69a4894a0bd59883cd4a
Created November 13, 2017 22:52
uninstall mysql5.7 and install mysql 5.6 client only on ubuntu 1604
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
dpkg -l | grep mysql
sudo apt-get install mysql-client-core-5.6
sudo apt-get update
sudo add-apt-repository -y ppa:ondrej/mysql-5.6
sudo apt-get update
sudo apt-get install mysql-client-core-5.6
dpkg -l | grep mysql