Skip to content

Instantly share code, notes, and snippets.

View jcderr's full-sized avatar

Jeremy Derr jcderr

  • Amsterdam
View GitHub Profile
@jcderr
jcderr / devnull
Created June 7, 2017 19:59
K8S Deployment Dev-nuller
#!/bin/bash
# Usage: devnuller <deployment>
# When troubleshooting k8s deployments, it is sometimes helpful to set command: ["tail", "-f", "/dev/null"]
# so that you have a long-running null-command, allowing you to `kubectl exec ...` in and troubleshoot the
# environment. This will do that, and tell you how to roll back your command.
DEPLOYMENT="
P_REV=$(kubectl get deployment/${DEPLOYMENT} -o json | \
jq -r '.metadata.annotations["deployment.kubernetes.io/revision"]')
@jcderr
jcderr / k8scopy.sh
Last active January 26, 2021 18:34
Copy a Kubernetes Context
#!/bin/bash
FROM=$1
[[ -n "$FROM" ]] || exit 1
for ITEM in ns secrets configmaps rc deployments svc; do
for OBJ in $(kubectl --context=$FROM get $ITEM -o name); do
kubectl --context=$FROM get $OBJ -o yaml | kubectl create -f -
done
@jcderr
jcderr / cloud-config
Created September 13, 2016 14:54
secured kubernetes cloud-config
#cloud-config
write-files:
- path: /opt/bin/wupiao
permissions: '0755'
content: |
#!/bin/bash
# [w]ait [u]ntil [p]ort [i]s [a]ctually [o]pen
[ -n "$1" ] && [ -n "$2" ] && while ! curl --output /dev/null \
--silent --head --fail \
http://${1}:${2}; do sleep 1 && echo -n .; done;
@jcderr
jcderr / wucfd
Created July 12, 2016 15:43
(W)ait (U)ntil (C)loud(F)ormation (D)one
#!/bin/zsh
autoload colors
if [[ "$terminfo[colors]" -gt 8 ]]; then
colors
fi
for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
eval ${COLOR}='$fg_no_bold[${(L)COLOR}]'
@jcderr
jcderr / wuamid
Created July 12, 2016 14:50
(W)ait (U)ntil (AMI) (D)one
#!/bin/zsh
autoload colors
if [[ "$terminfo[colors]" -gt 8 ]]; then
colors
fi
for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
eval ${COLOR}='$fg_no_bold[${(L)COLOR}]'
eval BOLD_${COLOR}='$fg_bold[${(L)COLOR}]'
@jcderr
jcderr / nginx-conf.d-conf-file
Last active January 15, 2019 16:50
Kubernetes Nginx Gateway with Upstreams from ConfigMap
include /etc/nginx/conf.d/upstreams/*.conf;
server {
listen 8080;
resolver 10.99.254.254;
server_name ~^(?<svc>[a-zA-Z0-9]+)(?<env>[\-a-zA-Z0-9]*)\..*\.com$;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@jcderr
jcderr / w200
Last active January 26, 2016 18:43
wait until server/url responds with 200
#!/bin/bash
URL=$1
CODE="200"
[[ -n "$URL" ]] || { echo "Please specify a URL to watch"; exit 1; }
[[ -n "$2" ]] && CODE=$2
while true; do
STATUS=$(curl -o /dev/null --insecure --silent --head --write-out '%{http_code}' ${URL})
@jcderr
jcderr / wupiao
Created July 30, 2015 16:46
[W]ait [U]ntil [P]ort [I]s [A]ctually [O]pen
#!/bin/bash
# usage: wupiao [ip] [port]
# inspired by script of same name from Kubernetes project
# we're going to test any port, though, not just HTTP
[ -n "$1" ] && [ -n "$2" ] && while ! nc -z $1 $2; do sleep 1 && echo -n .; done;
exit $?
@jcderr
jcderr / kube-apiserver.service
Created July 15, 2015 15:21
CoreOS Units for upgrading Kubernetes Master
[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
Requires=setup-network-environment.service etcd2.service generate-serviceaccount-key.service
After=setup-network-environment.service etcd2.service generate-serviceaccount-key.service
[Service]
EnvironmentFile=/etc/network-environment
ExecStartPre=-/usr/bin/mkdir -p /opt/bin
ExecStartPre=-/usr/bin/mv /opt/bin/kube-apiserver /opt/bin/kube-apiserver.backup
@jcderr
jcderr / vpnroute.sh
Created March 13, 2015 21:06
vpnroute.sh
#!/bin/bash
GATEWAY=$(ifconfig | grep 192.168 | grep "\-\->" | awk '{ print $2 }')
sudo /sbin/route add -net 10.0.0.0 -netmask 255.0.0.0 -gateway $GATEWAY