Skip to content

Instantly share code, notes, and snippets.

Jonathan Kosgei jonathan-kosgei

Block or report user

Report or block jonathan-kosgei

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jonathan-kosgei
jonathan-kosgei / Vagrantfile
Created Jul 19, 2017
Kubernetes Vagrant Setup
View Vagrantfile
$script = <<SCRIPT
# Install docker
curl -fsSL get.docker.com | sh
# Install kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
# Install kubeadm
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
@jonathan-kosgei
jonathan-kosgei / docker_clean_ci.sh
Last active Jul 15, 2017
Delete all images in order of dependency excluding selected base images for faster builds
View docker_clean_ci.sh
#!/bin/bash
function list_include_item { local list="$1"; local item="$2"; if [[ $list =~ (^|[[:space:]])"$item"($|[[:space:]]) ]] ; then result=0; else result=1; fi; return $result;};
bases="alpine:latest nginx:1.11.3-alpine"
delete=
# append latest tag to each image
for item in $(docker images --format "{{.Repository}}:{{.Tag}}@{{.ID}}")
do
export IFS=' '
IFS='@'; arr=($item); unset IFS;
@jonathan-kosgei
jonathan-kosgei / docker_image_clean.sh
Last active Jul 12, 2017
Clear all images on a Docker host except base images
View docker_image_clean.sh
#!/bin/bash
# set variable with base image names
# get base image ids and set in other list
all_images=`mktemp`
base_images=`mktemp`
#base_image_names="alpine linux"
#ids=`docker images --no-trunc -q $(base_image_names)`
bases="sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d624560 sha256:33aa78cbda15ae84375c46dfc3fc07560c9af8e7b8f37745d2c6542e2affec9f"
docker images -q --no-trunc > $all_images
@jonathan-kosgei
jonathan-kosgei / thirdpartypaths.json
Created May 3, 2017
Kubernetes Third Party Path json
View thirdpartypaths.json
{
"/apis/{fqdn}/v1/{resource}": {
"get": {
"security": [
{
"Bearer": [
]
}
],
View Dockerfile
FROM debian:jessie
MAINTAINER a.mulholland
RUN apt-get update && apt-get upgrade -y &&\
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&\
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list &&\
curl -sL https://deb.nodesource.com/setup_6.x | bash -
apt-get install -y nodejs yarn nginx php5-fpm php5-mysqlnd php5-curl php5-mcrypt php5-gd git curl mysql-client openssh-client
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
@jonathan-kosgei
jonathan-kosgei / schedule_function.sh
Created Apr 19, 2017
AWS Lambda backup EBS volumes with BOTO3
View schedule_function.sh
# Scheduling the above script hourly. Ensure you're properly authenticated via aws configure.
#!/bin/bash
zip ebs-backup-worker.zip .schedule-ebs-snapshot-backups.py
aws lambda create-function --function-name ebs-backup-worker \
--runtime python2.7 \
--role "arn for your lambda user's role" \
--handler lambda_handler \
--zip-file fileb:///ebs-backup-worker.zip
View snapshot_ebs_volumes_lambda_task.py
""" Make sure to create the "backup" tag on the volumes you want to backup.
For authentication, setup the aws policy and user as specified in the snapshot-trust.json and snapshot-policy.json
Inspired by: https://serverlesscode.com/post/lambda-schedule-ebs-snapshot-backups/
"""
from time import gmtime, strftime
import boto3
region = "us-west-2"
backup_tag = "backup"
@jonathan-kosgei
jonathan-kosgei / largest_number_in_nested_number_list.py
Last active Mar 5, 2017
Find largest number in nested number list Python
View largest_number_in_nested_number_list.py
def max_in_nested_number_list(numbers):
largest = 0
for item in numbers:
if isinstance(item, list):
numbers.append(max_in_nested_number_list(item))
else:
largest = item if item>largest else largest
return largest
@jonathan-kosgei
jonathan-kosgei / internal_ip.sh
Created Feb 25, 2017
Command to get internal ip programmatically
View internal_ip.sh
# From this askubuntu question http://askubuntu.com/a/604691/280044
ip route get 8.8.8.8 | awk '{print $NF; exit}'
@jonathan-kosgei
jonathan-kosgei / installing_calico_for_docker_networking.sh
Last active Mar 3, 2017
Installing Calico for Docker Networking
View installing_calico_for_docker_networking.sh
#!/bin/sh
# Setup Calico for Docker on Ubuntu 16.04
# Change to the internal ip of your node
NODE_IP=ip route get 8.8.8.8 | awk '{print $NF; exit}'
# Install docker
sudo apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \
You can’t perform that action at this time.