Skip to content

Instantly share code, notes, and snippets.

View rms1000watt's full-sized avatar

Ryan M Smith rms1000watt

View GitHub Profile
@rms1000watt
rms1000watt / k8s-print-pods-per-node.sh
Created February 26, 2020 22:07
Kubernetes Print all Pods per Node
#!/usr/bin/env bash
rm k8s-nodes-pods.txt &> /dev/null
for node in $(kubectl get nodes | grep -v NAME | cut -d' ' -f1); do
kubectl describe node "${node}" | grep -A99999 Namespace | grep -B999999 "Allocated resources:" | grep -v Allocated | grep -v Namespace | grep -v "\-\-\-\-\-" | awk '{print "'"${node}"' " $0}' >> k8s-nodes-pods.txt
done
@rms1000watt
rms1000watt / dind.sh
Created February 18, 2020 23:14
Docker in Docker 2020
docker run -it --rm --privileged docker:dind sh
# Then inside the container
dockerd-entrypoint.sh dockerd &
DOCKER_HOST=unix:///var/run/docker.sock
docker run -itd --rm redis
docker ps
@rms1000watt
rms1000watt / diff-helmfile-k8s.sh
Last active February 19, 2020 23:05
Get diff for helmfile against actual k8s state
#!/usr/bin/env bash
# Render all the k8s yaml
helmfile -f hello.yml template > ~/Desktop/hello.helmfile.yml
# Diff the new yaml with what's actually deployed
tail -n +2 ~/Desktop/hello.helmfile.yml | kubectl diff -f - > ~/Desktop/hello.helmfile.diff
# If diff is acceptable, run k8s
kubectl apply -f ~/Desktop/hello.helmfile.yml
@rms1000watt
rms1000watt / strace-open-openat.sh
Created December 6, 2019 23:17
See all files your program touches strace open openat
strace -e open -e openat go run main.go
@rms1000watt
rms1000watt / routetables-netstat.sh
Created November 26, 2019 18:58
Look at the route table on your machine using netstat -nr
netstat -nr
@rms1000watt
rms1000watt / svc-to-file.sh
Created November 15, 2019 23:11
Kubernetes save all deployed resources to file
#!/usr/bin/env bash
# Usage:
# ./svc-to-file.sh hello-world dev
if [[ -z $1 ]]; then
echo "ERROR: No service name provided"
exit 1
fi
@rms1000watt
rms1000watt / kubectl-pods-older-than-1-day.sh
Created November 6, 2019 22:45
Kubectl get all pods that are older than 1 day
# https://stackoverflow.com/a/53989428
kubectl get pod | awk 'match($5,/[0-9]+d/) {print $0}'
@rms1000watt
rms1000watt / nginx.conf
Created October 24, 2019 06:19
Enable SNI Proxying in Nginx
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ssl_server_name
# The Server Name is a TLS extention (not SSL) during the CLIENT HELLO in the init client TLS handshake for SNI.
# If this frame "server_name" is missing in the CLIENT HELLO packet, the server should fail TLS
# This happens with AWS Cloudfront
location /path/here/ {
proxy_redirect off;
proxy_ssl_server_name on;
proxy_pass https://proxy-site.com/path/here/;
}
@rms1000watt
rms1000watt / jinja2-omit-comma-from-item.txt.j2
Created October 18, 2019 21:10
Jinja2 omit comma from last item in list
# Courtesy of: https://stackoverflow.com/a/11974399
{%- for item in items %}
[
"{{item}}"{{ "," if not loop.last }}
]
{%- endfor %}
@rms1000watt
rms1000watt / jinja2-omit-comma-from-item.txt.j2
Created October 18, 2019 21:10
Jinja2 omit comma from last item in list
# Courtesy of: https://stackoverflow.com/a/11974399
{%- for item in items %}
[
"{{item}}"{{ "," if not loop.last }}
]
{%- endfor %}