Kubernetes on AWS

The AWS cluster configuration script Kubernetes comes with works pretty much flawlessly, with two exceptions. First, make sure you have curl installed on the system you are bootstrapping the cluster from. And, second, make sure the awscli package is recent.

The Debian AWS AMI does not come with curl installed and the awscli package is an old version: aws-cli/1.4.2 Python/3.4.2 Linux/3.16.0-4-amd64).“ After running pip install --upgrade awscli you should see a version at least: aws-cli/1.10.24 Python/2.7.9 Linux/3.16.0-4-amd64 botocore/1.4.15.

Good times.

Custom Nginx error pages on upstream responses

Digital Ocean has a great post on setting up error pages when nginx encounters an error. However, the above does not work when a request is successfully passed to an upstream server and the upstream response is a 50x error. When processing the upstream response is desired, proxy_intercept_errors on; must be added to the configuration (thank you Stack Overflow!).

The server block looks like this:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        [...]

        proxy_intercept_errors on;
        error_page 500 502 503 504 /custom_50x.html;
        location = /custom_50x.html {
                root /usr/share/nginx/html;
                internal;
        }

        [...]
}

InfluxDB on Raspberry Pi

I found a blog post by Aymerick describing how to build InfluxDB on a Raspberry Pi. Here’s what I did to get it working.

Install prerequisites

$ sudo apt-get install -y bison ruby2.1 ruby-dev build-essential
$ sudo gem2.1 install fpm

Install gvm

This installs gvm for the current user:

$ bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

Setup Go

$ gvm install go1.4.3
$ gvm use go1.4.3 --default

Create an influxdb package set

$ gvm pkgset create influxdb
$ gvm pkgset use influxdb

Build InfluxDB

$ go get github.com/sparrc/gdm
$ go get github.com/influxdata/influxdb
$ cd ~/.gvm/pkgsets/go1.4.3/influxdb/src/github.com/influxdata/influxdb
$ gdm restore
$ go clean ./...
$ go install ./...

The ./package.sh command did not work for me, so I settled for the influxd and influx binaries in ~/.gvm/pkgsets/go1.4.3/influxdb/bin.

Mac + Docker Toolbox + HAProxy

Working with Docker Toolbox on a Mac is great. It makes it very easy to work with Docker continers and setting up interconnected services with Docker Compose. However, since the services are running in a virtual machine, accessing the services from a machine other than the Mac itself is not possible out of the box.

HAProxy

Installing and running HAProxy on the Mac will proxy any traffic from the VM to external hosts looking to access the service. I installed haproxy via homebrew with the command brew install haproxy.

With HAProxy installed, I set it up to proxy HTTPS traffic over to the VM. In my case, the VM was 192.168.99.100 and my Mac’s IP was 192.168.1.200. I saved the configuration below at /usr/local/etc/haproxy/haproxy.cfg.

global
  log  127.0.0.1  local0
  log  127.0.0.1  local1 notice
  maxconn  4096
  chroot   /usr/local/share/haproxy
  uid  99
  gid  99


defaults
  log   global
  mode  tcp
  option  dontlognull
  retries  3
  option  redispatch
  option  http-server-close
  maxconn  2000
  timeout connect  5000
  timeout client  50000
  timeout server  50000


frontend www_fe
  bind 192.168.1.200:443

  use_backend www


backend www
  timeout server 30s
  server www1 192.168.99.100:443

Launch daemon

With haproxy configured, I placed the launchd configuration at /Library/LaunchDaemons/com.zymbit.haproxy.plist and ran the command sudo launchctl load -w /Library/LaunchDaemons/com.zymbit.haproxy.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>Label</key>
 <string>com.zymbit.haproxy</string>
 <key>ProgramArguments</key>
 <array>
   <string>/usr/local/bin/haproxy</string>
   <string>-db</string>
   <string>-f</string>
   <string>/usr/local/etc/haproxy/haproxy.cfg</string>
 </array>
</dict>
</plist>

Starting and stopping launchd

Now, whenever I want external access to the Docker service I run the command launchctl start com.zymbit.haproxy and when I’m done launchctl stop com.zymbit.haproxy.

Manually booting from a Grub prompt

I installed Ubuntu on a Cisco UCS C250 M2 system with a USB flash drive. The installer attempted installing Grub on the installer drive instead of the system drive. In attempts to have a bootable system, I dropped to a shell and ran:

chroot /target /bin/bash
grub-install /dev/sdb (where sdb is drive you installed on)

The above installed Grub, but didn’t configure it to boot the system. After booting I landed at a grub prompt instead of the system prompt. I was able to boot the system with the steps below.

First, I ran the command below to get the drive’s UUID. Below <tab> is tapping the tab key on the keyboard:

ls (hd0<tab>

This prints out details of the drive; the UUID is needed in the command below.

insmod ext2
set root='hd0,msdos1'
linux /boot/vmlinuz<tab> root=UUID=<insert UUID here>
initrd /boot/initrd<tab>
boot

This properly booted the system. From here, the first thing to do is install Grub properly. Login to the system and run:

update-grub
grub-install /dev/sda

After a reboot the system booted properly.

Transplant commits with git rebase –onto

You are working along and then realize that all the work you did is based off the wrong branch. Instead of working off the branch wrong-branch, you should have been working off the branch right-branch. What to do?

First, as a safety create a fix branch off your current branch:

git checkout -b fix-topic-branch topic-branch

Now, take a look at the commits to find the ref your work is on top of:

git log --oneline --decorate

8cb0c1a (fix-topic-branch) Added artcode urls
1ff8dac Added art form
0670ee7 added django-resourceful requirement
633dda6 Added ArtView class
e64f05f Added models
4186ba8 Added pristine django app artcode
d49ad49 (wrong-branch) Merge branch 'add-test-finder' into baseline
[...]

In the case above the commits we want are on top of d49ad49, which is `wrong-branch`. With this info you can tell git rebase --onto to take all commits “on top of” d49ad49 in fix-topic-branch and plant them on top of right-branch.

git rebase --onto right-branch d49ad49 fix-topic-branch

Once you confirm fix-topic-branch looks as you expect, you can rename it back to topic-branch:

git branch -D topic-branch
git branch -m topic-branch

Fix sync button in GitHub for Windows

My friend Elyse is a chef in Sonoma County. I setup a website for her using Jekyll, GitHub for Windows, and Heroku. When she wants to update her website, she makes changes to Markdown files and clicks the “sync” button in GitHub for Windows to publish her changes. It works magnificently well … until it breaks, and GitHub for Windows is terrible at telling you what the error actually is.

After some searching I discovered the sync button performs two actions:

git pull --rebase
git push

At some point git pull --rebase failed and left behind a .git/rebase-apply directory. In order to fix this, open the shell as the error message suggests and run the command:

del .git/rebase-apply

Confirm that it should remove the entire folder, then close the shell. Retry the sync command and it should work.