Skip to content

Latest commit

 

History

30 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

Just some stuff that I'm too bored to write again and too lasy to develop into separate tool(code). DevOps Automation routines mostly.

Warning! Use it strictly on your own risk

AWS

Update user password (cli is the last resort ex.)

aws --profile PROFILE iam update-login-profile --user-name USER --password

Search for something in some trashcan S3 bucket. Second is iterate over buckets with threaded tool(s4cmd)

aws --profile PROFILE s3 ls s3://BUCKET/ --recursive | grep PATTERN
for b in $(s4cmd -r ls | grep ftp | awk '{print $4}') ; do s4cmd -r ls ${b}1465/ ; done

Find subnets that are short of IPs

aws --profile PROFILE ec2 describe-subnets --filters "Name=vpc-id,Values=VPC_ID" | jq '.Subnets[] | .SubnetId + "=" + "\(.AvailableIpAddressCount)"'

Get all user keys. For blameless security investigation, you know

for u in $(aws --profile PROFILE iam list-users  | jq ".Users[].UserName" --raw-output); do   aws --profile PROFILE iam list-access-keys --user $u | jq '.AccessKeyMetadata[] | .UserName + ":" + .AccessKeyId' ; done

List EC2s + "plainification" with gron

aws ec2 describe-instances | gron | grep 'MetadataOptions.HttpTokens = "optional"' 

SSM tips

Get all instances with inventory without those in terminated state.

Terminated instances sometimes are a problem. More about it.

aws ssm get-inventory --filters '[{"Key":"AWS:InstanceInformation.InstanceStatus","Values":["terminated"],"Type":"NotEqual"}]'

One more tip is to send huge jsons to gron. Grep Json.

Connect to an instance by name

aws ssm start-session --target INSTANCE_NAME

K8S

See Events sorted by timestamp

k get events --sort-by='.lastTimestamp'

Merge kubeconfigs

cp ~/.kube/config ~/.kube/config.bak && KUBECONFIG=~/.kube/config:./ok-cluster/ok-cluster-eks-a-cluster.kubeconfig kubectl config view --flatten > /tmp/config && mv /tmp/config ~/.kube/config

Add profile to kubeconfig, all of profiles all clusters

aws eks --profile ok-dev update-kubeconfig --name eks-terra --alias ok-eks
for p in $(aws configure list-profiles) ; do for c in $(aws eks --profile $p list-clusters | jq '.clusters[]' | tr -d '\"') ; do echo $p $c ; aws eks --profile $p update-kubeconfig --name $c --alias $p:$c ; done ; done

Saving private persistent volume

kubectl patch pv $PV_NAME_i -p \
  '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'

Label all nodes with their type and lifecycle, mark your cattle ;)

for n in $(kubectl get nodes -o 'jsonpath={.items[*].metadata.name}') ; do lb="" ;  for a in $(kubectl label --list nodes $n | sort | grep -e NodeType -e lifecycle | cut -d= -f 2) ; do lb="${lb}$a" ; done ; kubectl label nodes $n node-role.kubernetes.io/$lb= ; done

Debugging a distroless(ex.) pod

kubectl debug -it POD --image=IMAGE_WITH_TOOLS --target=CONT --share-processes

MySQL

Kill somebody's sessions in RDS

SELECT CONCAT('CALL mysql.rds_kill(',id,');')
FROM information_schema.processlist
WHERE user='UGLY_BASTARD';

Self-explanatory

SHOW OPEN TABLES WHERE In_use > 0;
SHOW ENGINE INNODB STATUS;

Skip replication errors, read error-logs before skipping. It is important to understand what you are skipping.

CALL mysql.rds_skip_repl_error;

Other

Delete ALL topics in Kafka

export KFK=KFK_HOST
for t in $(./bin/kafka-topics.sh --bootstrap-server  $KFK:9092 --list) ; do ./bin/kafka-topics.sh --bootstrap-server $KFK:9092 --topic $t --delete ; done
#-||- --describe | grep 'ReplicationFactor:1' ; done

Inframamp

terraform state pull | inframap generate --connections=false | dot -Tpng > ~/Downloads/schema.png

KUBE-OPS-VIEW

(kubectl proxy --accept-hosts '.*' &) ; docker run -it -p 8080:8080 -e CLUSTERS=http://docker.for.mac.localhost:8001 hjacobs/kube-ops-view

Migrate Grafna DB from MySQL to PgSQL

podman run -it     --workdir $(pwd)/podman     --volume $(pwd)/podman:$(pwd)/podman:rw,Z     --rm ghcr.io/techouse/mysql-to-sqlite3:latest     --sqlite-file baz-prod.db     --mysql-user grafana     --mysql-password hehe     --sql-database prod_monitoring     --mysql-host MY_HOST --use-buffered-cursors

pg_dump --schema-only -h PG_HOST -U grafana -d grafana > schema.sql 
psql -h PG_HOST -U grafana -d grafana -f  schema.sql 

cat podman/f.load
load database
  from sqlite://baz-prod.db
  INTO postgresql://grafana:HEHE@PG_HOST/grafana?sslmode=prefer
  with data only, reset sequences, prefetch rows = 100
  set work_mem to '32MB', maintenance_work_mem to '256 MB';

podman run --rm -it  --workdir $(pwd)/podman  --volume $(pwd)/podman:$(pwd)/podman:rw,Z  dimitri/pgloader:latest   pgloader f.load

About

Some practice-gained oneliners of lasy ops

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors