Skip to content

Instantly share code, notes, and snippets.

View eshleebien's full-sized avatar

Esh Romero eshleebien

  • Manila, Philippines
View GitHub Profile
@eshleebien
eshleebien / medium-kong-gw-for-k8s-custom-kong-ingress.yaml
Created December 8, 2019 12:34
For Kong Gateway for Kubernetes medium article.
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
name: api-configuration
upstream:
hash_on: none
hash_fallback: none
healthchecks:
active:
concurrency: 10
@eshleebien
eshleebien / medium-kong-gw-for-k8s.yaml
Last active December 8, 2019 12:18
For Kong Gateway for Kubernetes medium article
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: api
labels:
app: api
spec:
rules:
- host: api.gengo.dev
http:
@eshleebien
eshleebien / kube-api-drain.sh
Created July 19, 2019 08:34
kubectl drain using kubernetes api
HOSTNAME=`curl -s http://169.254.169.254/latest/meta-data/local-hostname`
SERVER=$1
TOKEN=$2
curl -s --insecure -k -v -H "Accept: application/json" -H "Authorization: Bearer $TOKEN" -XPATCH -d '{"spec":{"unschedulable":true}}' -H "Content-Type: application/merge-patch+json" $SERVER/api/v1/nodes/$HOSTNAME
for each in $(curl -s -k -H "Authorization: Bearer $TOKEN" --insecure -XGET $SERVER/api/v1/namespaces | jq -r '.items[].metadata.name');
do arr=($(curl -s -k -H "Authorization: Bearer $TOKEN" --insecure -XGET $SERVER/api/v1/namespaces/$each/pods | jq --arg node $HOSTNAME -r '.items[] | select(.spec.nodeName == $node) | .metadata.name'));
for i in ${arr[@]};
@eshleebien
eshleebien / kube-api-labeler.sh
Created July 19, 2019 08:31
Label current node using Kubernetes API. Usage ```./kube-api-labeler.sh http://kube-api-server:8000 service_account_token```
SERVER=$1
HOSTNAME=`curl -s http://169.254.169.254/latest/meta-data/local-hostname`
TOKEN=$2
$KEY="node-role"
$VALUE="applications"
while true; do
if curl -s --insecure -k -H "Accept: application/json" -H "Authorization: Bearer $TOKEN" $SERVER/api/v1/nodes | grep $HOSTNAME
@eshleebien
eshleebien / medium-terminating-with-grace.py
Created July 9, 2019 07:31
For my medium article "Containers: Terminating with grace"
# source code
# shamelessly copied from
# https://stackoverflow.com/a/31464349/2591014
import signal
import time
class GracefulKiller:
kill_now = False
signals = {
chef-solo --lockfile /tmp/chef-1.pid -c ../path/to/your/solo-test.rb -E staging -o your-cookbooks::recipe >> /tmp/chef.log 2>&1 || exit 1 &
chef-solo --lockfile /tmp/chef-2.pid -c ../path/to/your/solo-test.rb -E live -o your-cookbooks::anotherrecipe >> /tmp/chef.log 2>&1 || exit 1 &
chef-solo --lockfile /tmp/chef-3.pid -c ../path/to/your/solo-test.rb -E dev -o your-cookbooks::anootheronerecipe >> /tmp/chef.log 2>&1 || exit 1 &
wait
has_errors = `grep -rn "ERROR" /tmp/chef.log`
if [ ! -z "$has_errors" ]; then
echo -e "Error occured"
cat /tmp/chef.log
rm /tmp/chef.log
#!/bin/bash
chef-solo -c ../path/to/your/solo-test.rb -E staging -o your-cookbooks::recipe || exit 1
chef-solo -c ../path/to/your/solo-test.rb -E staging -o your-cookbooks::another_recipe || exit 1
@eshleebien
eshleebien / medium-run-chef-recipes-in-travis-ci-travis.yaml
Created July 4, 2019 00:39
For run chef recipes in travis ci story
dist: xenial
sudo: true
install:
- "curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -v 14.7.17"
script:
- "chmod +x run_tests.sh"
- "./run_tests.sh"
@eshleebien
eshleebien / medium-solo-test.rb
Created July 4, 2019 00:33
For run chef recipes in travis CI story
base = File.expand_path('..', __FILE__)
nodes_path File.join(base, '/../nodes')
role_path File.join(base, '/../roles')
data_bag_path File.join(base, '/../data_bags')
encrypted_data_bag_secret File.join(base, '/../data_bag_key')
environment_path File.join(base, '/../environments')
ssl_verify_mode :verify_peer
solo_legacy_mode true
aws --version # make sure it is 1.16 and up
# aws-cli/1.16.192 Python/3.7.3 Darwin/18.2.0 botocore/1.12.182
aws rds create-db-instance-read-replica \
--db-instance-identifier main-db \
--source-db-instance-identifier [arn resource url of the source] \
--db-subnet-group-name [subnet in a different VPC] \
--vpc-security-group-ids [security group in a different VPC]