script

Updating a Kubernetes Deployment and waiting for it to roll out in a shell script

For some Kubernetes cluster operations (e.g. deploying an update to a small microservice or app), I need a quick and dirty way to:

  1. Build and push a Docker image to a private registry.
  2. Update a Kubernetes Deployment to use this new image version.
  3. Wait for the Deployment rollout to complete.
  4. Run some post-rollout operations (e.g. clear caches, run an update, etc.).

There are a thousand and one ways to do all this, and many are a bit more formal than this, but sometimes you just need a shell script you can run from your CI server to do it all. And it's not too hard, nor complex, to do it this way:

Parsing YAML files on the command line using Ruby

I have been working on an infrastructure project that uses YAML files for all inventory and configuration management, and for the most part, if you're using tools like Ansible, CloudFormation, etc., then you don't ever have to worry about the actual parsing of a YAML file, and keys and values in the file are readily accessible since these tools parse them and get them into a readable structure for you.

But there's often little bits of glue code, or infrastructure build/cleanup jobs, where you need to grab one specific value out of a YAML file, and all you have readily available is bash. Luckily for me, I also have Ruby available in the particular environment where I needed to parse the YAML file, so doing this was as easy as:

  1. Defining a little bit of Ruby code which would load the YAML file, then grab a value out of it.
  2. Running that Ruby code using ruby -e (-e for 'evaluate this code), operating on the contents of a YAML file.

And here's how that looked, in my case:

Current Time - @currenttime on Twitter

A few weeks ago, I was thinking to myself: "It's hard to tell what time certain tweets in my (already busy) timeline were posted... It'd be great if, instead of '18 minutes ago,' I could see that the post fell between 10 p.m. and 10:10 p.m. – it's much easier for me to remember tweets by time than by 'time ago.'

So, instead of trying to find some Twitter app that would let me insert my own timestamps or change the date format (I'm sure there are a few), I wrote a PHP script that would post a new tweet with the time in four time zones to the @currenttime Twitter account. Then, I followed @currenttime, and history was made ;-)

Here's the script I used (with help from Morethanseven's article, "Posting to Twitter using PHP"):

Subscribe to RSS - script