Sunday, December 22, 2019

My complete steps to join a new Raspberry Pi 4 node running Ubuntu 19.10 to the cluster

Connect the micro-hdmi, keyboard, and power.

Wait for it to boot up.

Login. Default user/pass is ubuntu/ubuntu, but it will make you change it on first login.

sudo apt update
sudo apt upgrade

Change the hostname, edit /etc/hostname

Enable the boot cmdline groups, edit /boot/firmware/nobtcmd.txt and add cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 to the end of the existing line (do not add newlines)

Reboot. Log in again.

Run ssh-keygen

From the master node:

copy over ssh key from master to the new node, just to make things easier:

ssh-copy-id nodehostname

copy over the node token from the master so that the new node can join the cluster:

scp /var/lib/rancher/k3s/server/node-token ubuntu@nodehostname:.

Now, back on the new node...

export K3S_TOKEN=$(cat node-token)
export K3S_URL=https://masterhostname:6443
curl -sfL https://get.k3s.io | sh -

Watch the logs, but the final message should be something like

systemd: Starting k3s-agent

Back on the master, run

sudo kubectl get nodes
And make sure the new one joined. That's it

Saturday, December 21, 2019

K3s on Raspberry Pi 4 4GB / Ubuntu 19.10 / Arm64

Picking this back up again, now that the USB bug with a >3GB of memory has been fixed in the latest version of Ubuntu 19.10.

Installing K3s is pretty easy, but there is one gotcha that isn't terribly well documented anywhere that I could find.

You need to enable cgroups for cpu and memory. To do that on Ubuntu 19.10 on a Raspberry Pi, edit /boot/firmware/nobtcmd.txt and add the following to the end of the existing line:

cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1

Reboot. Then install K3s

Friday, March 3, 2017

JSON pretty from inside vim

One liner to be able to format JSON into a readable (pretty) format from inside Vim.

:%!python -m json.tool

Saturday, January 30, 2016

Helping Apple with a missing button

Hi Apple,
It's ok, I get it... You're not trying to force Safari down our throats with the popup every couple days... it's just that you didn't have room to add "Don't ask me again" without ruining the aesthetic design.

I don't blame you, I mean look how nicely "Later" and "Try Now" fit together. I wouldn't want to add more options either.

Since Apple couldn't fit it in, here's how to fake the action of clicking on the missing "never ask me about switching to this beautifully designed browser" button. You'll have to open up terminal. Then type these three commands:

defaults write com.apple.coreservices.uiagent CSUIHasSafariBeenLaunched -bool YES
defaults write com.apple.coreservices.uiagent CSUIRecommendSafariNextNotificationDate -date 2020-01-01T00:00:00Z
defaults write com.apple.coreservices.uiagent CSUILastOSVersionWhereSafariRecommendationWasMade -float 10.99

That *should* take care of seeing the pop-up for the next few years...

Friday, November 13, 2015

updatedb on OSX

Mainly because I always forget, on OSX you can run the script the updates the locate db automatically, just run:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
(you only have to do it once)

Before you do, edit /System/Library/LaunchDaemons/com.apple.locate.plist Get rid of the following portion so that it runs daily instead of just once a week though.

                <key>Weekday</key>
                <integer>6</integer>

Monday, November 2, 2015

A refresher on what Java 7 brought...

Java 7 was released way back in 2011, but it's unfortunately not THAT uncommon for a large organization to get set in its ways (having found years ago, those battle-tested, magical, set of exact JVM tuning arguments that work for *their particular* application stack on a certain version of a 1.6 JVM) so that you don't get exposed to "newer" features. And to only get dragged kicking and screaming into JDK8 when Oracle deprecated certain versions.

So, what did Java 7 bring us? As developers, it seemed to be mostly about cleaning up syntax/getting rid of some of the boilerplate...

  • Strings in switch statements - sure, other languages had it for years, but you weren't able to switch on Strings until Java 7. Nice to have, not especially mind-blowing.
  • try with resources - This was a welcome addition - no longer did you have the super-awkward "declare your variable outside the block just so you have access to it in a second try/catch so you can close it..." e.g.
    Connection conn = null;
    try{
      conn = getConnectionFromSomewhere();
      // do work with the resource
    } catch (Exception e){
      // handle
    } finally {
      if (conn != null){
        try {
          conn.close();
        } catch (Exception someOtherExceptionYouProbablyIgnore) {
          // yah, you probably ignore this
        }
      }
    }
    
    Nope, now you can just do
    try(Connection conn = getConnectionFromSomewhere();){
      // do work with the resource
    } catch (Exception e) {
      // handle
    }
    You can also have your own objects work this way, look into java.lang.AutoClosable
  • Multi-catch - Another nice little cleanup, rather than listing out all the exceptions you want to handle (even if you handle some of them the same), you can now use the | pipe operator to union the exceptions you are handling. Instead of this:
    } catch (IOException ex) {
         logger.log(ex);
         throw ex;
    } catch (SQLException ex) {
         logger.log(ex);
         throw ex;
    }
    write this:
    } catch (IOException|SQLException ex) {
        logger.log(ex);
        throw ex;
    }
    
  • Binary literals - "0b" prefix, e.g. 0b10100111001 is 1337
  • left-to-right Improved type inference (<>) Removed the necessity of writing tripe like:
    Map<String, List<Integer>> m = new HashMap<String, List<Integer>>();
    simplifying it slightly to:
    Map<String, List<Integer>> m = new HashMap<>();
    (This seems slightly backwards to me, we're essentially specifying the details on the interface and waving our hands over the concrete implementation, instead of
    Map<> m = new HashMap<String, List<Integer>>(); // does not work
    but I'm not the designer - you must use the first version =)
  • Underscores in numeric literals What's easier to understand at a glance? Counting the zeros in 1000000000 or 1_000_000_000?
  • A whole slew of new APIs for NIO - notably, java.nio.Path and the WatchService, which allows you to be notified of changes to a path you're watching (there are a ton of applications for this)

Those are the big ones in my opinion. Did I miss any of your favorites?

Saturday, October 31, 2015

Changing default prefix keys for tmux

tmux uses Ctrl-b as the default command prefix, that's ok on Windows but less than desirable on a MacBook Pro. Turns out that it's super easy to remap to something easier to type, but it's a two-step process.

First, let's get some usage out of the vestigial 'caps lock' key. Go to 'System Preferences' -> 'Keyboard' -> 'Modifier Keys' and then change caps lock to do something (marginally more) useful, the Control key.

Now that that's out of the way, remap the prefix in tmux by editing (or creating) your ~/.tmux.conf file. We only need one line in there to remap the prefix to Ctrl-a (which are handily right next to each other):

set -g prefix C-a

Two things to note: first, changing the caps lock key to be control affects ALL applications on your Mac, if you're like me and never use caps lock, that's probably ok - just something to remember. Secondly, sometimes you might want to be able to send Ctrl-a to an application that you're using inside tmux. If you think you will, just add another line to your ~/.tmux.conf file:

bind C-a send-prefix

This will allow you to send Ctrl-a to the application running inside tmux by pressing it TWICE.